diff --git a/atom b/atom index 445277b..1f392d3 100755 --- a/atom +++ b/atom @@ -214,9 +214,13 @@ read -u4 removecount until (( ${#removefile[@]} == removecount )) do echo ' - SELECT id, - filename + SELECT destination_files.id, + destinations.name, + destination_files.filename FROM destination_files + INNER JOIN destinations + ON destination_files.destination_id + = destinations.id WHERE source_file_id is NULL LIMIT 500 OFFSET '${#removefile[@]}'; @@ -226,7 +230,11 @@ do read -u4 line until [[ $line == AtOM:NoMoreFiles ]] do - removefile[${line%::AtOM:SQL:Sep::*}]="${line#*::AtOM:SQL:Sep::}" + removeFileId=${line%%::AtOM:SQL:Sep::*} + rest=${line#*::AtOM:SQL:Sep::} + removeFileDestName=${line%%::AtOM:SQL:Sep::*} + rest=${line#*::AtOM:SQL:Sep::} + removefile[$removeFileId]="${destinationpath["$removeFileDestName"]}/${rest%%::AtOM:SQL:Sep::*}" read -u4 line done done @@ -288,6 +296,7 @@ echo ' ascii INTEGER, source_file INTEGER, fileid INTEGER, + destdir TEXT, filename TEXT, cmd_arg0 TEXT, cmd_arg1 TEXT, @@ -894,7 +903,9 @@ do progressSpin if [[ "$oldfilename" != "$destfilename" ]] then - mv "$oldfilename" "$destfilename" + mv \ + "${destinationpath[$destination]}/$oldfilename" \ + "${destinationpath[$destination]}/$destfilename" (( changedcount++ )) commit=1 fi @@ -929,10 +940,14 @@ done copyFiles_action echo ' - SELECT id, - filename, - old_filename + SELECT destination_files.id, + destination_files.filename, + destination_files.old_filename, + destinations.name FROM destination_files + INNER JOIN destinations + ON destination_files.destination_id + = destinations.id WHERE old_filename IS NOT NULL; SELECT "AtOM:NoMoreFiles"; @@ -952,10 +967,12 @@ do id=${line%%::AtOM:SQL:Sep::*} rest=${line#*::AtOM:SQL:Sep::} filename=${rest%%::AtOM:SQL:Sep::*} - oldfilename=${rest#*::AtOM:SQL:Sep::} + rest=${line#*::AtOM:SQL:Sep::} + oldfilename=${rest%%::AtOM:SQL:Sep::*} + destination=${rest#*::AtOM:SQL:Sep::} if [[ $oldfilename != "$filename" ]] && [ -f "$oldfilename" ] then - rm -f "$oldfilename" + rm -f "${destinationpath[$destination]}/$oldfilename" fi Update destination_files old_filename NULL <<<"id = $id" (( count++ )) diff --git a/lib/config/getDestination b/lib/config/getDestination index 5284c75..041917f 100644 --- a/lib/config/getDestination +++ b/lib/config/getDestination @@ -5,7 +5,7 @@ getConfigDestination() { destinationenabled["$destination"]="$value" ;; 'path') - destinationpath["$destination"]="$value" + destinationpath["$destination"]="${value%/}" ;; 'format') case "$value" in diff --git a/lib/database/checkVersion b/lib/database/checkVersion index 932afa5..33ac892 100644 --- a/lib/database/checkVersion +++ b/lib/database/checkVersion @@ -1,5 +1,5 @@ #!/usr/bin/env bash -currentdbversion=6 +currentdbversion=7 checkDatabaseVersion() { local dbversion if dbversion=$(Select atom version <<<"\"1\" = 1") diff --git a/lib/database/upgradedatabase_6_7 b/lib/database/upgradedatabase_6_7 new file mode 100644 index 0000000..7bbdfc4 --- /dev/null +++ b/lib/database/upgradedatabase_6_7 @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +upgradedatabase_6_7() { + echo "Upgrading database to version 7... (backup is $database.bak_v6)" + cp "$database" "$database.bak_v6" + for destination in "${destinations[@]}" + do + echo "UPDATE destination_files SET filename = REPLACE(filename,'${destinationpath[$destination]}/','') WHERE filename LIKE '${destinationpath[$destination]}/%';" >&3 + done + Update atom version 7 <<<"1 = 1" +} \ No newline at end of file diff --git a/lib/encode/mp3 b/lib/encode/mp3 index 22e9b74..d9fdc36 100644 --- a/lib/encode/mp3 +++ b/lib/encode/mp3 @@ -53,7 +53,7 @@ encodeFile::mp3() { esac fi fi - lameopts+=("$tempdir/$tmpfile.wav" "$destdir/$destfile.mp3") + lameopts+=("$tempdir/$tmpfile.wav" "${destinationpath[$destination]}/$destdir/$destfile.mp3") encodetaskid=$( Insert tasks <<-EOInsert key ${fileid}lame$destination diff --git a/lib/encode/opus b/lib/encode/opus index 18dc821..29b833e 100644 --- a/lib/encode/opus +++ b/lib/encode/opus @@ -23,7 +23,7 @@ encodeFile::opus() { [ -n "$track" ] && opusencopts+=(--comment "TRACKNUMBER=${track%/*}") [ -n "${track#*/}" ] && opusencopts+=(--comment "TRACKTOTAL=${track#*/}") [ -n "$year" ] && opusencopts+=(--comment "DATE=$year") - opusencopts+=("$tempdir/$tmpfile".wav "$destdir/$destfile.opus") + opusencopts+=("$tempdir/$tmpfile".wav "${destinationpath[$destination]}/$destdir/$destfile.opus") encodetaskid=$( Insert tasks <<-EOInsert key ${fileid}opusenc$destination diff --git a/lib/encode/vorbis b/lib/encode/vorbis index 6be67e5..40007c6 100644 --- a/lib/encode/vorbis +++ b/lib/encode/vorbis @@ -17,7 +17,7 @@ encodeFile::vorbis() { [ -n "$title" ] && oggencopts+=(-t "$title") [ -n "$track" ] && oggencopts+=(-N "$track") [ -n "$year" ] && oggencopts+=(-d "$year") - oggencopts+=(-o "$destdir/$destfile.ogg" "$tempdir/$tmpfile.wav") + oggencopts+=(-o "${destinationpath[$destination]}/$destdir/$destfile.ogg" "$tempdir/$tmpfile.wav") encodetaskid=$( Insert tasks <<-EOInsert key ${fileid}oggenc$destination diff --git a/lib/files/getDestDir b/lib/files/getDestDir index 2bf0073..79177e0 100644 --- a/lib/files/getDestDir +++ b/lib/files/getDestDir @@ -41,7 +41,7 @@ getDestDir() { ) ) then - destdir="${destinationpath[$destination]}/" + destdir="" if (( ${destinationascii["$destination"]} )) then echo "$album" >&${toascii[1]} @@ -83,8 +83,7 @@ getDestDir() { replace=$(sanitizeFile "$disc" dir) destdir="${destdir//?(\[)%\{disc\}?(\])/$replace}" else - destdir="${destinationpath[$destination]}/" - destdir+=$(sanitizeFile "${filename%%/*}" dir) + destdir=$(sanitizeFile "${filename%%/*}" dir) part=${filename#*/} while [[ $part =~ / ]] do @@ -101,7 +100,7 @@ getDestDir() { fi if ! [ -d "$destdir" ] then - mkdir -p "$destdir" + mkdir -p "${destinationpath[$destination]}/$destdir" fi destdir="${destdir//+(\/)//}" } diff --git a/lib/tags/gettags b/lib/tags/gettags index f541b7d..825a3df 100644 --- a/lib/tags/gettags +++ b/lib/tags/gettags @@ -1,7 +1,7 @@ #!/bin/bash getTags_version='unknown-4' getTags() { - unset type + local type case "$mimetype" in audio/mpeg) type=ffmpeg diff --git a/toys/checkextensions b/toys/checkextensions index 1abdd78..485e2c9 100755 --- a/toys/checkextensions +++ b/toys/checkextensions @@ -1,5 +1,13 @@ #!/usr/bin/env bash +cat <<-EOWarn + This script is unmaintained and provided as-is. It may or may not work. + + Use at your own risk! +EOWarn + +read -p "Press Enter to continue or Ctrl-C to abort" + # config structures declare -A \ destinationchannels \ diff --git a/toys/checkmissing b/toys/checkmissing index eabef5f..f747f17 100755 --- a/toys/checkmissing +++ b/toys/checkmissing @@ -62,27 +62,42 @@ getConfig sanityCheck openDatabase -echo 'SELECT id,filename FROM destination_files WHERE filename IS NOT NULL;' >&3 +echo ' + SELECT + destination_files.id, + destinations.name, + destination_files.filename + FROM destinations + INNER JOIN destination_files + ON destinations.id=destination_files.destination_id + WHERE filename IS NOT NULL;' >&3 echo 'SELECT "AtOM:NoMoreFiles";' >&3 -read -u4 filename -until [[ $filename == AtOM:NoMoreFiles ]] +declare -a \ + destination_names \ + files +read -u4 line +until [[ $line == AtOM:NoMoreFiles ]] do - files+=("$filename") - read -u4 filename + id=${line%%::AtOM:SQL:Sep::*} + rest=${line#*::AtOM:SQL:Sep::} + destination_names[id]=${rest%%::AtOM:SQL:Sep::*} + rest=${rest#*::AtOM:SQL:Sep::} + files[id]=${rest} + read -u4 line done echo 'BEGIN TRANSACTION;' >&3 echo -n "Checking for missing files... " -for filename in "${files[@]}" +for index in "${!files[@]}" do - id=${filename%%::AtOM:SQL:Sep::*} - filename=${filename#*::AtOM:SQL:Sep::} + destination=${destination_names[index]} + filename="${destinationpath[$destination]}/${files[index]}" if ! [ -f "$filename" ] then echo -e "\r$filename\033[K" - ((regen))&&Update destination_files last_change 0 <<<"id = $id" + ((regen))&&Update destination_files last_change 0 <<<"id = $index" echo -n "Checking for missing files... " (( missing++ )) fi @@ -91,6 +106,6 @@ done echo 'COMMIT;' >&3 -echo -e "\r${missing:-0} missing files\033[K" +echo -e "\r${missing:-No} missing files\033[K" closeDatabase diff --git a/toys/cleandestinations b/toys/cleandestinations index dc49966..10b9503 100755 --- a/toys/cleandestinations +++ b/toys/cleandestinations @@ -73,7 +73,7 @@ do do if ! Select destination_files id \ >/dev/null \ - <<<"filename = $filename" + <<<"filename = ${filename#${destinationpath["$destination"]}/}" then echo -e $'\r'"$filename\033[K" (( remove )) && rm -f "$filename"