diff options
| author | 2013-04-07 15:37:36 +0200 | |
|---|---|---|
| committer | 2013-04-07 15:37:36 +0200 | |
| commit | 5797b0946f8d080d5b6ec30bd86395320e25e71a (patch) | |
| tree | 74b9fe077fd570e7879f6b60f00042ed80457274 /module/plugins/crypter | |
| parent | UploadedTo: fixed #68 (diff) | |
| parent | Ported YoutubeBatch to new google api (diff) | |
| download | pyload-5797b0946f8d080d5b6ec30bd86395320e25e71a.tar.xz | |
Merge pull request #69 from enkore/stable
Ported YoutubeBatch to new google api
Diffstat (limited to 'module/plugins/crypter')
| -rw-r--r-- | module/plugins/crypter/YoutubeBatch.py | 35 | 
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)) | 
