async def process_playlist(self, playlist_type, url): if playlist_type == linkutils.Playlist_Types.YouTube_Playlist: if ("playlist?list=" in url): listid = url.split('=')[1] else: video = url.split('&')[0] await self.process_song(video) return options = {'format': 'bestaudio/best', 'extract_flat': True} with youtube_dl.YoutubeDL(options) as ydl: r = ydl.extract_info(url, download=False) for entry in r['entries']: link = "https://www.youtube.com/watch?v={}".format( entry['id']) song = Song(linkutils.Origins.Playlist, linkutils.Sites.YouTube, "", "", "", "", link) self.playlist.add(song) if playlist_type == linkutils.Playlist_Types.Spotify_Playlist: links = linkutils.get_spotify_playlist(url) for link in links: song = Song(linkutils.Origins.Playlist, linkutils.Sites.Spotify, "", "", "", "", link) self.playlist.add(song)
async def process_song(self, track): """Adds the track to the playlist instance and plays it, if it is the first song""" host = linkutils.identify_url(track) is_playlist = linkutils.identify_playlist(track) if is_playlist != linkutils.Playlist_Types.Unknown: if len(self.playlist.playque) == 0: start = True else: start = False await self.process_playlist(is_playlist, track) if is_playlist == linkutils.Playlist_Types.Spotify_Playlist: song = Song(linkutils.Origins.Playlist, linkutils.Sites.Spotify, "", "", "", "", "") if is_playlist == linkutils.Playlist_Types.YouTube_Playlist: song = Song(linkutils.Origins.Playlist, linkutils.Sites.YouTube, "", "", "", "", "") if start == True: await self.play_song(self.playlist.playque[0]) print("Playing {}".format(track)) return song if host == linkutils.Sites.Unknown: if linkutils.get_url(track) is not None: return None track = await self.search_youtube(track) if host == linkutils.Sites.Spotify: title = linkutils.convert_spotify(track) track = await self.search_youtube(title) try: downloader = youtube_dl.YoutubeDL({ 'format': 'bestaudio', 'title': True }) r = downloader.extract_info(track, download=False) except: downloader = youtube_dl.YoutubeDL({'title': True}) r = downloader.extract_info(track, download=False) song = Song(linkutils.Origins.Default, host, r.get('url'), r.get('uploader'), r.get('title'), r.get('duration'), r.get('webpage_url')) self.playlist.add(song) if len(self.playlist.playque) == 1: print("Playing {}".format(track)) await self.play_song(song) return song
async def process_song(self, track): """Adds the track to the playlist instance and plays it, if it is the first song""" host = linkutils.identify_url(track) is_playlist = linkutils.identify_playlist(track) if is_playlist != linkutils.Playlist_Types.Unknown: await self.process_playlist(is_playlist, track) if self.current_song == None: await self.play_song(self.playlist.playque[0]) print("Playing {}".format(track)) song = Song(linkutils.Origins.Playlist, linkutils.Sites.Unknown) return song if host == linkutils.Sites.Unknown: if linkutils.get_url(track) is not None: return None track = self.search_youtube(track) if host == linkutils.Sites.Spotify: title = await linkutils.convert_spotify(track) track = self.search_youtube(title) if host == linkutils.Sites.YouTube: track = track.split("&list=")[0] try: downloader = youtube_dl.YoutubeDL( {'format': 'bestaudio', 'title': True, "cookiefile": config.COOKIE_PATH}) r = downloader.extract_info( track, download=False) except: downloader = youtube_dl.YoutubeDL( {'title': True, "cookiefile": config.COOKIE_PATH}) r = downloader.extract_info( track, download=False) if r.get('thumbnails') is not None: thumbnail = r.get('thumbnails')[len( r.get('thumbnails')) - 1]['url'] else: thumbnail = None song = Song(linkutils.Origins.Default, host, base_url=r.get('url'), uploader=r.get('uploader'), title=r.get( 'title'), duration=r.get('duration'), webpage_url=r.get('webpage_url'), thumbnail=thumbnail) self.playlist.add(song) if self.current_song == None: print("Playing {}".format(track)) await self.play_song(song) return song
async def process_playlist(self, playlist_type, url): if playlist_type == linkutils.Playlist_Types.YouTube_Playlist: if ("playlist?list=" in url): listid = url.split('=')[1] else: video = url.split('&')[0] await self.process_song(video) return options = { 'format': 'bestaudio/best', 'extract_flat': True, "cookiefile": config.COOKIE_PATH } with yt_dlp.YoutubeDL(options) as ydl: r = ydl.extract_info(url, download=False) for entry in r['entries']: link = "https://www.youtube.com/watch?v={}".format( entry['id']) song = Song(linkutils.Origins.Playlist, linkutils.Sites.YouTube, webpage_url=link) self.playlist.add(song) if playlist_type == linkutils.Playlist_Types.Spotify_Playlist: links = await linkutils.get_spotify_playlist(url) for link in links: song = Song(linkutils.Origins.Playlist, linkutils.Sites.Spotify, webpage_url=link) self.playlist.add(song) if playlist_type == linkutils.Playlist_Types.BandCamp_Playlist: options = {'format': 'bestaudio/best', 'extract_flat': True} with yt_dlp.YoutubeDL(options) as ydl: r = ydl.extract_info(url, download=False) for entry in r['entries']: link = entry.get('url') song = Song(linkutils.Origins.Playlist, linkutils.Sites.Bandcamp, webpage_url=link) self.playlist.add(song) for song in list(self.playlist.playque)[:config.MAX_SONG_PRELOAD]: asyncio.ensure_future(self.preload(song))