Skip to content

Commit

Permalink
update v1.2 18/12/2023
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
thrive4 authored Dec 18, 2023
1 parent 83727a3 commit 0757a7b
Show file tree
Hide file tree
Showing 8 changed files with 891 additions and 229 deletions.
8 changes: 4 additions & 4 deletions app.rc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ FB_PROGRAM_ICON ICON "app.ico"

// add version and file info in exe windows only
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1, 1, 0, 000
PRODUCTVERSION 1, 1, 0, 0
FILEVERSION 1, 2, 0, 000
PRODUCTVERSION 1, 2, 0, 0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x9L
Expand All @@ -29,13 +29,13 @@ BEGIN
VALUE "Comments", "needs sqlite 3.42 or up lib"
VALUE "CompanyName", "thrive4"
VALUE "FileDescription", "sqlite command line util"
VALUE "FileVersion", "1, 1, 0, 000"
VALUE "FileVersion", "1, 2, 0, 000"
VALUE "InternalName", ""
VALUE "LegalCopyright", ""
VALUE "OriginalFilename", "cmdsqlite"
VALUE "PrivateBuild", ""
VALUE "ProductName", "cmdsqlite"
VALUE "ProductVersion", "1, 1, 0, 0"
VALUE "ProductVersion", "1, 2, 0, 0"
END
END
BLOCK "VarFileInfo"
Expand Down
123 changes: 110 additions & 13 deletions cmdsqlite.bas
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,26 @@
' more info see: https://github.com/thrive4/util.fb.cmdsqlite

declare function listrecords(needle as string = "") as boolean
declare function getimagemetric(filename As String) As boolean
' init imagemetric
common shared coverwidth as integer
common shared coverheight as integer
common shared orientation as string
common shared report as string
common shared thumbnail as string
common shared thumb as integer
common shared layout as string
common shared chunk as string
common shared csv as string

#include once "sqlite3.bi"
#include once "windows.bi"
#include once "utilfile.bas"
#include once "utilmedia.bas"
#include once "utilmht.bas"
#cmdline "app.rc"

' init sqlite
Dim db As sqlite3 Ptr
Dim rc As Integer
Dim fn As String
Expand Down Expand Up @@ -78,7 +93,6 @@ function listcsv(needle as string = "", checkfile as boolean = false) as boolean
next i
print mid(dummy, 1, len(dummy) - 1)


' get fieldvalues aka data
dummy = ""
for i as integer = 0 to recnr
Expand Down Expand Up @@ -171,7 +185,8 @@ function listhtml(needle as string = "") as boolean
dim tbname as string = "game"
dim fieldnr as integer = 0
dim cnt as integer = 0
dim as integer itemnr = 1, i = 1, n = 1, tmp, f
dim as integer itemnr = 1, i = 1, n = 1
dim as long tmp, f

' get template for body, css, and javacript
tmp = readfromfile(exepath + "\templates\head.html")
Expand Down Expand Up @@ -277,6 +292,17 @@ function listjson(needle as string = "") as boolean
end if
else
' parse non sqlite output

' todo implement rest of json escaping
'Backspace is replaced with \b
'Form feed is replaced with \f
'Newline is replaced with \n
'Carriage return is replaced with \r
'Tab is replaced with \t
'Double quote is replaced with \"
'Backslash is replaced with \\
record.fieldvalue(i) = replace(record.fieldvalue(i), "\", "\\")

if cnt = fieldnr then
dummy += chr$(34) + record.fieldname(i) + chr$(34) + ":" + chr$(34) + record.fieldvalue(i) + chr$(34) + "}," + chr$(13) + chr$(10)
cnt = 1
Expand Down Expand Up @@ -395,9 +421,17 @@ dim itm as string
dim inikey as string
dim inival as string
dim inifile as string = exepath + "\conf\" + "conf.ini"
dim f as integer
dim f as long
dim htmloutput as string

' init mp3 cover
dim nocover as string = ""
dim tempfolder as string = exepath + "\cover"
dim filename as string
dim itemnr as integer = 0
dim listitem as string
dim maxitems as integer = 0

if FileExists(inifile) = false then
logentry("error", inifile + "file does not excist")
else
Expand All @@ -414,25 +448,22 @@ else
logtype = inival
case "usecons"
usecons = inival
case "htmloutput"
htmloutput = inival
'case "htmloutput"
' htmloutput = inival
end select
'print inikey + " - " + inival
end if
loop
loop
close(f)
end if

' basic commandline parser
' init basic commandline parser
' via https://www.freebasic.net/forum/viewtopic.php?t=31889 code by coderJeff
dim i as integer = 1
dim runsqlquery as boolean = false
dim runlistrecords as boolean = false
dim dummy as string = ""

'print "cmd1 " + command(1)
'print "cmd2 " + command(2)
'print "cmd3 " + command(3)

' parse if no commandline options are present
select case true
case len(command(1)) = 0
Expand Down Expand Up @@ -494,20 +525,28 @@ while i < __FB_ARGC__
else
logentry("fatal", "file not found or missing.. '" & command(i) & "'")
end if
case instr(command(1), ".mht") > 0
if FileExists(command(1)) then
mhtconvert(command(1))
wordwrap2file(command(1), swp)
logentry("terminate", "mhtconvert duration " + command(1) + " " + exectime(exectimer, "stop"))
else
logentry("fatal", "file not found or missing.. '" & command(i) & "'")
end if
' eperimental todo use as text analysis for sqlite fts5
'case instr(command(1), ".txt") > 0
' dictonary(command(1), wc)
case instr(command(1), ":") > 0
if checkpath(command(1)) = false then
logentry("fatal", "please specify a valid path.. '" & command(i) & "'")
logentry("fatal", "please specify a valid file or path.. '" & command(i) & "'")
end if
if len(command(2)) = 0 then
logentry("fatal", "please specify filespec ex. *.mp3.. '" & command(i) & "'")
end if
SELECT case command(3)
case "csv", "json", "html", "sql", "xml"
' note somehow freebasic has an issue with the wildcard *
dir2file(command(1), command(2), command(3), htmloutput)
dir2file(command(1), command(2), command(3), command(4))
dummy = replace(mid(command(1), instrrev(command(1), "\") + 1), " ", "")
select case command(3)
case "csv"
Expand All @@ -522,10 +561,68 @@ while i < __FB_ARGC__
listxml(replace(replace(left(command(1),instrrev(command(1), "\") - 1), "\", "_"), ":", ""), dummy)
END select
logentry("notice", "dir2" + command(3) + " duration " + exectime(exectimer, "stop"))
case "cover"
if instr(command(2), ".mp3") > 0 then
' export covers to jpeg or png file(s)
mkdir (tempfolder) ' create export folder regardless
print "scanning and exporting mp3 covers(s)...."
if instr(command(1), ".mp3") > 0 then
getmp3cover(command(1), filename)
itemnr = 1
else
createlist(command(1), ".mp3", "cover")
'f = freefile
open "cover.tmp" for input as #20
Do Until EOF(20)
Line Input #20, listitem
filename = lcase(mid(listitem, instrrev(listitem, "\") + 1))
filename = lcase(mid(filename, 1, instrrev(filename, ".") - 1))
if getmp3cover(listitem, filename) then
itemnr += 1
else
nocover = nocover + "no cover art found in " + filename + chr$(13) + chr$(10)
csv = csv + chr$(34) + command(1) + "\" + filename + chr$(34) + ",0,0" + chr$(13) + chr$(10)
end if
listitem = ""
maxitems += 1
loop
close(20)
' strip final carrige return csv
csv = mid(csv, 1, len(csv) - 2)
' cleanup listplay files
delfile(exepath + "\cover.tmp")
delfile(exepath + "\cover.lst")
end if
' report to command line
print nocover
if thumbnail = "" then
print "no thumbnail(s) found in scanned files"
else
print thumbnail
end if
if layout = "" then
print "all scanned file(s) are sqare"
else
print layout
end if
print "finished scanning " & maxitems & " file(s)"
print "exported " & itemnr & " covers(s) to " + tempfolder
' export results as csv
f = freefile
open "mp3cover.csv" for output as f
print #f, csv
close(f)
print "created report mp3cover.csv in " + exepath
print "total duration operation(s) " + exectime(exectimer, "stop")
logentry("terminate", "export mp3 album covers duration " + exectime(exectimer, "stop"))
else
logentry("fatal", "only supports mp3 files .. '" & command(i) & "'")
end if
case else
logentry("fatal", "please specify a valid export file type.. '" & command(i) & "'")
end select
logentry("terminate", "normal termination created " + command(3))

case else
if FileExists(command(1)) then
logentry("fatal", "file not supported.. '" & command(i) & "'")
Expand Down
13 changes: 13 additions & 0 deletions cmdsqlite.nfo
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
update v1.2 18/12/2023
- intergrated mp3 album cover export
from https://github.com/thrive4/util.fb.mp3cover
added filesize and orientation image as field data
to mp3cover.csv report
- intergrated .mht convert (converts .mht to .html and .txt)
from https://www.freebasic.net/forum/viewtopic.php?p=288025
- updated wordwrap2file some what better text formating
- 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

update v1.1 02/11/2023
- added export meta info mp3 to other fileformats
csv, json, sql and xml
Expand Down
Binary file modified cmdsqlite.wfbe
Binary file not shown.
40 changes: 34 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and file in specified field.\
See included help, or tutorial.txt in data folder, for more details\
cmdsqlite.exe /? (or -h, -help, etc)\
Note: [folder] [filespec] folders are scanned recursively for filespec

## usage
- basic\
cmdsqlite.exe [dbname] [query]\
Expand All @@ -27,21 +28,37 @@ example: cmdsqlite.exe g:\data\images\classic *.jpg csv
checkfile returns -1 if the file exists, otherwise zero 0

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

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

- export to json\
cmdsqlite.exe game.db "select name, developer from game" json\
example: cmdsqlite.exe game.db "select name, developer from game" json\
equivelent of:\
select json_object('name', name, 'developer', developer) from game" json

- exports to csv\
cmdsqlite.exe game.db "select name, developer from game" csv
- export to csv\
example: cmdsqlite.exe game.db "select name, developer from game" csv

- export coverart in mp3\
example: cmdsqlite.exe g:\data\mp3\classic *.mp3 cover\
exports cover art (.jpr or .png) in mp3 to folder cover and generates report\
with width / height, thumbnail info, etc of .jpg or .png if present

- supplement exporttype: 'exif' as optional fourth parameter\
example: cmdsqlite.exe g:\data\images\paris *.jpg csv exif\
generates report with\
width / height in .jpg or .png if present

- example: cmdsqlite.exe g:\data\images\paris *.jpg html exif\
filespec *.jpg creates imageviewer

- example: cmdsqlite.exe g:\data\mp3\classic *.mp3 html exif\
filespec *.mp3 gets tag info and creates audio link

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

- convert
.mht files are converted to .txt and .html\
usage: <filename>.mht\
example: cmdsqlite.exe g:\data\text\demo.mht\
creates a folder <filename> and extracts all files in the .mht\
plus converts the main .html to a sperate wordwrapped text file.

## configuration
options via \conf\conf.ini\
[output]\
' deprecated\
' additional parsing per filetype mp3, jpg\
' options: default, extra\
htmloutput = extra
' htmloutput = extra\
use fourth parameter 'exif' on commandline

## requirements
sqlite.dll 32-bit DLL (x86) for SQLite version 3.43.0.\
https://www.sqlite.org/download.html
Expand All @@ -71,6 +98,7 @@ handles ~30 / ~50\
threads 1 / 3\
cpu ~1 (low) / ~2\
tested on intel i5-6600T

## special thanks
tips on commandline parsing via:\
https://www.freebasic.net/forum/viewtopic.php?t=31889 code by coderJeff\
Expand Down
Loading

0 comments on commit 0757a7b

Please sign in to comment.