#!/usr/bin/env bash # author: Lilian BESSON # email: Lilian.BESSON[AT]ens-cachan[DOT]fr # date: 05-11-2015 # web: https://bitbucket.org/lbesson/bin/src/master/youtube-albums.sh # # A small script to download every album/playlist from a Youtube page, based on [youtube-dl](http://yt-dl.org/), # which is awesome, but fails to every music track from a Youtube page. # # My script asks confirmation before any action, so nothing is deleted or moved # without warning you before (can be disabled by passing the CLI '--batch' option). # # Example: # $ youtube-albums.sh https://www.youtube.com/channel/UCCR7DJUk70fWSs05WIujdiw/playlists?sort=dd&shelf_id=3579731707244514300&view=50 # --> will download every the first 50 Neil Diamond albums # $ youtube-albums.sh https://www.youtube.com/user/Xnihpsel/playlists # --> will download all the playlists from this artist # # Requires wget and [youtube-dl](http://yt-dl.org/), # and my [smoothnameone.sh](https://bitbucket.org/lbesson/bin/src/master/smoothnameone.sh) to slugify the folder names # Uses [Smooth_Name.sh](https://bitbucket.org/lbesson/bin/src/master/Smooth_Name.sh) # also if possible to slugify the names of the downloaded songs. # # This script uses youtube-playlist.sh to download every song from each playlist # from one band (cf. https://bitbucket.org/lbesson/bin/src/master/youtube-playlist.sh) # # Licence: GPL v3 # version='0.2' LANG='fr' clear # Destination of the HTML file out="/tmp/youtube-albums.tmp.html" if [ "${1}" = "--batch" ]; then READ="echo -e 'Nothing asked to the user : batch mode (option --batch).'" shift else READ="read" fi icon=$(ls -H /usr/share/icons/*/*/*/*music*svg 2>/dev/null|uniq|head -n1) dlalbums() { echo -e "${white}Trying to download the albums : '${blue}${1}${white}'..." # Try to download it according to the args passed to the script wget "${1}" -O "${out}" || wget "https://www.youtube.com/channel/${1}/playlists" -O "${out}" # Then parsing it and downloading every playlists number=$(for j in $(grep -o "playlist?list=[a-zA-Z0-9_-]*" "${out}" | sed s/'playlist?list='// | uniq); do echo "$j"; done | wc -l) echo -e "I found ${green}${number}${white} different playlists in this Youtube page, is it correct ?" echo -e "(${magenta}[Enter]${white} to continue, ${magenta}[Ctrl+C]${white} to cancel)." $READ || exit # Ask for confirmation echo -e "Just to be sure, I am showing you the downloading commands I will execute : (${magenta}[Enter]${white} to see)." $READ || exit for j in $(grep -o "playlist?list=[a-zA-Z0-9_-]*" "${out}" | sed s/'playlist?list='// | uniq); do echo -e youtube-playlist.sh --batch "$j" # echo -e youtube-dl -o "%(title)s.%(ext)s" --extract-audio --console-title --audio-format=mp3 -w -- "$j" done echo -e "Are you OK with these downloading commands (using ${u}youtube-playlist.sh${U}) ? (${magenta}[Enter]${white} if OK)." $READ || exit # Create the directory title=$(grep "