summaryrefslogtreecommitdiffstats
path: root/module
diff options
context:
space:
mode:
authorGravatar enkore <public@enkore.de> 2013-04-07 14:13:01 +0200
committerGravatar enkore <public@enkore.de> 2013-04-07 14:13:01 +0200
commit615e2d11ad54089caab4b61be1b1722b1131b2a5 (patch)
treeb3c924dc937a71526c4163dc68005848abf29709 /module
parentARD: Correct file extension (diff)
downloadpyload-615e2d11ad54089caab4b61be1b1722b1131b2a5.tar.xz
Ported YoutubeBatch to new google api
Now playlists with more than a dozen or so videos work TODO: Add support for downloading channels
Diffstat (limited to 'module')
-rw-r--r--module/plugins/crypter/YoutubeBatch.py35
1 files changed, 25 insertions, 10 deletions
diff --git a/module/plugins/crypter/YoutubeBatch.py b/module/plugins/crypter/YoutubeBatch.py
index 2e68dfe02..567191bb9 100644
--- a/module/plugins/crypter/YoutubeBatch.py
+++ b/module/plugins/crypter/YoutubeBatch.py
@@ -2,26 +2,41 @@
# -*- coding: utf-8 -*-
import re
+import json
from module.plugins.Crypter import Crypter
+API_KEY = "AIzaSyCKnWLNlkX-L4oD1aEzqqhRw1zczeD6_k0"
+
class YoutubeBatch(Crypter):
__name__ = "YoutubeBatch"
__type__ = "container"
- __pattern__ = r"http://(?:[^/]*?)youtube\.com/((?:view_play_list|playlist|.*?feature=PlayList).*?[\?&](?:list|p)=|user/)(\w+)"
+ __pattern__ = r"http://(?:[^/]*?)youtube\.com/((?:view_play_list|playlist|.*?feature=PlayList).*?[\?&](?:list|p)=)([a-zA-Z0-9-_]+)"
__version__ = "0.92"
__description__ = """Youtube.com Channel Download Plugin"""
- __author_name__ = ("RaNaN", "Spoob", "zoidberg")
- __author_mail__ = ("RaNaN@pyload.org", "spoob@pyload.org", "zoidberg@mujmail.cz")
+ __author_name__ = ("RaNaN", "Spoob", "zoidberg", "roland")
+ __author_mail__ = ("RaNaN@pyload.org", "spoob@pyload.org", "zoidberg@mujmail.cz", "roland@enkore.de")
+
+ def get_videos(self, playlist_id, token=None):
+ url = "https://www.googleapis.com/youtube/v3/playlistItems?playlistId=%s&part=snippet&key=%s&maxResults=50" % (playlist_id, API_KEY)
+ if token:
+ url += "&pageToken=" + token
+
+ response = json.loads(self.load(url))
+
+ for item in response["items"]:
+ if item["kind"] == "youtube#playlistItem" and item["snippet"]["resourceId"]["kind"] == "youtube#video":
+ yield "http://youtube.com/watch?v=" + item["snippet"]["resourceId"]["videoId"]
+
+ if "nextPageToken" in response:
+ for item in self.get_videos(playlist_id, response["nextPageToken"]):
+ yield item
def decrypt(self, pyfile):
match_id = re.match(self.__pattern__, self.pyfile.url)
- if match_id.group(1) == "user/":
- url = "http://gdata.youtube.com/feeds/api/users/%s/uploads?v=2" % match_id.group(2)
- else:
- url = "http://gdata.youtube.com/feeds/api/playlists/%s?v=2" % match_id.group(2)
-
- rep = self.load(url)
new_links = []
- new_links.extend(re.findall(r"href\='(http:\/\/www.youtube.com\/watch\?v\=[^']+)&", rep))
+ playlist_id = match_id.group(2)
+
+ new_links.extend(self.get_videos(playlist_id))
+
self.packages.append((self.pyfile.package().name, new_links, self.pyfile.package().name))