ssr765_python

code

Oct 17th, 2023
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. import multiprocessing
  2.  
  3. from yt_dlp import YoutubeDL
  4.  
  5.  
  6. YDL_OPTS = {
  7.     'format': 'bestaudio/best',
  8.     'outtmpl': f'./dw2/[%(channel)s] %(title)s - %(id)s.%(ext)s',
  9.     'noplaylist': True,
  10.     'ignoreerrors': True,
  11.     # 'quiet': True,
  12.     'postprocessors': [{
  13.         'key': 'FFmpegExtractAudio',
  14.         'preferredcodec': 'mp3',
  15.         'preferredquality': '192',
  16.     }]
  17. }
  18.  
  19. class Cancion:
  20.     def __init__(self, info: dict) -> None:
  21.         self._info = info
  22.         self.titulo = info['title']
  23.         self.album = info['channel']
  24.         self.artista = ";".join(info['artist'].split(",")) if "artist" in info else info['channel']
  25.         self.url = info['webpage_url']
  26.  
  27.     def descargar(self) -> None:
  28.         ydl = YoutubeDL(YDL_OPTS)
  29.         ydl.download(self.url)
  30.  
  31. def descargar(cancion: Cancion):
  32.     cancion.descargar()
  33.  
  34. if __name__ == "__main__":
  35.     YDL = YoutubeDL(YDL_OPTS)
  36.     playlist_url = 'https://www.youtube.com/playlist?list=PLdr0SQOzbC6fFL3jH173V78WRnkYsTt7L'
  37.     info = YDL.extract_info(playlist_url, download=False)
  38.     canciones = [Cancion(info_cancion) for info_cancion in info['entries'] if info_cancion != None]
  39.    
  40.     pool = multiprocessing.Pool(10)
  41.     for cancion in canciones:
  42.         pool.apply_async(descargar, [cancion])
  43.  
  44.     pool.close()
  45.     pool.join()
Advertisement
Add Comment
Please, Sign In to add comment