From 1764b8afeaee31e1ac01dafbd6dedc554c72ae03 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Tue, 30 Apr 2013 03:18:42 +0200 Subject: [PATCH 01/10] I have no shame --- README | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README b/README index 3f5f6ed..b87cabe 100644 --- a/README +++ b/README @@ -52,3 +52,26 @@ AtOM requires a database to function. Now that we have a database containing various information about our media files, why not use it? AtOM comes with a small set of tools in the toys/ directory. These are documented in toys/README. + +======================== +Shameless Self Promotion +------------------------ +I am the author of free (Creative Commons CC-By-SA) music which you can stream +for free, or buy to get high quality and bonuses from Bandcamp +(http://djblackred.bandcamp.com). If you like electronic music taking its +inspiration from Trance, Drum & Bass, Ambient and (rarely) Free Jazz, please +check it out! +Downloads are available in FLAC, Ogg, MP3, and more, and includes the "source +code" (sequencer files and the likes) for most tracks. +I am receiving 85% of the money you'll spend, so you won't be feeding some +greedy BigCorp producer or distributor. +And if you don't like it, you can still spread the word to friends who may like. +You can see this as a way to thank me for this piece of code. + +===== +Legal +----- +Some of the format and/or tool names cited above are trademarks belonging to +their rightful owners. AtOM and its authors are not linked in any way to +those companies or individuals. Said companies do not endorse nor support +AtOM in any way. From 6b3ac87c9982b72ad5407b37910afc8230da5c10 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Tue, 30 Apr 2013 13:07:30 +0200 Subject: [PATCH 02/10] conditional use of sox for video --- lib/decode/decodeFile | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/decode/decodeFile b/lib/decode/decodeFile index cc52f01..09c2dc3 100644 --- a/lib/decode/decodeFile +++ b/lib/decode/decodeFile @@ -3,7 +3,17 @@ decodeFile() { case "$mimetype" in 'video/'*) extractAudio - sox_needed=1 + if (( ${destinationnormalize["$destination"]}))\ + || ( + [ -n "${destinationfrequency["$destination"]}" ]\ + && (( ${rate:-0} != ${destinationfrequency["$destination"]}))\ + ) || ( + [ -n "${destinationchannels["$destination"]}" ]\ + && (( ${channels:-0} != ${destinationchannels["$destination"]} )) + ) + then + sox_needed=1 + fi ;; 'audio/mpeg') if [[ ${destinationformat[$destination]} = mp3 ]] \ From 048693ec8c1ef69b965701f3f98cd304b8c0a0d8 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Tue, 30 Apr 2013 13:32:47 +0200 Subject: [PATCH 03/10] don't rename if tags missing --- lib/files/getDestDir | 29 ++++++++++++++++++++++++++++- lib/files/getDestFile | 29 ++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/lib/files/getDestDir b/lib/files/getDestDir index 81b6839..787adaf 100644 --- a/lib/files/getDestDir +++ b/lib/files/getDestDir @@ -1,7 +1,34 @@ #!/bin/bash getDestDir() { destdir="${destinationpath[$destination]}/" - if [ -n "${destinationrenamepath[$destination]}" ] + if [ -n "${destinationrenamepath[$destination]}" ] \ + && ( + ( + ! [[ ${destinationrenamepath[$destination]} =~ %{album} ]] \ + || [ -n "$album" ] + ) && ( + ! [[ ${destinationrenamepath[$destination]} =~ %{albumartist} ]] \ + || [ -n "$albumartist" ] + ) && ( + ! [[ ${destinationrenamepath[$destination]} =~ %{artist} ]] \ + || [ -n "$artist" ] + ) && ( + ! [[ ${destinationrenamepath[$destination]} =~ %{genre} ]] \ + || [ -n "$genre" ] + ) && ( + ! [[ ${destinationrenamepath[$destination]} =~ %{title} ]] \ + || [ -n "$title" ] + ) && ( + ! [[ ${destinationrenamepath[$destination]} =~ %{track} ]] \ + || [ -n "$track" ] + ) && ( + ! [[ ${destinationrenamepath[$destination]} =~ %{year} ]] \ + || [ -n "$year" ] + ) && ( + ! [[ ${destinationrenamepath[$destination]} =~ %{disc} ]] \ + || [ -n "$disc" ] + ) + ) then replace=$(sanitizeFile "$album" dir) destdir+="${destinationrenamepath[$destination]//%\{album\}/$replace}" diff --git a/lib/files/getDestFile b/lib/files/getDestFile index 7730b48..e943b41 100644 --- a/lib/files/getDestFile +++ b/lib/files/getDestFile @@ -1,6 +1,33 @@ #!/bin/bash getDestFile() { - if [ -n "${destinationrename[$destination]}" ] + if [ -n "${destinationrename[$destination]}" ] \ + && ( + ( + ! [[ ${destinationrename[$destination]} =~ %{album} ]] \ + || [ -n "$album" ] + ) && ( + ! [[ ${destinationrename[$destination]} =~ %{albumartist} ]] \ + || [ -n "$albumartist" ] + ) && ( + ! [[ ${destinationrename[$destination]} =~ %{artist} ]] \ + || [ -n "$artist" ] + ) && ( + ! [[ ${destinationrename[$destination]} =~ %{genre} ]] \ + || [ -n "$genre" ] + ) && ( + ! [[ ${destinationrename[$destination]} =~ %{title} ]] \ + || [ -n "$title" ] + ) && ( + ! [[ ${destinationrename[$destination]} =~ %{track} ]] \ + || [ -n "$track" ] + ) && ( + ! [[ ${destinationrename[$destination]} =~ %{year} ]] \ + || [ -n "$year" ] + ) && ( + ! [[ ${destinationrename[$destination]} =~ %{disc} ]] \ + || [ -n "$disc" ] + ) + ) then destfile="${destinationrename[$destination]//%\{album\}/$album}" destfile="${destfile//%\{albumartist\}/$albumartist}" From 28b11a77eaf2ee936c1773e80bff24450bb9d853 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Wed, 1 May 2013 03:40:43 +0200 Subject: [PATCH 04/10] ffmpeg: fix tracknumber tag --- lib/tags/getInfos::ffmpeg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tags/getInfos::ffmpeg b/lib/tags/getInfos::ffmpeg index d855139..5f129f3 100644 --- a/lib/tags/getInfos::ffmpeg +++ b/lib/tags/getInfos::ffmpeg @@ -31,7 +31,7 @@ getInfos::ffmpeg() { genre=$(gettag genre) performer=$(gettag TOPE) title=$(gettag title) - tracknum=$(gettag tracknumber) + tracknum=$(gettag track) year=$(gettag year) expr='^[0-9]*$' if [ -n "$genre" ] && [[ $genre =~ $expr ]] From 1fa431cc5f90a8d64132848f9d5ee80801515f77 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Thu, 2 May 2013 02:23:24 +0200 Subject: [PATCH 05/10] filenames and/or tags may contain | --- atom | 148 +++++++++++++++++++------------------- lib/copy/copyFiles_action | 16 ++--- lib/database/openDatabase | 1 + lib/files/sanitizeFile | 7 ++ lib/tasks/gettaskinfos | 24 +++---- lib/workers/master | 144 ++++++++++++++++++------------------- toys/checkextensions | 16 ++--- toys/missingtags | 44 ++++++------ 8 files changed, 204 insertions(+), 196 deletions(-) diff --git a/atom b/atom index 83a3906..dff6205 100755 --- a/atom +++ b/atom @@ -144,8 +144,8 @@ removed=0 read -u4 line until [[ $line == AtOM:NoMoreFiles ]] do - id=${line%|*} - filename=${line#*|} + id=${line%::AtOM:SQL:Sep::*} + filename=${line#*::AtOM:SQL:Sep::} if [ -n "$filename" ] then if rm -f "$filename" @@ -220,12 +220,12 @@ done echo 'BEGIN TRANSACTION;' >&3 for line in "${tagfiles[@]}" do - sourcefileid=${line%%|*} - rest=${line#*|} - lastchange=${rest%%|*} - rest=${rest#*|} - mimetype=${rest%%|*} - filename=${rest#*|} + sourcefileid=${line%%::AtOM:SQL:Sep::*} + rest=${line#*::AtOM:SQL:Sep::} + lastchange=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + mimetype=${rest%%::AtOM:SQL:Sep::*} + filename=${rest#*::AtOM:SQL:Sep::} echo -en "\rTags: $((++count*100/filecount))%" if (( count % 1000 == 0 )) then @@ -376,7 +376,7 @@ echo ' read -u4 line while ! [[ $line = AtOM:NoMoreFiles ]] do - decodefiles+=("$line|") + decodefiles+=("$line::AtOM:SQL:Sep::") read -u4 line done echo -n 'Creating tasks... ' @@ -384,41 +384,41 @@ echo -n 'Creating tasks... ' echo 'BEGIN TRANSACTION;' >&3 for line in "${decodefiles[@]}" do - fileid=${line%%|*} - rest=${line#*|} - filename=${rest%%|*} - rest=${rest#*|} - mimetype=${rest%%|*} - rest=${rest#*|} - destination=${rest%%|*} - rest=${rest#*|} - destfileid=${rest%%|*} - rest=${rest#*|} - rate=${rest%%|*} - rest=${rest#*|} - channels=${rest%%|*} - rest=${rest#*|} - bitrate=${rest%%|*} - rest=${rest#*|} - genre=${rest%%|*} - rest=${rest#*|} - albumartist=${rest%%|*} - rest=${rest#*|} - year=${rest%%|*} - rest=${rest#*|} - album=${rest%%|*} - rest=${rest#*|} - disc=${rest%%|*} - rest=${rest#*|} - artist=${rest%%|*} - rest=${rest#*|} - track=${rest%%|*} - rest=${rest#*|} - title=${rest%%|*} - rest=${rest#*|} - composer=${rest%%|*} - rest=${rest#*|} - performer=${rest%%|*} + fileid=${line%%::AtOM:SQL:Sep::*} + rest=${line#*::AtOM:SQL:Sep::} + filename=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + mimetype=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + destination=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + destfileid=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + rate=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + channels=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + bitrate=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + genre=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + albumartist=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + year=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + album=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + disc=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + artist=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + track=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + title=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + composer=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + performer=${rest%%::AtOM:SQL:Sep::*} unset rest decodeFile getDestDir @@ -647,32 +647,32 @@ do echo -n "$destination: rename pattern changed, renaming files... " while [[ $line != AtOM:NoMoreFiles ]] do - oldfilename=${line%%|*} - rest=${line#*|}'|' - destfileid=${rest%%|*} - rest=${rest#*|} - filename=${rest%%|*} - rest=${rest#*|} - album=${rest%%|*} - rest=${rest#*|} - albumartist=${rest%%|*} - rest=${rest#*|} - artist=${rest%%|*} - rest=${rest#*|} - composer=${rest%%|*} - rest=${rest#*|} - disc=${rest%%|*} - rest=${rest#*|} - genre=${rest%%|*} - rest=${rest#*|} - performer=${rest%%|*} - rest=${rest#*|} - title=${rest%%|*} - rest=${rest#*|} - track=${rest%%|*} - rest=${rest#*|} - year=${rest%%|*} - rest=${rest#*|} + oldfilename=${line%%::AtOM:SQL:Sep::*} + rest=${line#*::AtOM:SQL:Sep::}'::AtOM:SQL:Sep::' + destfileid=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + filename=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + album=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + albumartist=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + artist=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + composer=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + disc=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + genre=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + performer=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + title=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + track=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + year=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} if [ -n "$oldfilename" -a -f "$oldfilename" ] then getDestDir @@ -720,10 +720,10 @@ done echo 'BEGIN TRANSACTION;' >&3 for line in "${lines[@]}" do - id=${line%%|*} - rest=${line#*|} - filename=${rest%%|*} - oldfilename=${rest#*|} + id=${line%%::AtOM:SQL:Sep::*} + rest=${line#*::AtOM:SQL:Sep::} + filename=${rest%%::AtOM:SQL:Sep::*} + oldfilename=${rest#*::AtOM:SQL:Sep::} if [[ $oldfilename != $filename ]] && [ -f "$oldfilename" ] then rm -f "$oldfilename" diff --git a/lib/copy/copyFiles_action b/lib/copy/copyFiles_action index 86820cc..c0c352f 100644 --- a/lib/copy/copyFiles_action +++ b/lib/copy/copyFiles_action @@ -31,15 +31,15 @@ copyFiles_action() { echo 'BEGIN TRANSACTION;' >&3 for copyfile in "${copyfiles[@]}" do - sourcefilename=${copyfile%%|*} + sourcefilename=${copyfile%%::AtOM:SQL:Sep::*} sourcedir=${sourcefilename%/*} - rest="${copyfile#*|}|" - lastchange=${rest%%|*} - rest=${rest#*|} - destinationid=${rest%%|*} - rest=${rest#*|} - destfileid=${rest%%|*} - rest=${rest#*|} + rest="${copyfile#*::AtOM:SQL:Sep::}::AtOM:SQL:Sep::" + lastchange=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + destinationid=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + destfileid=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} echo 'SELECT IFNULL( ( SELECT destination_files.filename FROM destination_files diff --git a/lib/database/openDatabase b/lib/database/openDatabase index df05d84..b75cef4 100644 --- a/lib/database/openDatabase +++ b/lib/database/openDatabase @@ -24,5 +24,6 @@ openDatabase() { exec 3> >(tee -a $tempdir/debug.log >&5) fi cat $schema >&3 + echo '.separator ::AtOM:SQL:Sep::' >&3 echo 'PRAGMA foreign_keys = ON;' >&3 } diff --git a/lib/files/sanitizeFile b/lib/files/sanitizeFile index 07e8e50..2968f5e 100644 --- a/lib/files/sanitizeFile +++ b/lib/files/sanitizeFile @@ -27,5 +27,12 @@ sanitizeFile() { string=${string/%+(.)/} fi fi + # Not exactly filename sanitity, but these will make the script fail in + # a decorative way.. + string="${string//&/\\&}" + strint="${string//;/\\;}" + # And these would exhibit strange behaviors + string="${string//\[/\\\[}" + string="${string//\]/\\\]}" echo "$string" } diff --git a/lib/tasks/gettaskinfos b/lib/tasks/gettaskinfos index f0023bd..5a51657 100644 --- a/lib/tasks/gettaskinfos +++ b/lib/tasks/gettaskinfos @@ -12,16 +12,16 @@ gettaskinfos() { WHERE id='$1'; ' >&3 read -u4 line - taskid=${line%%|*} - rest="${line#*|}|" - sourcefileid=${rest%%|*} - rest=${rest#*|} - required=${rest%%|*} - rest=${rest#*|} - cleanup=${rest%%|*} - rest=${rest#*|} - destfileid=${rest%%|*} - rest=${rest#*|} - destfilename=${rest%%|*} - rest=${rest#*|} + taskid=${line%%::AtOM:SQL:Sep::*} + rest="${line#*::AtOM:SQL:Sep::}::AtOM:SQL:Sep::" + sourcefileid=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + required=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + cleanup=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + destfileid=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + destfilename=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} } diff --git a/lib/workers/master b/lib/workers/master index 4c22abe..a6d0c99 100644 --- a/lib/workers/master +++ b/lib/workers/master @@ -69,78 +69,78 @@ master() { else (( ++active )) read -u4 line - taskid=${line%%|*} - rest="${line#*|}|" - sourcefileid=${rest%%|*} - rest=${rest#*|} - required=${rest%%|*} - rest=${rest#*|} - cmd_arg=("${rest%%|*}") - rest=${rest#*|} - cmd_arg+=("${rest%%|*}") - rest=${rest#*|} - cmd_arg+=("${rest%%|*}") - rest=${rest#*|} - cmd_arg+=("${rest%%|*}") - rest=${rest#*|} - cmd_arg+=("${rest%%|*}") - rest=${rest#*|} - cmd_arg+=("${rest%%|*}") - rest=${rest#*|} - cmd_arg+=("${rest%%|*}") - rest=${rest#*|} - cmd_arg+=("${rest%%|*}") - rest=${rest#*|} - cmd_arg+=("${rest%%|*}") - rest=${rest#*|} - cmd_arg+=("${rest%%|*}") - rest=${rest#*|} - cmd_arg+=("${rest%%|*}") - rest=${rest#*|} - cmd_arg+=("${rest%%|*}") - rest=${rest#*|} - cmd_arg+=("${rest%%|*}") - rest=${rest#*|} - cmd_arg+=("${rest%%|*}") - rest=${rest#*|} - cmd_arg+=("${rest%%|*}") - rest=${rest#*|} - cmd_arg+=("${rest%%|*}") - rest=${rest#*|} - cmd_arg+=("${rest%%|*}") - rest=${rest#*|} - cmd_arg+=("${rest%%|*}") - rest=${rest#*|} - cmd_arg+=("${rest%%|*}") - rest=${rest#*|} - cmd_arg+=("${rest%%|*}") - rest=${rest#*|} - cmd_arg+=("${rest%%|*}") - rest=${rest#*|} - cmd_arg+=("${rest%%|*}") - rest=${rest#*|} - cmd_arg+=("${rest%%|*}") - rest=${rest#*|} - cmd_arg+=("${rest%%|*}") - rest=${rest#*|} - cmd_arg+=("${rest%%|*}") - rest=${rest#*|} - cmd_arg+=("${rest%%|*}") - rest=${rest#*|} - cmd_arg+=("${rest%%|*}") - rest=${rest#*|} - cmd_arg+=("${rest%%|*}") - rest=${rest#*|} - cmd_arg+=("${rest%%|*}") - rest=${rest#*|} - cmd_arg+=("${rest%%|*}") - rest=${rest#*|} - cleanup=${rest%%|*} - rest=${rest#*|} - destfileid=${rest%%|*} - rest=${rest#*|} - destfilename=${rest%%|*} - rest=${rest#*|} + taskid=${line%%::AtOM:SQL:Sep::*} + rest="${line#*::AtOM:SQL:Sep::}::AtOM:SQL:Sep::" + sourcefileid=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + required=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + cmd_arg=("${rest%%::AtOM:SQL:Sep::*}") + rest=${rest#*::AtOM:SQL:Sep::} + cmd_arg+=("${rest%%::AtOM:SQL:Sep::*}") + rest=${rest#*::AtOM:SQL:Sep::} + cmd_arg+=("${rest%%::AtOM:SQL:Sep::*}") + rest=${rest#*::AtOM:SQL:Sep::} + cmd_arg+=("${rest%%::AtOM:SQL:Sep::*}") + rest=${rest#*::AtOM:SQL:Sep::} + cmd_arg+=("${rest%%::AtOM:SQL:Sep::*}") + rest=${rest#*::AtOM:SQL:Sep::} + cmd_arg+=("${rest%%::AtOM:SQL:Sep::*}") + rest=${rest#*::AtOM:SQL:Sep::} + cmd_arg+=("${rest%%::AtOM:SQL:Sep::*}") + rest=${rest#*::AtOM:SQL:Sep::} + cmd_arg+=("${rest%%::AtOM:SQL:Sep::*}") + rest=${rest#*::AtOM:SQL:Sep::} + cmd_arg+=("${rest%%::AtOM:SQL:Sep::*}") + rest=${rest#*::AtOM:SQL:Sep::} + cmd_arg+=("${rest%%::AtOM:SQL:Sep::*}") + rest=${rest#*::AtOM:SQL:Sep::} + cmd_arg+=("${rest%%::AtOM:SQL:Sep::*}") + rest=${rest#*::AtOM:SQL:Sep::} + cmd_arg+=("${rest%%::AtOM:SQL:Sep::*}") + rest=${rest#*::AtOM:SQL:Sep::} + cmd_arg+=("${rest%%::AtOM:SQL:Sep::*}") + rest=${rest#*::AtOM:SQL:Sep::} + cmd_arg+=("${rest%%::AtOM:SQL:Sep::*}") + rest=${rest#*::AtOM:SQL:Sep::} + cmd_arg+=("${rest%%::AtOM:SQL:Sep::*}") + rest=${rest#*::AtOM:SQL:Sep::} + cmd_arg+=("${rest%%::AtOM:SQL:Sep::*}") + rest=${rest#*::AtOM:SQL:Sep::} + cmd_arg+=("${rest%%::AtOM:SQL:Sep::*}") + rest=${rest#*::AtOM:SQL:Sep::} + cmd_arg+=("${rest%%::AtOM:SQL:Sep::*}") + rest=${rest#*::AtOM:SQL:Sep::} + cmd_arg+=("${rest%%::AtOM:SQL:Sep::*}") + rest=${rest#*::AtOM:SQL:Sep::} + cmd_arg+=("${rest%%::AtOM:SQL:Sep::*}") + rest=${rest#*::AtOM:SQL:Sep::} + cmd_arg+=("${rest%%::AtOM:SQL:Sep::*}") + rest=${rest#*::AtOM:SQL:Sep::} + cmd_arg+=("${rest%%::AtOM:SQL:Sep::*}") + rest=${rest#*::AtOM:SQL:Sep::} + cmd_arg+=("${rest%%::AtOM:SQL:Sep::*}") + rest=${rest#*::AtOM:SQL:Sep::} + cmd_arg+=("${rest%%::AtOM:SQL:Sep::*}") + rest=${rest#*::AtOM:SQL:Sep::} + cmd_arg+=("${rest%%::AtOM:SQL:Sep::*}") + rest=${rest#*::AtOM:SQL:Sep::} + cmd_arg+=("${rest%%::AtOM:SQL:Sep::*}") + rest=${rest#*::AtOM:SQL:Sep::} + cmd_arg+=("${rest%%::AtOM:SQL:Sep::*}") + rest=${rest#*::AtOM:SQL:Sep::} + cmd_arg+=("${rest%%::AtOM:SQL:Sep::*}") + rest=${rest#*::AtOM:SQL:Sep::} + cmd_arg+=("${rest%%::AtOM:SQL:Sep::*}") + rest=${rest#*::AtOM:SQL:Sep::} + cmd_arg+=("${rest%%::AtOM:SQL:Sep::*}") + rest=${rest#*::AtOM:SQL:Sep::} + cleanup=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + destfileid=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + destfilename=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} for key in ${!cmd_arg[@]} do [ -z "${cmd_arg[key]}" ] && unset cmd_arg[key] diff --git a/toys/checkextensions b/toys/checkextensions index a390bc1..3a427ff 100755 --- a/toys/checkextensions +++ b/toys/checkextensions @@ -112,8 +112,8 @@ getdstfiles() { done for line in "${lines[@]}" do - fileid=${line%|*} - filename=${line#*|} + fileid=${line%::AtOM:SQL:Sep::*} + filename=${line#*::AtOM:SQL:Sep::} echo $'\t'"$filename" (( rename )) && echo -n $'\t' (( rename )) && renameFile @@ -149,12 +149,12 @@ do done for line in "${lines[@]}" do - fileid=${line%%|*} - rest="${line#*|}|" - filename=${rest%%|*} - rest=${rest#*|} - mimetype=${rest%%|*} - rest=${rest#*|} + fileid=${line%%::AtOM:SQL:Sep::*} + rest="${line#*::AtOM:SQL:Sep::}::AtOM:SQL:Sep::" + filename=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + mimetype=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} dest=$sourcepath case "$mimetype" in 'audio/mpeg') diff --git a/toys/missingtags b/toys/missingtags index c64f5ee..ab73d1b 100755 --- a/toys/missingtags +++ b/toys/missingtags @@ -140,33 +140,33 @@ done for line in "${lines[@]}" do missing=() - filename=${line%%|*} - rest="${line#*|}|" - (( ${checks[genre]} )) && [ -z "${rest%%|*}" ] && missing+=( "Genre" ) - rest=${rest#*|} - (( ${checks[albumartist]} )) && [ -z "${rest%%|*}" ] && missing+=( "AlbumArtist" ) - rest=${rest#*|} - (( ${checks[year]} )) && [ -z "${rest%%|*}" ] && missing+=( "Year" ) - rest=${rest#*|} - (( ${checks[album]} )) && [ -z "${rest%%|*}" ] && missing+=( "Album" ) - rest=${rest#*|} - (( ${checks[disc]} )) && [ -z "${rest%%|*}" ] && missing+=( "Disc" ) - rest=${rest#*|} - (( ${checks[artist]} )) && [ -z "${rest%%|*}" ] && missing+=( "Artist" ) - rest=${rest#*|} - track=${rest%%|*} + filename=${line%%::AtOM:SQL:Sep::*} + rest="${line#*::AtOM:SQL:Sep::}::AtOM:SQL:Sep::" + (( ${checks[genre]} )) && [ -z "${rest%%::AtOM:SQL:Sep::*}" ] && missing+=( "Genre" ) + rest=${rest#*::AtOM:SQL:Sep::} + (( ${checks[albumartist]} )) && [ -z "${rest%%::AtOM:SQL:Sep::*}" ] && missing+=( "AlbumArtist" ) + rest=${rest#*::AtOM:SQL:Sep::} + (( ${checks[year]} )) && [ -z "${rest%%::AtOM:SQL:Sep::*}" ] && missing+=( "Year" ) + rest=${rest#*::AtOM:SQL:Sep::} + (( ${checks[album]} )) && [ -z "${rest%%::AtOM:SQL:Sep::*}" ] && missing+=( "Album" ) + rest=${rest#*::AtOM:SQL:Sep::} + (( ${checks[disc]} )) && [ -z "${rest%%::AtOM:SQL:Sep::*}" ] && missing+=( "Disc" ) + rest=${rest#*::AtOM:SQL:Sep::} + (( ${checks[artist]} )) && [ -z "${rest%%::AtOM:SQL:Sep::*}" ] && missing+=( "Artist" ) + rest=${rest#*::AtOM:SQL:Sep::} + track=${rest%%::AtOM:SQL:Sep::*} (( ${checks[track]} )) && [ -z "$track" ] && missing+=( "Track" ) if (( ${checks[tracktotal]} )) && ! [[ $track =~ / ]] then missing+=( TrackTotal ) fi - rest=${rest#*|} - (( ${checks[title]} )) && [ -z "${rest%%|*}" ] && missing+=( "Title" ) - rest=${rest#*|} - (( ${checks[composer]} )) && [ -z "${rest%%|*}" ] && missing+=( "Composer" ) - rest=${rest#*|} - (( ${checks[performer]} )) && [ -z "${rest%%|*}" ] && missing+=( "Performer" ) - rest=${rest#*|} + rest=${rest#*::AtOM:SQL:Sep::} + (( ${checks[title]} )) && [ -z "${rest%%::AtOM:SQL:Sep::*}" ] && missing+=( "Title" ) + rest=${rest#*::AtOM:SQL:Sep::} + (( ${checks[composer]} )) && [ -z "${rest%%::AtOM:SQL:Sep::*}" ] && missing+=( "Composer" ) + rest=${rest#*::AtOM:SQL:Sep::} + (( ${checks[performer]} )) && [ -z "${rest%%::AtOM:SQL:Sep::*}" ] && missing+=( "Performer" ) + rest=${rest#*::AtOM:SQL:Sep::} echo "$filename: ${missing[@]}" done From 9c2f765f5c95d67e6f2f1c20a1079df4c1873b31 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Thu, 2 May 2013 03:40:24 +0200 Subject: [PATCH 06/10] toys/missingtags: skip text and image files --- toys/missingtags | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/toys/missingtags b/toys/missingtags index ab73d1b..780b475 100755 --- a/toys/missingtags +++ b/toys/missingtags @@ -99,10 +99,10 @@ for check in ${!checks[@]} do case $check in tracktotal) - whereclause+="${whereclause+ OR }NOT tags.track LIKE \"%/%\"" + whereclause+="${whereclause+OR }NOT tags.track LIKE \"%/%\"" ;; *) - whereclause+="${whereclause+ OR }tags.$check IS NULL" + whereclause+="${whereclause+OR }tags.$check IS NULL" ;; esac whereclause+=' @@ -124,8 +124,15 @@ cat >&3 <<-EOSelect FROM tags INNER JOIN source_files ON tags.source_file=source_files.id - WHERE $whereclause - AND NOT tags.tagreader LIKE "unknown-%"; + INNER JOIN mime_types + ON source_files.mime_type=mime_types.id + WHERE ( + $whereclause + ) + AND NOT tags.tagreader LIKE "unknown-%" + AND NOT mime_types.mime_text LIKE "text/%" + AND NOT mime_types.mime_text LIKE "image/%" + ; SELECT "AtOM:NoMoreFiles"; EOSelect From 7b34e0eb11993dd3ffd6a17a9b0ebe5791f827aa Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Thu, 2 May 2013 03:49:21 +0200 Subject: [PATCH 07/10] ffmpag: fix "year" tag --- lib/tags/getInfos::ffmpeg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tags/getInfos::ffmpeg b/lib/tags/getInfos::ffmpeg index 5f129f3..e03e879 100644 --- a/lib/tags/getInfos::ffmpeg +++ b/lib/tags/getInfos::ffmpeg @@ -1,5 +1,5 @@ #!/bin/bash -getInfosffmpeg_version='ffmpeg-1' +getInfosffmpeg_version='ffmpeg-2' tagreaders+=( "$getInfosffmpeg_version" ) getInfos::ffmpeg() { tagreader="$getInfosffmpeg_version" @@ -32,7 +32,7 @@ getInfos::ffmpeg() { performer=$(gettag TOPE) title=$(gettag title) tracknum=$(gettag track) - year=$(gettag year) + year=$(gettag date) expr='^[0-9]*$' if [ -n "$genre" ] && [[ $genre =~ $expr ]] then From 7c8617d713cafe4f70ec81ad6ad0421107bfdeef Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Thu, 2 May 2013 03:58:15 +0200 Subject: [PATCH 08/10] create function updateTags() * move code from atom to updateTags() * toys/missingtags: update tags --- atom | 110 +------------------------------------------ lib/tags/updateTags | 111 ++++++++++++++++++++++++++++++++++++++++++++ toys/missingtags | 1 + 3 files changed, 113 insertions(+), 109 deletions(-) create mode 100644 lib/tags/updateTags diff --git a/atom b/atom index dff6205..5c35308 100755 --- a/atom +++ b/atom @@ -161,115 +161,7 @@ do done echo "Suppressed $deleted files, $removed removed from database" -# get files -for reader in "${tagreaders[@]}" -do - tagreaderclause+="${tagreaderclause:+ AND }NOT tags.tagreader = \"$reader\"" -done -echo ' - SELECT COUNT(DISTINCT source_files.filename) - FROM source_files - INNER JOIN destination_files - ON destination_files.source_file_id=source_files.id - INNER JOIN destinations - ON destination_files.destination_id=destinations.id - INNER JOIN mime_type_actions - ON destinations.id=mime_type_actions.destination_id - INNER JOIN tags - ON source_files.id=tags.source_file - WHERE mime_type_actions.id = source_files.mime_type - AND ( - CAST(tags.last_change AS TEXT) - <> - CAST(source_files.last_change AS TEXT) - OR ('"$tagreaderclause"') - ) - AND mime_type_actions.action = 1;' >&3 -read -u4 filecount -echo ' - SELECT DISTINCT - source_files.id, - source_files.last_change, - mime_type_actions.mime_text, - source_files.filename - FROM source_files - INNER JOIN destination_files - ON destination_files.source_file_id=source_files.id - INNER JOIN destinations - ON destination_files.destination_id=destinations.id - INNER JOIN mime_type_actions - ON destinations.id=mime_type_actions.destination_id - INNER JOIN tags - ON source_files.id=tags.source_file - WHERE mime_type_actions.id = source_files.mime_type - AND ( - CAST(tags.last_change AS TEXT) - <> - CAST(source_files.last_change AS TEXT) - OR ('"$tagreaderclause"') - ) - AND mime_type_actions.action = 1; - - SELECT "AtOM:NoMoreFiles";' >&3 -read -u4 line -while ! [[ $line = AtOM:NoMoreFiles ]] -do - tagfiles+=("$line") - read -u4 line -done -echo 'BEGIN TRANSACTION;' >&3 -for line in "${tagfiles[@]}" -do - sourcefileid=${line%%::AtOM:SQL:Sep::*} - rest=${line#*::AtOM:SQL:Sep::} - lastchange=${rest%%::AtOM:SQL:Sep::*} - rest=${rest#*::AtOM:SQL:Sep::} - mimetype=${rest%%::AtOM:SQL:Sep::*} - filename=${rest#*::AtOM:SQL:Sep::} - echo -en "\rTags: $((++count*100/filecount))%" - if (( count % 1000 == 0 )) - then - echo 'COMMIT;BEGIN TRANSACTION;' >&3 - (( debug )) \ - && echo -n " $count files read, committing..." - fi - if getTags - then - Update tags \ - album "${album:-NULL}" \ - albumartist "${albumartist:-NULL}" \ - artist "${artist:-NULL}" \ - composer "${composer:-NULL}" \ - disc "${disc:-NULL}" \ - genre "${genre:-NULL}" \ - performer "${performer:-NULL}" \ - title "${title:-NULL}" \ - track "${tracknum:-NULL}" \ - year "${year:-NULL}" \ - last_change "$lastchange" \ - rate "${rate:-NULL}" \ - channels "${channels:-NULL}" \ - bitrate "${bitrate:-NULL}" \ - tagreader "$tagreader" \ - >/dev/null <<<"source_file = $sourcefileid" - unset genre \ - albumartist \ - year \ - album \ - disc \ - artist \ - tracknum \ - title \ - composer \ - performer \ - rate \ - bitrate \ - channels - fi -done -echo 'COMMIT;' >&3 -echo -e "\rRead tags from ${count:-0} files.\033[K" -unset count tagfiles +updateTags echo ' CREATE TEMPORARY TABLE tasks( diff --git a/lib/tags/updateTags b/lib/tags/updateTags new file mode 100644 index 0000000..d317c1a --- /dev/null +++ b/lib/tags/updateTags @@ -0,0 +1,111 @@ +#!/bin/bash +updateTags() { + for reader in "${tagreaders[@]}" + do + tagreaderclause+="${tagreaderclause:+ AND }NOT tags.tagreader = \"$reader\"" + done + echo ' + SELECT COUNT(DISTINCT source_files.filename) + FROM source_files + INNER JOIN destination_files + ON destination_files.source_file_id=source_files.id + INNER JOIN destinations + ON destination_files.destination_id=destinations.id + INNER JOIN mime_type_actions + ON destinations.id=mime_type_actions.destination_id + INNER JOIN tags + ON source_files.id=tags.source_file + WHERE mime_type_actions.id = source_files.mime_type + AND ( + CAST(tags.last_change AS TEXT) + <> + CAST(source_files.last_change AS TEXT) + OR ('"$tagreaderclause"') + ) + AND mime_type_actions.action = 1;' >&3 + read -u4 filecount + echo ' + SELECT DISTINCT + source_files.id, + source_files.last_change, + mime_type_actions.mime_text, + source_files.filename + FROM source_files + INNER JOIN destination_files + ON destination_files.source_file_id=source_files.id + INNER JOIN destinations + ON destination_files.destination_id=destinations.id + INNER JOIN mime_type_actions + ON destinations.id=mime_type_actions.destination_id + INNER JOIN tags + ON source_files.id=tags.source_file + WHERE mime_type_actions.id = source_files.mime_type + AND ( + CAST(tags.last_change AS TEXT) + <> + CAST(source_files.last_change AS TEXT) + OR ('"$tagreaderclause"') + ) + AND mime_type_actions.action = 1; + + SELECT "AtOM:NoMoreFiles";' >&3 + read -u4 line + while ! [[ $line = AtOM:NoMoreFiles ]] + do + tagfiles+=("$line") + read -u4 line + done + echo 'BEGIN TRANSACTION;' >&3 + for line in "${tagfiles[@]}" + do + sourcefileid=${line%%::AtOM:SQL:Sep::*} + rest=${line#*::AtOM:SQL:Sep::} + lastchange=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + mimetype=${rest%%::AtOM:SQL:Sep::*} + filename=${rest#*::AtOM:SQL:Sep::} + echo -en "\rTags: $((++count*100/filecount))%" + if (( count % 1000 == 0 )) + then + echo 'COMMIT;BEGIN TRANSACTION;' >&3 + (( debug )) \ + && echo -n " $count files read, committing..." + fi + if getTags + then + Update tags \ + album "${album:-NULL}" \ + albumartist "${albumartist:-NULL}" \ + artist "${artist:-NULL}" \ + composer "${composer:-NULL}" \ + disc "${disc:-NULL}" \ + genre "${genre:-NULL}" \ + performer "${performer:-NULL}" \ + title "${title:-NULL}" \ + track "${tracknum:-NULL}" \ + year "${year:-NULL}" \ + last_change "$lastchange" \ + rate "${rate:-NULL}" \ + channels "${channels:-NULL}" \ + bitrate "${bitrate:-NULL}" \ + tagreader "$tagreader" \ + >/dev/null <<<"source_file = $sourcefileid" + unset genre \ + albumartist \ + year \ + album \ + disc \ + artist \ + tracknum \ + title \ + composer \ + performer \ + rate \ + bitrate \ + channels + fi + done + echo 'COMMIT;' >&3 + echo -e "\rRead tags from ${count:-0} files.\033[K" + unset count tagfiles +} diff --git a/toys/missingtags b/toys/missingtags index 780b475..72f723b 100755 --- a/toys/missingtags +++ b/toys/missingtags @@ -93,6 +93,7 @@ if (( update )) then getFiles updateMimes + updateTags fi for check in ${!checks[@]} From 8b3f121179d5f8226f18c36df614b6e7e6f087ae Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Fri, 3 May 2013 17:25:07 +0200 Subject: [PATCH 09/10] Fix file renaming --- lib/copy/copyFiles_action | 3 +++ lib/files/getDestDir | 16 ++++++++-------- lib/files/getDestFile | 16 ++++++++-------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/lib/copy/copyFiles_action b/lib/copy/copyFiles_action index c0c352f..a944ef8 100644 --- a/lib/copy/copyFiles_action +++ b/lib/copy/copyFiles_action @@ -6,6 +6,7 @@ copyFiles_action() { source_files.filename, source_files.last_change, destinations.id, + destinations.name, destination_files.id FROM source_files INNER JOIN destination_files @@ -38,6 +39,8 @@ copyFiles_action() { rest=${rest#*::AtOM:SQL:Sep::} destinationid=${rest%%::AtOM:SQL:Sep::*} rest=${rest#*::AtOM:SQL:Sep::} + destination=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} destfileid=${rest%%::AtOM:SQL:Sep::*} rest=${rest#*::AtOM:SQL:Sep::} echo 'SELECT IFNULL( ( diff --git a/lib/files/getDestDir b/lib/files/getDestDir index 787adaf..ff4f26b 100644 --- a/lib/files/getDestDir +++ b/lib/files/getDestDir @@ -4,28 +4,28 @@ getDestDir() { if [ -n "${destinationrenamepath[$destination]}" ] \ && ( ( - ! [[ ${destinationrenamepath[$destination]} =~ %{album} ]] \ + ! [[ ${destinationrenamepath[$destination]} =~ %\{album\} ]] \ || [ -n "$album" ] ) && ( - ! [[ ${destinationrenamepath[$destination]} =~ %{albumartist} ]] \ + ! [[ ${destinationrenamepath[$destination]} =~ %\{albumartist\} ]] \ || [ -n "$albumartist" ] ) && ( - ! [[ ${destinationrenamepath[$destination]} =~ %{artist} ]] \ + ! [[ ${destinationrenamepath[$destination]} =~ %\{artist\} ]] \ || [ -n "$artist" ] ) && ( - ! [[ ${destinationrenamepath[$destination]} =~ %{genre} ]] \ + ! [[ ${destinationrenamepath[$destination]} =~ %\{genre\} ]] \ || [ -n "$genre" ] ) && ( - ! [[ ${destinationrenamepath[$destination]} =~ %{title} ]] \ + ! [[ ${destinationrenamepath[$destination]} =~ %\{title\} ]] \ || [ -n "$title" ] ) && ( - ! [[ ${destinationrenamepath[$destination]} =~ %{track} ]] \ + ! [[ ${destinationrenamepath[$destination]} =~ %\{track\} ]] \ || [ -n "$track" ] ) && ( - ! [[ ${destinationrenamepath[$destination]} =~ %{year} ]] \ + ! [[ ${destinationrenamepath[$destination]} =~ %\{year\} ]] \ || [ -n "$year" ] ) && ( - ! [[ ${destinationrenamepath[$destination]} =~ %{disc} ]] \ + ! [[ ${destinationrenamepath[$destination]} =~ %\{disc\} ]] \ || [ -n "$disc" ] ) ) diff --git a/lib/files/getDestFile b/lib/files/getDestFile index e943b41..1ec9087 100644 --- a/lib/files/getDestFile +++ b/lib/files/getDestFile @@ -3,28 +3,28 @@ getDestFile() { if [ -n "${destinationrename[$destination]}" ] \ && ( ( - ! [[ ${destinationrename[$destination]} =~ %{album} ]] \ + ! [[ ${destinationrename[$destination]} =~ %\{album\} ]] \ || [ -n "$album" ] ) && ( - ! [[ ${destinationrename[$destination]} =~ %{albumartist} ]] \ + ! [[ ${destinationrename[$destination]} =~ %\{albumartist\} ]] \ || [ -n "$albumartist" ] ) && ( - ! [[ ${destinationrename[$destination]} =~ %{artist} ]] \ + ! [[ ${destinationrename[$destination]} =~ %\{artist\} ]] \ || [ -n "$artist" ] ) && ( - ! [[ ${destinationrename[$destination]} =~ %{genre} ]] \ + ! [[ ${destinationrename[$destination]} =~ %\{genre\} ]] \ || [ -n "$genre" ] ) && ( - ! [[ ${destinationrename[$destination]} =~ %{title} ]] \ + ! [[ ${destinationrename[$destination]} =~ %\{title\} ]] \ || [ -n "$title" ] ) && ( - ! [[ ${destinationrename[$destination]} =~ %{track} ]] \ + ! [[ ${destinationrename[$destination]} =~ %\{track\} ]] \ || [ -n "$track" ] ) && ( - ! [[ ${destinationrename[$destination]} =~ %{year} ]] \ + ! [[ ${destinationrename[$destination]} =~ %\{year\} ]] \ || [ -n "$year" ] ) && ( - ! [[ ${destinationrename[$destination]} =~ %{disc} ]] \ + ! [[ ${destinationrename[$destination]} =~ %\{disc\} ]] \ || [ -n "$disc" ] ) ) From 0d511b26745cc8e93e1420792be2f7301cf97900 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Sat, 4 May 2013 01:38:48 +0200 Subject: [PATCH 10/10] toys/cleandestinations: handle special chars correctly --- toys/cleandestinations | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toys/cleandestinations b/toys/cleandestinations index a2e9845..b80e767 100755 --- a/toys/cleandestinations +++ b/toys/cleandestinations @@ -61,7 +61,7 @@ checkwanted() { for destination in "${!destinationpath[@]}" do echo -ne "\rScanning destination $destination... \033[K" - while read filename + while read -r filename do if ! Select destination_files id \ >/dev/null \