Implemented api-less youtube feeds

users, playlists and channels are supported
This commit is contained in:
Xincognito10 2018-04-08 16:08:05 -05:00
parent 15617c5b39
commit 14315c6c72
3 changed files with 48 additions and 6 deletions

View File

@ -291,7 +291,8 @@ class gPodderCli(object):
return None
# Check if it's a YouTube feed, and if we have an API key, auto-resolve the channel
url = youtube.resolve_v3_url(url, self._config.youtube.api_key_v3)
#url = youtube.resolve_v3_url(url, self._config.youtube.api_key_v3)
url = youtube.parse_youtube_url(url)
# Subscribe to new podcast
if create:

View File

@ -2306,7 +2306,8 @@ class gPodder(BuilderWidget, dbus.service.Object):
url = util.normalize_feed_url(input_url)
# Check if it's a YouTube feed, and if we have an API key, auto-resolve the channel
url = youtube.resolve_v3_url(url, self.config.youtube.api_key_v3)
# url = youtube.resolve_v3_url(url, self.config.youtube.api_key_v3)
url = youtube.parse_youtube_url(url)
if url is None:
# Fail this one because the URL is not valid

View File

@ -20,9 +20,7 @@
# Justin Forest <justin.forest@gmail.com> 2008-10-13
#
import gpodder
from gpodder import util
import os.path
@ -73,8 +71,8 @@ formats_dict = dict(formats)
V3_API_ENDPOINT = 'https://www.googleapis.com/youtube/v3'
CHANNEL_VIDEOS_XML = 'https://www.youtube.com/feeds/videos.xml'
class YouTubeError(Exception): pass
class YouTubeError(Exception):
pass
def get_fmt_ids(youtube_config):
@ -262,3 +260,45 @@ def resolve_v3_url(url, api_key_v3):
return new_urls[0]
return url
def parse_youtube_url(url):
"""
Youtube Channel Links are parsed into youtube feed links
>>> parse_youtube_url("https://www.youtube.com/channel/CHANNEL_ID")
'https://www.youtube.com/feeds/videos.xml?channel_id=CHANNEL_ID'
Youtube User Links are parsed into youtube feed links
>>> parse_youtube_url("https://www.youtube.com/user/USERNAME")
'https://www.youtube.com/feeds/videos.xml?user=USERNAME'
Youtube Playlist Links are parsed into youtube feed links
>>> parse_youtube_url("https://www.youtube.com/playlist?list=PLAYLIST_ID")
'https://www.youtube.com/feeds/videos.xml?playlist_id=PLAYLIST_ID'
@param url: the path to the channel, user or playlist
@return: the feed url if successful or the given url if not
"""
scheme, netloc, path, query, fragment = urllib.parse.urlsplit(url)
print(scheme, " ", netloc, " ", path, " ", query, " ", fragment)
if 'youtube.com' in netloc and ('/user/' in path or '/channel/' in path or 'list=' in query):
if path.startswith('/user/'):
user_id = path.split('/')[2]
query = 'user={user_id}'.format(user_id=user_id)
if path.startswith('/channel/'):
channel_id = path.split('/')[2]
query = 'channel_id={channel_id}'.format(channel_id=channel_id)
if 'list=' in query:
playlist_query = [query_value for query_value in query.split("&") if 'list=' in query_value][0]
playlist_id = playlist_query.strip("list=")
query = 'playlist_id={playlist_id}'.format(playlist_id=playlist_id)
path = '/feeds/videos.xml'
return urllib.parse.urlunsplit((scheme, netloc, path, query, fragment))
else:
return url