Improve yt-audio function
This commit is contained in:
		
							parent
							
								
									159c8cff90
								
							
						
					
					
						commit
						cefab517a5
					
				
							
								
								
									
										41
									
								
								.aliases
									
									
									
									
									
								
							
							
						
						
									
										41
									
								
								.aliases
									
									
									
									
									
								
							| 
						 | 
					@ -580,11 +580,45 @@ download_youtube_uploads_list() {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function download_youtube_audio() {
 | 
					function download_youtube_audio() {
 | 
				
			||||||
    if [[ $1 == "" ]]; then
 | 
					    local make_folder="$1"
 | 
				
			||||||
        error "Usage: <url>"
 | 
					    local url="$2"
 | 
				
			||||||
 | 
					    shift 2
 | 
				
			||||||
 | 
					    local opts="$@"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if [[ $url == "" ]]; then
 | 
				
			||||||
 | 
					        error "Usage: <make folder?> <url> <optional args>"
 | 
				
			||||||
        return
 | 
					        return
 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
    yt-dlp.exe -f "140" "$1"
 | 
					
 | 
				
			||||||
 | 
					    printf "${BOLD}Downloading Youtube audio\n\n${NORMAL}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if [[ $make_folder == "1" ]]; then
 | 
				
			||||||
 | 
					        make_vid_dir_and_cd_into $url ""
 | 
				
			||||||
 | 
					        if [[ $? -ne 0 ]]; then
 | 
				
			||||||
 | 
					            return
 | 
				
			||||||
 | 
					        fi
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    local format="140"
 | 
				
			||||||
 | 
					    local name_format="%(upload_date>%Y-%m-%d)s-%(title)s-yt-%(id)s"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # Get the audio filename.
 | 
				
			||||||
 | 
					    local filename=$(yt-dlp.exe --get-filename -f $format -o "$name_format.%(ext)s" $opts $url)
 | 
				
			||||||
 | 
					    printf "filename: $filename\n"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    local cmd="yt-dlp.exe -f $format -o \"$filename\" $opts $url"
 | 
				
			||||||
 | 
					    eval $cmd   # Need to eval in order to preserve the quotes wrapping the filename format string.
 | 
				
			||||||
 | 
					    error=$?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if [[ $error -ne 0 ]]; then
 | 
				
			||||||
 | 
					        error "Error: Failed to download '$url'"
 | 
				
			||||||
 | 
					        if [[ $make_folder == "1" ]]; then cd ..; fi
 | 
				
			||||||
 | 
					        return
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if [[ $make_folder == "1" ]]; then cd ..; fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    printf "${BOLD}Finished downloading ${YELLOW}$filename${NORMAL}\n"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Download Twitch chat transcript
 | 
					# Download Twitch chat transcript
 | 
				
			||||||
| 
						 | 
					@ -1030,6 +1064,7 @@ alias yt-playlist-1440='download_youtube_playlist "620+140"'
 | 
				
			||||||
alias yt-playlist-1080='download_youtube_playlist "137+140"'
 | 
					alias yt-playlist-1080='download_youtube_playlist "137+140"'
 | 
				
			||||||
alias yt-playlist-720='download_youtube_playlist  "136+140"'
 | 
					alias yt-playlist-720='download_youtube_playlist  "136+140"'
 | 
				
			||||||
alias yt-playlist-tiny='download_youtube_playlist "160+140"'
 | 
					alias yt-playlist-tiny='download_youtube_playlist "160+140"'
 | 
				
			||||||
 | 
					#---------------------------
 | 
				
			||||||
alias yt-audio='download_youtube_audio'
 | 
					alias yt-audio='download_youtube_audio'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#-------------------------------------------------
 | 
					#-------------------------------------------------
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user