scripts

Scripts
git clone git://git.wimdupont.com/scripts.git
Log | Files | Refs | LICENSE

ytd-album (1855B)


      1 #!/bin/bash
      2 
      3 #requires yt-dlp ffmpeg id3
      4 
      5 URL=$1
      6 
      7 #=== DOWNLOADING
      8 
      9 if [ -z ${URL} ]; then
     10 	echo "Paste Youtube URL"
     11 	read URL
     12 fi
     13 
     14 readonly URL
     15 
     16 mkdir -pv ~/tmp
     17 mkdir -pv ~/Downloads/tmp
     18 
     19 echo "Downloading $URL in ~/tmp"
     20 
     21 cd ~/Downloads/tmp && yt-dlp -x -f bestaudio -i -o "%(playlist_index)s - %(title)s.%(ext)s" "$URL"
     22 
     23 #cd ~/Downloads/tmp && youtube-dl -f bestaudio -i -o "%(playlist_index)s - %(title)s.%(ext)s" "$URL"
     24  
     25 #=== DIR SETUP
     26 
     27 echo "What's the band name?"
     28 
     29 read BAND
     30 readonly BAND
     31 
     32 echo "What's the album name?"
     33 
     34 read ALBUM
     35 readonly ALBUM
     36 
     37 echo "What's the year of release?"
     38 
     39 read YEAR
     40 readonly YEAR
     41 
     42 echo "What's the genre?"
     43 
     44 read GENRE
     45 readonly GENRE
     46 
     47 if [ -d "$HOME/tmp/$BAND/$ALBUM" ]; then
     48 	echo "Album directory already exists - (y) or (yes) to continue."
     49 	read answer
     50 	if [[ ! $answer =~ ^(y|yes)$ ]]; then
     51 		echo "Exiting."
     52 		exit 0;
     53 	fi
     54 fi
     55 
     56 mkdir -pv "$HOME/tmp/$BAND/$ALBUM"
     57 
     58 readonly DIR=$HOME/tmp/$BAND/$ALBUM
     59 
     60 mv $HOME/Downloads/tmp/* "$DIR"
     61 
     62 rm -rfv $HOME/Downloads/tmp
     63 
     64 echo Converting files to mp3
     65 
     66 for f in "$DIR"/*; do
     67 	if [[ ! $f =~ (.mp3)$ ]]; then
     68 		echo "Converting $f"
     69 		ffmpeg -loglevel error -i "$f" "${f%.*}.mp3";
     70 		rm "$f"
     71 	fi
     72 done
     73 
     74 for f in "$DIR"/*; do
     75 
     76 	#remove path to get songname
     77 	songname=$(echo "$f" | sed 's/.*\///g' | sed 's/.mp3//g')
     78 
     79 
     80 	track=$(echo $songname | cut -d ' ' -f 1)
     81 	title=$(echo $songname | sed "s/$track - //g")
     82 
     83 	oldname=$songname
     84 
     85 	echo "Type song name for : ${title}"
     86        	echo "Enter/Return to keep as is."
     87 	
     88 	read newname
     89 
     90 	if [[ ! -z $newname ]]; then
     91 		songname=$newname;
     92 
     93 		echo $oldname to $songname
     94 
     95 		mv "$DIR/$oldname.mp3" "$DIR/$track - $songname.mp3"
     96 
     97 		id3 -t "$songname" -a "$BAND" -l "$ALBUM" -y "$YEAR" -n $track -g "$GENRE" "$DIR/$track - $songname.mp3"
     98 	else
     99 		id3 -t "$title" -a "$BAND" -l "$ALBUM" -y "$YEAR" -n "$track" -g "$GENRE" "$DIR/$songname.mp3"
    100 	fi
    101 done