def enqueue_audio_channel_uploads(self, arg): """Add all audio streams in a YouTube channel to the playback queue. :param arg: a YouTube channel url """ logging.info("arg : %s", arg) try: print_msg( "[YouTube] [Audio channel uploads] : '{0}'. ".format(arg)) count = len(self.queue) channel = pafy.get_channel(arg) if channel: for yt_video in channel.uploads: self._add_to_playback_queue( video=yt_video, info=VideoInfo(ytid=yt_video.videoid, title=yt_video.title), ) if count == len(self.queue): raise ValueError self._update_play_queue_order() except ValueError: raise ValueError(str("Channel not found : %s" % arg))
def monitor_youtube_channel(self): try: latest_video_url = pafy.get_channel( "RobertsSpaceInd").uploads[0].watchv_url if self.database_manager.rsi_video_is_new(latest_video_url): self.channel_main.send_message(latest_video_url) except HTTPException as you_tube_error: self.logger.warning( "Unsuccessful YouTube channel connection. '%s'", str(you_tube_error))
def vods_with_donations(self): date_format = '%Y-%m-%d %H:%M:%S' # Donations were enabled since Sep 30, 2015 # First stream is https://www.youtube.com/watch?v=snkEcLcIPew first_donation_date = dt.datetime.strptime('2015-09-30 00:00:00', date_format) channel = pafy.get_channel("https://www.youtube.com/user/SpitefulDick") uploads = list(filter(lambda vod: dt.datetime.strptime(vod.published, date_format) >= first_donation_date, channel.uploads)) return sorted(uploads, key=lambda vod: vod.published)
def enqueue_audio_channel_playlist(self, channel_name, playlist_name): """Search a playlist within a channel and if found, adds all the audio streams to the playback queue. :param arg: a YouTube playlist id """ logging.info("args : %s - %s", channel_name, playlist_name) try: print_msg( "[YouTube] [Audio channel playlist] : '{0} - {1}'. ".format( channel_name, playlist_name)) count = len(self.queue) channel = pafy.get_channel(channel_name) if channel: pl_dict = dict() pl_titles = list() pl_name = "" playlist = None for pl in channel.playlists: print_nfo("[YouTube] [Playlist] '{0}'.".format( to_ascii(pl.title))) if fuzz.partial_ratio(playlist_name, pl.title) > 50: pl_dict[pl.title] = pl pl_titles.append(pl.title) if len(pl_titles) > 1: pl_name = process.extractOne(playlist_name, pl_titles)[0] playlist = pl_dict[pl_name] elif len(pl_titles) == 1: pl_name = pl_titles[0] playlist = pl_dict[pl_name] if pl_name: if pl_name.lower() != playlist_name.lower(): print_adv("[YouTube] Playlist '{0}' not found. " "Playing '{1}' instead.".format( to_ascii(playlist_name), to_ascii(pl_name))) for yt_video in playlist: self._add_to_playback_queue( video=yt_video, info=VideoInfo(ytid=yt_video.videoid, title=yt_video.title), ) if count == len(self.queue): raise ValueError self._update_play_queue_order() except ValueError: raise ValueError(str("Channel not found : %s" % channel_name))
def enqueue_audio_channel_playlist(self, channel_name, playlist_name): """Search a playlist within a channel and if found, adds all the audio streams to the playback queue. :param arg: a YouTube playlist id """ logging.info('args : %s - %s', channel_name, playlist_name) try: count = len(self.queue) channel = pafy.get_channel(channel_name) if channel: pl_dict = dict() pl_titles = list() pl_name = '' playlist = None for pl in channel.playlists: print_nfo("[YouTube] [Playlist] '{0}'." \ .format(to_ascii(pl.title))) if fuzz.partial_ratio(playlist_name, pl.title) > 50: pl_dict[pl.title] = pl pl_titles.append(pl.title) if len(pl_titles) > 1: pl_name = process.extractOne(playlist_name, pl_titles)[0] playlist = pl_dict[pl_name] elif len(pl_titles) == 1: pl_name = pl_titles[0] playlist = pl_dict[pl_name] if pl_name: if pl_name.lower() != playlist_name.lower(): print_wrn("[YouTube] Playlist '{0}' not found. " \ "Playing '{1}' instead." \ .format(to_ascii(playlist_name), \ to_ascii(pl_name))) for yt_video in playlist: self.add_to_playback_queue(video=yt_video, \ info=VideoInfo(ytid=yt_video.videoid, \ title=yt_video.title)) if count == len(self.queue): raise ValueError self.__update_play_queue_order() except ValueError: raise ValueError(str("Channel not found : %s" % channel_name))
def parse_channel(channel_id): channel = Channel(channel_id) print('get channel {} ...'.format(channel_id)) resp = pafy.get_channel(channel_id) channel.fill(resp) print('get playlists ...') for x in resp.playlists: p = Playlist() p.fill(x) channel.add_playlist(p) print('get videos of playlist {}'.format(p.id)) for x2 in x: v = Video() v.fill(x2) p.add_video(v) print('OK!!!') return channel
def enqueue_audio_channel_uploads(self, arg): """Add all audio streams in a YouTube channel to the playback queue. :param arg: a YouTube channel url """ logging.info('arg : %s', arg) try: count = len(self.queue) channel = pafy.get_channel(arg) if channel: for yt_video in channel.uploads: self.add_to_playback_queue(video=yt_video, \ info=VideoInfo(ytid=yt_video.videoid, \ title=yt_video.title)) if count == len(self.queue): raise ValueError self.__update_play_queue_order() except ValueError: raise ValueError(str("Channel not found : %s" % arg))
def run_youtube_channel_search(arg): return pafy.get_channel(arg)