scripts

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

ytd-album (1871B)


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