33' more info see: https://github.com/thrive4/util.fb.cmdsqlite
44
55declare 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
1126Dim db As sqlite3 Ptr
1227Dim rc As Integer
1328Dim 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
395421dim inikey as string
396422dim inival as string
397423dim inifile as string = exepath + "\conf\" + "conf.ini"
398- dim f as integer
424+ dim f as long
399425dim 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+
401435if FileExists(inifile) = false then
402436 logentry( "error" , inifile + "file does not excist" )
403437else
@@ -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)
423458end 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
427462dim i as integer = 1
428463dim runsqlquery as boolean = false
429464dim runlistrecords as boolean = false
430465dim 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
437468select 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) & "'" )
0 commit comments