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