def test_channel_uri(request_get, channel_videos_html): request_get.return_value = channel_videos_html c = Channel('https://www.youtube.com/c/ProgrammingKnowledge/videos') assert c.channel_uri == '/c/ProgrammingKnowledge' c = Channel( 'https://www.youtube.com/channel/UCs6nmQViDpUw0nuIx9c_WvA/videos') assert c.channel_uri == '/channel/UCs6nmQViDpUw0nuIx9c_WvA'
def test_init_with_url(request_get, channel_videos_html): request_get.return_value = channel_videos_html c = Channel('https://www.youtube.com/c/ProgrammingKnowledge/videos') assert c.channel_url == 'https://www.youtube.com/c/ProgrammingKnowledge' assert c.videos_url == f'{c.channel_url}/videos' assert c.playlists_url == f'{c.channel_url}/playlists' assert c.community_url == f'{c.channel_url}/community' assert c.featured_channels_url == f'{c.channel_url}/channels' assert c.about_url == f'{c.channel_url}/about'
def run(args): """main function :param args: Command line parameters. """ channel = Channel(args.channel_url) delimiter = args.delimiter for v in paginate(channel, extract_videos): url = f"https://www.youtube.com/watch?v={v['videoId']}" title = v['title']['runs'][0]['text'] pubdate = v['publishedTimeText']['simpleText'] count = v['viewCountText']['simpleText'] print(delimiter.join((url, title, pubdate, count)))
def test_channel_video_list(request_get, channel_videos_html): request_get.return_value = channel_videos_html c = Channel('https://www.youtube.com/c/ProgrammingKnowledge/videos') first_ten = [ 'https://www.youtube.com/watch?v=t_xLpJo_35k', 'https://www.youtube.com/watch?v=ccbh5YhxouQ', 'https://www.youtube.com/watch?v=wDnFjDjxW_0', 'https://www.youtube.com/watch?v=F3W_p_4XftA', 'https://www.youtube.com/watch?v=_fxm0xGGEi4', 'https://www.youtube.com/watch?v=cRbKZzcuIsg', 'https://www.youtube.com/watch?v=sdDu3dfIuow', 'https://www.youtube.com/watch?v=10KIbp-gJCE', 'https://www.youtube.com/watch?v=wZIT-cRtd6s', 'https://www.youtube.com/watch?v=KucCvEbTj0w', ] assert c.video_urls[:10] == first_ten
def fetch_latest_youtube_vid(): channel = Channel( 'https://www.youtube.com/channel/UCblA_CnykG2Dw_6IMwZ9z9A/videos') link = channel.video_urls[0] title = YouTube(link).title read_checker = open('src/latest_youtube_vid/checker.txt', 'r') latest_title = read_checker.readline() if latest_title == title: title = link = None else: update_checker = open('src/latest_youtube_vid/checker.txt', 'w') update_checker.write(title) return title, link
def test_videos_html(request_get, channel_videos_html): request_get.return_value = channel_videos_html c = Channel('https://www.youtube.com/c/ProgrammingKnowledge') assert c.html == channel_videos_html
def test_channel_vanity_url(request_get, channel_videos_html): request_get.return_value = channel_videos_html c = Channel('https://www.youtube.com/c/ProgrammingKnowledge/videos') assert c.vanity_url == 'http://www.youtube.com/c/ProgrammingKnowledge'