Fixed playlist sync in parallel

This commit is contained in:
Jeroen De Meerleer 2020-02-16 13:27:14 +01:00
parent ddbca852db
commit f4c71cd38e

View File

@ -53,8 +53,8 @@ jobcount=$(expr $(nproc) - 2)
multithread=false multithread=false
script_name=$(basename "${0}") script_name=$(basename "${0}")
script_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) script_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
listmapping[0]='' mappingdest=''
listmapping[1]='' mappingsrc=''
windowspaths=false windowspaths=false
playlists=false playlists=false
@ -237,10 +237,10 @@ GetOptions() {
-m|--mapping) -m|--mapping)
VerboseOutput 0 "--mapping given" VerboseOutput 0 "--mapping given"
listmappingparam=(${2//,/ }) listmappingparam=(${2//,/ })
listmapping[0]=${listmappingparam[0]:-""} mappingsrc=${listmappingparam[0]:-""}
listmapping[1]=${listmappingparam[1]:-""} mappingdest=${listmappingparam[1]:-""}
shift 2 shift 2
VerboseOutput 1 "Playlist mappings enabled source=${listmapping[0]} dest=${listmapping[1]}" VerboseOutput 1 "Playlist mappings enabled source=${mappingsrc} dest=${mappingdest}"
;; ;;
--) --)
shift shift
@ -358,6 +358,9 @@ Execute() {
export verbose export verbose
export coverartsize export coverartsize
export begin export begin
export windowspaths
export mappingsrc
export mappingdest
parallel --jobs ${jobcount} --will-cite --line-buffer --arg-file "/tmp/music-sync-filelist" ProcessFile parallel --jobs ${jobcount} --will-cite --line-buffer --arg-file "/tmp/music-sync-filelist" ProcessFile
else else
for line in $(cat "/tmp/music-sync-filelist") for line in $(cat "/tmp/music-sync-filelist")
@ -399,19 +402,23 @@ ConvertPlaylist() {
fi; fi;
if [[ -f "$temp/$line" ]]; then if [[ -f "$temp/$line" ]]; then
rm $temp/$line rm "$temp/$line"
fi fi
search=${listmapping[0]}
replace=${listmapping[1]}
VerboseOutput 0 "Creating playlist $temp/$line" VerboseOutput 0 "Creating playlist $temp/$line"
IFS="
"
for item in $(cat "$source/$line") for item in $(cat "$source/$line")
do do
mp3item=$(echo $item | sed -e 's/\.*\//\//g'| tr -s ' ') mp3item=$(echo $item | sed -e 's/\.*\//\//g'| tr -s ' ')
playline=$(echo "${mp3item}" | sed -e "s,$mappingsrc,$mappingdest,g")
echo "${playline}"
echo "search: $mappingsrc"
echo "replace: $mappingdest"
echo $playline
if [[ $windowspaths == true ]]; then if [[ $windowspaths == true ]]; then
echo "${mp3item/$search/$replace}" | sed -e 's,\/,\\,g' >> $temp/$line playline=$(echo "${playline}" | sed -e 's,\/,\\,g')
else fi
echo "${mp3item/$search/$replace}" >> $temp/$line echo $playline >> $temp/$line
fi
done done
if [[ $windowspaths == true ]]; then if [[ $windowspaths == true ]]; then
VerboseOutput 0 "Converting lf to crlf" VerboseOutput 0 "Converting lf to crlf"