Skip to content

Commit 0757a7b

Browse files
authored
update v1.2 18/12/2023
- integrated mp3 album cover export from https://github.com/thrive4/util.fb.mp3cover added filesize and orientation image as field data to mp3cover.csv report - integrated .mht convert (converts .mht to .html and .txt) from https://www.freebasic.net/forum/viewtopic.php?p=288025 - updated wordwrap2file some what better text formatting - added sticky table header for data tables sticky tip courtesy https://codepen.io/stephen-george-west/pen/rNpjXYL - updated help.ini with new functionality - partial implementation json data format escaping rules
1 parent 83727a3 commit 0757a7b

File tree

8 files changed

+891
-229
lines changed

8 files changed

+891
-229
lines changed

app.rc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ FB_PROGRAM_ICON ICON "app.ico"
1010

1111
// add version and file info in exe windows only
1212
VS_VERSION_INFO VERSIONINFO
13-
FILEVERSION 1, 1, 0, 000
14-
PRODUCTVERSION 1, 1, 0, 0
13+
FILEVERSION 1, 2, 0, 000
14+
PRODUCTVERSION 1, 2, 0, 0
1515
FILEFLAGSMASK 0x3fL
1616
#ifdef _DEBUG
1717
FILEFLAGS 0x9L
@@ -29,13 +29,13 @@ BEGIN
2929
VALUE "Comments", "needs sqlite 3.42 or up lib"
3030
VALUE "CompanyName", "thrive4"
3131
VALUE "FileDescription", "sqlite command line util"
32-
VALUE "FileVersion", "1, 1, 0, 000"
32+
VALUE "FileVersion", "1, 2, 0, 000"
3333
VALUE "InternalName", ""
3434
VALUE "LegalCopyright", ""
3535
VALUE "OriginalFilename", "cmdsqlite"
3636
VALUE "PrivateBuild", ""
3737
VALUE "ProductName", "cmdsqlite"
38-
VALUE "ProductVersion", "1, 1, 0, 0"
38+
VALUE "ProductVersion", "1, 2, 0, 0"
3939
END
4040
END
4141
BLOCK "VarFileInfo"

cmdsqlite.bas

Lines changed: 110 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,26 @@
33
' more info see: https://github.com/thrive4/util.fb.cmdsqlite
44

55
declare function listrecords(needle as string = "") as boolean
6+
declare function getimagemetric(filename As String) As boolean
7+
' init imagemetric
8+
common shared coverwidth as integer
9+
common shared coverheight as integer
10+
common shared orientation as string
11+
common shared report as string
12+
common shared thumbnail as string
13+
common shared thumb as integer
14+
common shared layout as string
15+
common shared chunk as string
16+
common shared csv as string
17+
618
#include once "sqlite3.bi"
719
#include once "windows.bi"
820
#include once "utilfile.bas"
21+
#include once "utilmedia.bas"
22+
#include once "utilmht.bas"
923
#cmdline "app.rc"
1024

25+
' init sqlite
1126
Dim db As sqlite3 Ptr
1227
Dim rc As Integer
1328
Dim fn As String
@@ -78,7 +93,6 @@ function listcsv(needle as string = "", checkfile as boolean = false) as boolean
7893
next i
7994
print mid(dummy, 1, len(dummy) - 1)
8095

81-
8296
' get fieldvalues aka data
8397
dummy = ""
8498
for i as integer = 0 to recnr
@@ -171,7 +185,8 @@ function listhtml(needle as string = "") as boolean
171185
dim tbname as string = "game"
172186
dim fieldnr as integer = 0
173187
dim cnt as integer = 0
174-
dim as integer itemnr = 1, i = 1, n = 1, tmp, f
188+
dim as integer itemnr = 1, i = 1, n = 1
189+
dim as long tmp, f
175190

176191
' get template for body, css, and javacript
177192
tmp = readfromfile(exepath + "\templates\head.html")
@@ -277,6 +292,17 @@ function listjson(needle as string = "") as boolean
277292
end if
278293
else
279294
' parse non sqlite output
295+
296+
' todo implement rest of json escaping
297+
'Backspace is replaced with \b
298+
'Form feed is replaced with \f
299+
'Newline is replaced with \n
300+
'Carriage return is replaced with \r
301+
'Tab is replaced with \t
302+
'Double quote is replaced with \"
303+
'Backslash is replaced with \\
304+
record.fieldvalue(i) = replace(record.fieldvalue(i), "\", "\\")
305+
280306
if cnt = fieldnr then
281307
dummy += chr$(34) + record.fieldname(i) + chr$(34) + ":" + chr$(34) + record.fieldvalue(i) + chr$(34) + "}," + chr$(13) + chr$(10)
282308
cnt = 1
@@ -395,9 +421,17 @@ dim itm as string
395421
dim inikey as string
396422
dim inival as string
397423
dim inifile as string = exepath + "\conf\" + "conf.ini"
398-
dim f as integer
424+
dim f as long
399425
dim htmloutput as string
400426

427+
' init mp3 cover
428+
dim nocover as string = ""
429+
dim tempfolder as string = exepath + "\cover"
430+
dim filename as string
431+
dim itemnr as integer = 0
432+
dim listitem as string
433+
dim maxitems as integer = 0
434+
401435
if FileExists(inifile) = false then
402436
logentry("error", inifile + "file does not excist")
403437
else
@@ -414,25 +448,22 @@ else
414448
logtype = inival
415449
case "usecons"
416450
usecons = inival
417-
case "htmloutput"
418-
htmloutput = inival
451+
'case "htmloutput"
452+
' htmloutput = inival
419453
end select
420454
'print inikey + " - " + inival
421455
end if
422-
loop
456+
loop
457+
close(f)
423458
end if
424459

425-
' basic commandline parser
460+
' init basic commandline parser
426461
' via https://www.freebasic.net/forum/viewtopic.php?t=31889 code by coderJeff
427462
dim i as integer = 1
428463
dim runsqlquery as boolean = false
429464
dim runlistrecords as boolean = false
430465
dim dummy as string = ""
431466

432-
'print "cmd1 " + command(1)
433-
'print "cmd2 " + command(2)
434-
'print "cmd3 " + command(3)
435-
436467
' parse if no commandline options are present
437468
select case true
438469
case len(command(1)) = 0
@@ -494,20 +525,28 @@ while i < __FB_ARGC__
494525
else
495526
logentry("fatal", "file not found or missing.. '" & command(i) & "'")
496527
end if
528+
case instr(command(1), ".mht") > 0
529+
if FileExists(command(1)) then
530+
mhtconvert(command(1))
531+
wordwrap2file(command(1), swp)
532+
logentry("terminate", "mhtconvert duration " + command(1) + " " + exectime(exectimer, "stop"))
533+
else
534+
logentry("fatal", "file not found or missing.. '" & command(i) & "'")
535+
end if
497536
' eperimental todo use as text analysis for sqlite fts5
498537
'case instr(command(1), ".txt") > 0
499538
' dictonary(command(1), wc)
500539
case instr(command(1), ":") > 0
501540
if checkpath(command(1)) = false then
502-
logentry("fatal", "please specify a valid path.. '" & command(i) & "'")
541+
logentry("fatal", "please specify a valid file or path.. '" & command(i) & "'")
503542
end if
504543
if len(command(2)) = 0 then
505544
logentry("fatal", "please specify filespec ex. *.mp3.. '" & command(i) & "'")
506545
end if
507546
SELECT case command(3)
508547
case "csv", "json", "html", "sql", "xml"
509548
' note somehow freebasic has an issue with the wildcard *
510-
dir2file(command(1), command(2), command(3), htmloutput)
549+
dir2file(command(1), command(2), command(3), command(4))
511550
dummy = replace(mid(command(1), instrrev(command(1), "\") + 1), " ", "")
512551
select case command(3)
513552
case "csv"
@@ -522,10 +561,68 @@ while i < __FB_ARGC__
522561
listxml(replace(replace(left(command(1),instrrev(command(1), "\") - 1), "\", "_"), ":", ""), dummy)
523562
END select
524563
logentry("notice", "dir2" + command(3) + " duration " + exectime(exectimer, "stop"))
564+
case "cover"
565+
if instr(command(2), ".mp3") > 0 then
566+
' export covers to jpeg or png file(s)
567+
mkdir (tempfolder) ' create export folder regardless
568+
print "scanning and exporting mp3 covers(s)...."
569+
if instr(command(1), ".mp3") > 0 then
570+
getmp3cover(command(1), filename)
571+
itemnr = 1
572+
else
573+
createlist(command(1), ".mp3", "cover")
574+
'f = freefile
575+
open "cover.tmp" for input as #20
576+
Do Until EOF(20)
577+
Line Input #20, listitem
578+
filename = lcase(mid(listitem, instrrev(listitem, "\") + 1))
579+
filename = lcase(mid(filename, 1, instrrev(filename, ".") - 1))
580+
if getmp3cover(listitem, filename) then
581+
itemnr += 1
582+
else
583+
nocover = nocover + "no cover art found in " + filename + chr$(13) + chr$(10)
584+
csv = csv + chr$(34) + command(1) + "\" + filename + chr$(34) + ",0,0" + chr$(13) + chr$(10)
585+
end if
586+
listitem = ""
587+
maxitems += 1
588+
loop
589+
close(20)
590+
' strip final carrige return csv
591+
csv = mid(csv, 1, len(csv) - 2)
592+
' cleanup listplay files
593+
delfile(exepath + "\cover.tmp")
594+
delfile(exepath + "\cover.lst")
595+
end if
596+
' report to command line
597+
print nocover
598+
if thumbnail = "" then
599+
print "no thumbnail(s) found in scanned files"
600+
else
601+
print thumbnail
602+
end if
603+
if layout = "" then
604+
print "all scanned file(s) are sqare"
605+
else
606+
print layout
607+
end if
608+
print "finished scanning " & maxitems & " file(s)"
609+
print "exported " & itemnr & " covers(s) to " + tempfolder
610+
' export results as csv
611+
f = freefile
612+
open "mp3cover.csv" for output as f
613+
print #f, csv
614+
close(f)
615+
print "created report mp3cover.csv in " + exepath
616+
print "total duration operation(s) " + exectime(exectimer, "stop")
617+
logentry("terminate", "export mp3 album covers duration " + exectime(exectimer, "stop"))
618+
else
619+
logentry("fatal", "only supports mp3 files .. '" & command(i) & "'")
620+
end if
525621
case else
526622
logentry("fatal", "please specify a valid export file type.. '" & command(i) & "'")
527623
end select
528624
logentry("terminate", "normal termination created " + command(3))
625+
529626
case else
530627
if FileExists(command(1)) then
531628
logentry("fatal", "file not supported.. '" & command(i) & "'")

cmdsqlite.nfo

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
update v1.2 18/12/2023
2+
- intergrated mp3 album cover export
3+
from https://github.com/thrive4/util.fb.mp3cover
4+
added filesize and orientation image as field data
5+
to mp3cover.csv report
6+
- intergrated .mht convert (converts .mht to .html and .txt)
7+
from https://www.freebasic.net/forum/viewtopic.php?p=288025
8+
- updated wordwrap2file some what better text formating
9+
- added sticky table header for data tables
10+
sticky tip courtesy https://codepen.io/stephen-george-west/pen/rNpjXYL
11+
- updated help.ini with new functionality
12+
- partial implementation json data format escaping rules
13+
114
update v1.1 02/11/2023
215
- added export meta info mp3 to other fileformats
316
csv, json, sql and xml

cmdsqlite.wfbe

784 Bytes
Binary file not shown.

readme.md

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and file in specified field.\
1515
See included help, or tutorial.txt in data folder, for more details\
1616
cmdsqlite.exe /? (or -h, -help, etc)\
1717
Note: [folder] [filespec] folders are scanned recursively for filespec
18+
1819
## usage
1920
- basic\
2021
cmdsqlite.exe [dbname] [query]\
@@ -27,21 +28,37 @@ example: cmdsqlite.exe g:\data\images\classic *.jpg csv
2728
checkfile returns -1 if the file exists, otherwise zero 0
2829

2930
- export to html(table)\
30-
cmdsqlite.exe game.db "select name, developer from game" html\
31+
example: cmdsqlite.exe game.db "select name, developer from game" html\
3132
exports query result to an html sortable table (using templates)\
3233

3334
- export to html(table) via folder\
34-
cmdsqlite.exe g:\data\mp3\classic *.mp3 html\
35+
example: cmdsqlite.exe g:\data\mp3\classic *.mp3 html\
3536
exports all files and subsequent folders in 'g:\data\mp3\classic'\
3637
to an html sortable table (using templates)
3738

3839
- export to json\
39-
cmdsqlite.exe game.db "select name, developer from game" json\
40+
example: cmdsqlite.exe game.db "select name, developer from game" json\
4041
equivelent of:\
4142
select json_object('name', name, 'developer', developer) from game" json
4243

43-
- exports to csv\
44-
cmdsqlite.exe game.db "select name, developer from game" csv
44+
- export to csv\
45+
example: cmdsqlite.exe game.db "select name, developer from game" csv
46+
47+
- export coverart in mp3\
48+
example: cmdsqlite.exe g:\data\mp3\classic *.mp3 cover\
49+
exports cover art (.jpr or .png) in mp3 to folder cover and generates report\
50+
with width / height, thumbnail info, etc of .jpg or .png if present
51+
52+
- supplement exporttype: 'exif' as optional fourth parameter\
53+
example: cmdsqlite.exe g:\data\images\paris *.jpg csv exif\
54+
generates report with\
55+
width / height in .jpg or .png if present
56+
57+
- example: cmdsqlite.exe g:\data\images\paris *.jpg html exif\
58+
filespec *.jpg creates imageviewer
59+
60+
- example: cmdsqlite.exe g:\data\mp3\classic *.mp3 html exif\
61+
filespec *.mp3 gets tag info and creates audio link
4562

4663
- import via sql of csv, json or xml\
4764
cmdsqlite.exe [filename].csv\
@@ -55,12 +72,22 @@ displays table names contained in [dbname]\
5572
cmdsqlite.exe [dbname] showfields [tablename]\
5673
displays fieldnames contained in [tablename]
5774

75+
- convert
76+
.mht files are converted to .txt and .html\
77+
usage: <filename>.mht\
78+
example: cmdsqlite.exe g:\data\text\demo.mht\
79+
creates a folder <filename> and extracts all files in the .mht\
80+
plus converts the main .html to a sperate wordwrapped text file.
81+
5882
## configuration
5983
options via \conf\conf.ini\
6084
[output]\
85+
' deprecated\
6186
' additional parsing per filetype mp3, jpg\
6287
' options: default, extra\
63-
htmloutput = extra
88+
' htmloutput = extra\
89+
use fourth parameter 'exif' on commandline
90+
6491
## requirements
6592
sqlite.dll 32-bit DLL (x86) for SQLite version 3.43.0.\
6693
https://www.sqlite.org/download.html
@@ -71,6 +98,7 @@ handles ~30 / ~50\
7198
threads 1 / 3\
7299
cpu ~1 (low) / ~2\
73100
tested on intel i5-6600T
101+
74102
## special thanks
75103
tips on commandline parsing via:\
76104
https://www.freebasic.net/forum/viewtopic.php?t=31889 code by coderJeff\

0 commit comments

Comments
 (0)