You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
import os
from const import *
from . yt_dlp_logger import *
import wget
import yt_dlp
def download_process_list ( artist , processed_albums_data_list ) :
"""
Take a list of dictionaries that have the values needed to create a file-structure and save the downloaded files
:param artist:
:param processed_albums_data_list:
:return:
"""
artist_path = MEDIA_FOLDER + ' / %s ' % artist
if not os . path . exists ( artist_path ) :
os . mkdir ( artist_path )
for item in processed_albums_data_list :
print ( ' --- ' )
# Create album folder
album = item . get ( ' album ' )
album_path = artist_path + ' / %s ' % album
if not os . path . exists ( album_path ) :
os . mkdir ( album_path )
# Save album cover
if item . get ( ' cover ' ) :
try :
download_file ( item . get ( ' cover ' ) , album_path )
except Exception as e :
print ( " Warning: %s " % e )
# Download album
print ( item )
ydl_opts = {
' logger ' : YtDlpLogger ( ) ,
' progress_hooks ' : [ yt_dlp_log_hook ] ,
' format ' : ' mp3/bestaudio/best ' ,
' outtmpl ' : album_path + ' / %(title)s . %(ext)s ' ,
# ℹ ️ See help(yt_dlp.postprocessor) for a list of available Postprocessors and their arguments
' postprocessors ' : [ { # Extract audio using ffmpeg
' key ' : ' FFmpegExtractAudio ' ,
' preferredcodec ' : ' mp3 ' ,
} ]
}
with yt_dlp . YoutubeDL ( ydl_opts ) as ydl :
try :
error_code = ydl . download ( ' https://youtube.com ' + item . get ( ' link ' ) )
except Exception as e :
print ( ' !!!!!!!!! ' )
print ( e )
def download_file ( url , output ) :
filename = wget . download ( url , out = output )
os . rename ( filename , output + ' /album.jpg ' )
return filename