#!/bin/bash ## Remote Server Backup Script ## Author: Ze'ev Schurmann ## Reddit: u/thisiszeev ## License: MIT ## Dependancies: ## ffprobe (ffmpeg), jq ## Please consider making me small donation. Even though my scripts are open source and free to use, I still need to eat. And the ## occasional bottle of wine also goes down well. ## $5 buys me a cup of coffee ## $10 buys me a nice burger ## $20 buys me a bottle of wine ## Anything above that will be awesome as well. ## You can send me a donation via Paypal https://www.paypal.com/paypalme/thisiszeev ## Drop me a message on Reddit if you do make a donation. ## Support is only offered freely to those who donate $20 or more. ## Your donation contributes to further development. ## If you need a custom script, contact me on Reddit for pricing. rm -f tmp.lst if [[ ! -f paths.lst ]]; then echo "Please create a text file called paths.lst and put /the/absolute/path to each library on a seperate line." exit 1 fi if [[ ! -f library.tsv ]]; then echo -e "title\tartist\talbum\tgenre\tdate\ttrack_number\ttrack_total\tbitrate\tduration\tfilename\tfilesize\tpath" >> library.tsv fi added=0 while read -r path; do find "$path" -type f -name "*.mp3" > tmp.lst while read -r mp3; do test=$(cat library.tsv | grep -F "$mp3") if [[ -z $test ]]; then ((added++)) echo "Found new MP3 at $mp3" json=$(ffprobe -print_format json -show_format "$mp3" 2> /dev/null | jq -c .) title="$(echo "$json" | jq -r .format.tags.title)" artist="$(echo "$json" | jq -r .format.tags.artist)" album="$(echo "$json" | jq -r .format.tags.album)" genre="$(echo "$json" | jq -r .format.tags.genre)" date="$(echo "$json" | jq -r .format.tags.date)" track_number="$(echo "$json" | jq -r .format.tags.track)" track_total="$(echo "$json" | jq -r .format.tags.TRACKTOTAL)" bitrate="$(($(echo "$json" | jq -r .format.bit_rate)/1000))" runtime="$(echo "$json" | jq -r .format.duration)" runtime="${runtime%%.*}" min=$((runtime/60)) sec=$(printf %02d $((runtime%60))) duration="$min:$sec" filename="${mp3##*/}" size="$(echo "$json" | jq -r .format.size)" mb=$((size/1048576)) kb=$((size%1048576)) filesize="$mb.${kb:0:1} MB" echo -e "$title\t$artist\t$album\t$genre\t$date\t$track_number\t$track_total\t$bitrate\t$duration\t$filename\t$filesize\t$mp3" >> library.tsv fi done < tmp.lst rm -f tmp.lst done < paths.lst if [[ $added == 0 ]]; then echo "Move along nothing to see here..." else echo "Added $added MP3s to library.tsv. Total of $(($(cat library.tsv | wc -l)-1)) MP3s in library.tsv." fi