Created
September 23, 2012 22:59
-
-
Save samatjain/3773355 to your computer and use it in GitHub Desktop.
Print the YouTube URLs for a Ubicast.tv videos RSS feed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Take a Ubicast.tv RSS feed (usually found on channel pages) and print all the YouTube links available for the video. Said list can be fed into youtube-dl so videos can be watched offline | |
# Author: Samat Jain <[email protected]> | |
# License: GPLv3 | |
import re | |
import sys | |
import feedparser | |
import requests | |
rs = requests.session() | |
def determine_ubicast_domain(url): | |
'''Determine the Ubicast subdomain we are using, and return it''' | |
r = re.compile('//((.*)\.ubicast.tv)') | |
domain = r.search(url).groups()[0] | |
return domain | |
def go(feed_url): | |
fpo = feedparser.parse(requests.get(feed_url).text) | |
videos_list = [] | |
for item in fpo.entries: | |
videos_list.append(item.link) | |
r = re.compile('modes_url = "(.*?)";') | |
modes_urls = [] | |
for video in videos_list: | |
page_html = rs.get(video).text | |
modes_url = r.search(page_html).groups()[0] | |
modes_urls.append(modes_url) | |
base_domain = determine_ubicast_domain(feed_url) | |
youtube_urls = [] | |
for modes_url in modes_urls: | |
modes_url_qualified = 'http://%s%s' % (base_domain, modes_url) | |
modes_url_doc = rs.get(modes_url_qualified) | |
youtube_urls.append(modes_url_doc.json['modes']['youtubehd']['flash']['yturl']) | |
return youtube_urls | |
if __name__ == '__main__': | |
feed_url = sys.argv[1] | |
youtube_urls = go(feed_url) | |
for url in youtube_urls: | |
print(url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment