Compare commits
No commits in common. "9e2b515bed91d95cf2d6b2bb1449cb263ea09ae2" and "c6be37116d9fc8fd3fd0cc7846d942005061efb4" have entirely different histories.
9e2b515bed
...
c6be37116d
56
README.MD
56
README.MD
|
@ -1,47 +1,45 @@
|
|||
# Bash Music sync
|
||||
(c) 2018-2020 Jeroen De Meerleer <me@jeroened.be>
|
||||
(c) 2018-2019 Jeroen De Meerleer <me@jeroened.be>
|
||||
|
||||
Script to sync music from one folder to another
|
||||
|
||||
## Usage:
|
||||
|
||||
```
|
||||
Syncronises music from one folder to another.
|
||||
music-sync <options> -s|--source <source> -d|--dest <destination>
|
||||
music-sync <options> <source> <destination>
|
||||
|
||||
Usage:
|
||||
music-sync <options> -s|--source <source> -d|--dest <destination>
|
||||
music-sync <options> <source> <destination>
|
||||
Syncronises music from one folder to another.
|
||||
|
||||
Options:
|
||||
-s, --source <source> The source folder of the music
|
||||
-d, --dest <destination> The destination folder of the music
|
||||
-t, --temp <folder> The temporary cache for converted files (default: /tmp/converted)
|
||||
-c, --convert <bitrate> Convert files to a given bitrate in kbps before syncing (default: 192)
|
||||
-a, --resize-art <width> Resize album-art before syncing (default width: 200)
|
||||
-j, --jobs <nproc> Number of processes to use in multi-threading (default: nproc - 2)
|
||||
-v, --verbose <0-6> Set log level (default: 2)
|
||||
-h, --help Display this help text
|
||||
Options:
|
||||
-s, --source <source> The source folder of the music
|
||||
-d, --dest <destination> The destination folder of the music
|
||||
-t, --temp <folder> The temporary cache for converted files (default: /tmp/converted)
|
||||
-c, --convert <bitrate> Convert files to a given bitrate in kbps before syncing (default: 192)
|
||||
-a, --resize-art <width> Resize album-art before syncing (default width: 200)
|
||||
-v, --verbose <0-6> Set log level (default: 2)
|
||||
-h, --help Display this help text
|
||||
|
||||
Log levels:
|
||||
0 | Verbose
|
||||
1 | Debug
|
||||
2 | Info
|
||||
3 | Warning
|
||||
4 | Error
|
||||
5 | Fatal
|
||||
6 | Silence
|
||||
Log levels:
|
||||
0 | Verbose
|
||||
1 | Debug
|
||||
2 | Info
|
||||
3 | Warning
|
||||
4 | Error
|
||||
5 | Fatal
|
||||
6 | Silence
|
||||
|
||||
Exit Codes:
|
||||
1 Dependencies not met
|
||||
2 Invalid Argument
|
||||
3 Source Unreachable
|
||||
4 Destination Unreachable
|
||||
5 Command failed
|
||||
Exit Codes:
|
||||
1 Dependencies not met
|
||||
2 Invalid Argument
|
||||
3 Source Unreachable
|
||||
4 Destination Unreachable
|
||||
5 Command failed
|
||||
|
||||
```
|
||||
|
||||
## Licence
|
||||
Copyright 2018-2020 Jeroen De Meerleer <me@jeroened.be>
|
||||
Copyright 2018-2019 Jeroen De Meerleer <me@jeroened.be>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
|
|
110
music-sync.sh
110
music-sync.sh
|
@ -13,7 +13,7 @@
|
|||
#/ -t, --temp <folder> The temporary cache for converted files (default: /tmp/converted)
|
||||
#/ -c, --convert <bitrate> Convert files to a given bitrate in kbps before syncing (default: 192)
|
||||
#/ -a, --resize-art <width> Resize album-art before syncing (default width: 200)
|
||||
#/ -j, --jobs <nproc> Number of processes to use in multi-threading (default: nproc - 2)
|
||||
#/ -j, --jobs <nproc> Number of processes to use in multi-threading (default: CPU_CORES - 2)
|
||||
#/ -v, --verbose <0-6> Set log level (default: 2)
|
||||
#/ -h, --help Display this help text
|
||||
#/
|
||||
|
@ -46,13 +46,13 @@ help=false
|
|||
temp="/tmp/converted"
|
||||
convertart=false
|
||||
coverartsize=200
|
||||
jobcount=$(expr $(nproc) - 2)
|
||||
jobcount="-2"
|
||||
multithread=false
|
||||
script_name=$(basename "${0}")
|
||||
script_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
|
||||
CheckDeps() {
|
||||
if [[ $1 == 2 ]]; then
|
||||
if [[ $1 == 0 ]]; then
|
||||
# Check getopt
|
||||
! getopt --test > /dev/null
|
||||
if [[ ${PIPESTATUS[0]} -ne 4 ]]; then
|
||||
|
@ -67,56 +67,48 @@ CheckDeps() {
|
|||
|
||||
if [[ $1 == 1 ]]; then
|
||||
# Check ffmpeg
|
||||
if [[ $convert == true ]]; then
|
||||
if [[ ! $(ffmpeg -h 2>/dev/null) ]]; then
|
||||
VerboseOutput 5 "\`ffmpeg -h\` failed"
|
||||
VerboseOutput 5 "Sorry, It seems that ffmpeg is not installed on your system"
|
||||
VerboseOutput 5 "Please install ffmpeg from your repositories and make sure it is available in your \$PATH"
|
||||
VerboseOutput 5 "Otherwise disable conversion"
|
||||
ExecTime
|
||||
exit 1
|
||||
fi
|
||||
VerboseOutput 0 "\`ffmpeg -h\` succeeded"
|
||||
if [[ $convert == true && ! $(ffmpeg -h 2>/dev/null) ]]; then
|
||||
VerboseOutput 5 "\`ffmpeg -h\` failed"
|
||||
VerboseOutput 5 "Sorry, It seems that ffmpeg is not installed on your system"
|
||||
VerboseOutput 5 "Please install ffmpeg from your repositories and make sure it is available in your \$PATH"
|
||||
VerboseOutput 5 "Otherwise disable conversion"
|
||||
ExecTime
|
||||
exit 1
|
||||
fi
|
||||
VerboseOutput 0 "\`ffmpeg -h\` succeeded"
|
||||
|
||||
# Check EyeD3
|
||||
if [[ $convertart == true ]]; then
|
||||
if [[ ! $(eyeD3 --version 2>/dev/null) ]]; then
|
||||
VerboseOutput 5 "\`eyeD3 --version\` failed"
|
||||
VerboseOutput 5 "Sorry, It seems that eyeD3 is not installed on your system"
|
||||
VerboseOutput 5 "Please install eyeD3 from your repositories and make sure it is available in your \$PATH"
|
||||
VerboseOutput 5 "Otherwise disable albumart conversion"
|
||||
ExecTime
|
||||
exit 1
|
||||
fi
|
||||
VerboseOutput 0 "\`eyeD3 --version\` succeeded"
|
||||
if [[ $convertart == true && ! $(eyeD3 --version 2>/dev/null) ]]; then
|
||||
VerboseOutput 5 "\`eyeD3 --version\` failed"
|
||||
VerboseOutput 5 "Sorry, It seems that eyeD3 is not installed on your system"
|
||||
VerboseOutput 5 "Please install eyeD3 from your repositories and make sure it is available in your \$PATH"
|
||||
VerboseOutput 5 "Otherwise disable albumart conversion"
|
||||
ExecTime
|
||||
exit 1
|
||||
fi
|
||||
VerboseOutput 0 "\`eyeD3 --version\` succeeded"
|
||||
|
||||
# Check ImageMagick
|
||||
if [[ $convertart == true ]]; then
|
||||
if [[ ! $(convert --version 2>/dev/null) ]]; then
|
||||
VerboseOutput 5 "\`convert --version\` failed"
|
||||
VerboseOutput 5 "Sorry, It seems that ImageMagick is not installed on your system"
|
||||
VerboseOutput 5 "Please install ImageMagick from your repositories and make sure it is available in your \$PATH"
|
||||
VerboseOutput 5 "Otherwise disable albumart conversion"
|
||||
ExecTime
|
||||
exit 1
|
||||
fi
|
||||
VerboseOutput 0 "\`convert --version\` succeeded"
|
||||
if [[ $convertart == true && ! $(convert --version 2>/dev/null) ]]; then
|
||||
VerboseOutput 5 "\`convert --version\` failed"
|
||||
VerboseOutput 5 "Sorry, It seems that ImageMagick is not installed on your system"
|
||||
VerboseOutput 5 "Please install ImageMagick from your repositories and make sure it is available in your \$PATH"
|
||||
VerboseOutput 5 "Otherwise disable albumart conversion"
|
||||
ExecTime
|
||||
exit 1
|
||||
fi
|
||||
VerboseOutput 0 "\`convert --version\` succeeded"
|
||||
|
||||
# Check Gnu parallel
|
||||
if [[ $multithread == true ]]; then
|
||||
if [[ ! $(parallel -h 2>/dev/null) ]]; then
|
||||
VerboseOutput 5 "\`parallel -h\` failed"
|
||||
VerboseOutput 5 "Sorry, It seems that parallel is not installed on your system"
|
||||
VerboseOutput 5 "Please install gnu-parallel and env_parallel from your repositories and make sure it is available in your \$PATH"
|
||||
VerboseOutput 5 "Otherwise disable multithreading"
|
||||
ExecTime
|
||||
exit 1
|
||||
fi
|
||||
VerboseOutput 0 "\`parallel -h \` succeeded"
|
||||
if [[ $multithread == true && ! $(parallel -h 2>/dev/null) ]]; then
|
||||
VerboseOutput 5 "\`parallel -h\` failed"
|
||||
VerboseOutput 5 "Sorry, It seems that parallel is not installed on your system"
|
||||
VerboseOutput 5 "Please install gnu-parallel and env_parallel from your repositories and make sure it is available in your \$PATH"
|
||||
VerboseOutput 5 "Otherwise disable multithreading"
|
||||
ExecTime
|
||||
exit 1
|
||||
fi
|
||||
VerboseOutput 0 "\`parallel -h \` succeeded"
|
||||
fi
|
||||
VerboseOutput 1 "Dependency test OK"
|
||||
}
|
||||
|
@ -149,8 +141,9 @@ GetOptions() {
|
|||
verbose=2
|
||||
if [[ $2 != "" ]]; then
|
||||
verbose=${2}
|
||||
shift
|
||||
fi
|
||||
shift 2
|
||||
shift
|
||||
;;
|
||||
-h|--help)
|
||||
help=true
|
||||
|
@ -180,9 +173,10 @@ GetOptions() {
|
|||
bitrate=192
|
||||
if [[ $2 != "" ]]; then
|
||||
bitrate=${2}
|
||||
shift
|
||||
fi
|
||||
VerboseOutput 1 "Converted bitrate is ${bitrate}"
|
||||
shift 2
|
||||
shift
|
||||
;;
|
||||
-a|--resize-art)
|
||||
VerboseOutput 0 "--resize-art given"
|
||||
|
@ -190,19 +184,21 @@ GetOptions() {
|
|||
coverartsize=200
|
||||
if [[ $2 != "" ]]; then
|
||||
coverartsize=${2}
|
||||
shift
|
||||
fi
|
||||
shift 2
|
||||
shift
|
||||
VerboseOutput 1 "Album art will ${coverartsize}px wide"
|
||||
;;
|
||||
-j|--jobs)
|
||||
VerboseOutput 0 "--jobs given"
|
||||
multithread=true
|
||||
jobcount=$(expr $(nproc) - 2)
|
||||
jobcount="-2"
|
||||
if [[ $2 != "" ]]; then
|
||||
jobcount=${2}
|
||||
shift
|
||||
fi
|
||||
shift 2
|
||||
VerboseOutput 1 "Multithreading will use ${jobcount} threads"
|
||||
shift
|
||||
VerboseOutput 1 "multithreading will use ${jobcount} threads"
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
|
@ -278,7 +274,7 @@ CreateFileList() {
|
|||
sourcepath="${sourcepath/\]/\\\]}"
|
||||
for file in $sourcepath; do
|
||||
origfile="${file#"$1/"}"
|
||||
relfile=$(echo ${origfile} | sed -e 's/\(\.\)*$//g' | tr -s ' ')
|
||||
relfile=$(echo ${origfile} | sed -e 's/\(\.\)*$//g')
|
||||
mp3file=$(echo "${relfile}" | sed -e 's/.flac/.mp3/')
|
||||
VerboseOutput 0 "Checking ${origfile}"
|
||||
if [[ -d "${1}/$origfile" ]]; then
|
||||
|
@ -319,10 +315,11 @@ Execute() {
|
|||
export verbose
|
||||
export coverartsize
|
||||
export begin
|
||||
parallel --jobs ${jobcount} --will-cite --line-buffer --arg-file "/tmp/music-sync-filelist" ProcessFile
|
||||
parallel --jobs ${jobcount} --line-buffer --arg-file "/tmp/music-sync-filelist" ProcessFile
|
||||
else
|
||||
for line in $(cat "/tmp/music-sync-filelist")
|
||||
do
|
||||
|
||||
curline=$(expr ${curline} + 1)
|
||||
total=$(cat /tmp/music-sync-filelist | wc -l)
|
||||
percentage=$(echo "scale=4;${curline}/${total}" | bc)
|
||||
|
@ -336,12 +333,7 @@ Execute() {
|
|||
}
|
||||
ProcessFile() {
|
||||
line=${1}
|
||||
curline="$(grep -n "$line" /tmp/music-sync-filelist | head -n 1 | cut -d: -f1)"
|
||||
total=$(cat /tmp/music-sync-filelist | wc -l)
|
||||
percentage=$(echo "scale=4;${curline}/${total}" | bc)
|
||||
percentage=$(echo "scale=2;${percentage}*100" | bc)
|
||||
VerboseOutput 2 "Current File: $line"
|
||||
VerboseOutput 2 "Progress: $curline / $total (${percentage%00}%)"
|
||||
if [[ $convert == true ]]; then
|
||||
ConvertFile "$line"
|
||||
fi
|
||||
|
@ -410,7 +402,7 @@ CopyFile() {
|
|||
exit 3
|
||||
fi
|
||||
|
||||
destline=$(echo $mp3line | sed -e 's/\.*\//\//g'| tr -s ' ')
|
||||
destline=$(echo $mp3line | sed -e 's/\.*\//\//g')
|
||||
VerboseOutput 1 "Copying: $line"
|
||||
|
||||
if [[ "$dest/$line" = */* ]]; then
|
||||
|
@ -418,7 +410,7 @@ CopyFile() {
|
|||
mkdir -p "$dest/${destline%/*}";
|
||||
fi;
|
||||
|
||||
cp -fv "$temp/$mp3line" "$dest/${destline}" 1>/dev/null 2>/dev/null
|
||||
cp -f "$temp/$mp3line" "$dest/${destline}" 1>/dev/null 2>/dev/null
|
||||
|
||||
VerboseOutput 1 "Copied: $line"
|
||||
}
|
||||
|
@ -454,7 +446,7 @@ ExitHandler() {
|
|||
trap 'ExitHandler' SIGINT
|
||||
trap 'ErrorHandler $BASH_COMMAND' ERR
|
||||
|
||||
CheckDeps 2
|
||||
CheckDeps 0
|
||||
GetOptions $@
|
||||
CheckDeps 1
|
||||
if [[ $help == true ]]; then
|
||||
|
|
Loading…
Reference in New Issue