diff options
-rw-r--r-- | module/plugins/crypter/YoutubeBatch.py | 109 | ||||
-rw-r--r-- | module/plugins/hoster/BayfilesCom.py | 18 |
2 files changed, 99 insertions, 28 deletions
diff --git a/module/plugins/crypter/YoutubeBatch.py b/module/plugins/crypter/YoutubeBatch.py index b6178448d..ee84f0528 100644 --- a/module/plugins/crypter/YoutubeBatch.py +++ b/module/plugins/crypter/YoutubeBatch.py @@ -1,10 +1,28 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +""" + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, + or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see <http://www.gnu.org/licenses/>. + + @author: Walter Purcaro +""" + import re import json from module.plugins.Crypter import Crypter +from os.path import join API_KEY = "AIzaSyCKnWLNlkX-L4oD1aEzqqhRw1zczeD6_k0" @@ -12,33 +30,86 @@ API_KEY = "AIzaSyCKnWLNlkX-L4oD1aEzqqhRw1zczeD6_k0" class YoutubeBatch(Crypter): __name__ = "YoutubeBatch" __type__ = "container" - __pattern__ = r"https?://(?:[^/]*?)youtube\.com/(?:(?:view_play_list|playlist|.*?feature=PlayList).*?[?&](?:list|p)=)([a-zA-Z0-9-_]+)" - __version__ = "0.93" + __pattern__ = r"https?://(?:[^/]*?)youtube\.com/(?:(view_play_list|playlist|.*?feature=PlayList|user)(?:.*?[?&](?:list|p)=|/))([a-zA-Z0-9-_]+)" + __version__ = "0.94" __description__ = """Youtube.com Channel Download Plugin""" - __author_name__ = ("RaNaN", "Spoob", "zoidberg", "roland") - __author_mail__ = ("RaNaN@pyload.org", "spoob@pyload.org", "zoidberg@mujmail.cz", "roland@enkore.de") + __author_name__ = ("RaNaN", "Spoob", "zoidberg", "roland", "Walter Purcaro") + __author_mail__ = ("RaNaN@pyload.org", "spoob@pyload.org", "zoidberg@mujmail.cz", "roland@enkore.de", "vuolter@gmail.com") - 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) + def json_response(self, api, req): + req.update({"key": API_KEY}) + url = "https://www.googleapis.com/youtube/v3/" + api + page = self.load(url, get=req) + return json.loads(page) + + def get_playlist_baseinfos(self, playlist_id): + res = self.json_response("playlists", {"part": "snippet", "id": playlist_id}) + + snippet = res["items"][0]["snippet"] + playlist_name = snippet["title"] + channel_title = snippet["channelTitle"] + return playlist_name, channel_title + + def get_channel_id(self, user_name): + res = self.json_response("channels", {"part": "id", "forUsername": user_name}) + return res["items"][0]["id"] + + def get_playlists(self, user_name, token=None): + channel_id = self.get_channel_id(user_name) + req = {"part": "id", "maxResults": "50", "channelId": channel_id} if token: - url += "&pageToken=" + token + req.update({"pageToken": token}) + res = self.json_response("playlists", req) - response = json.loads(self.load(url)) + for item in res["items"]: + yield item["id"] - 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 res: + for item in self.get_playlists(user_name, res["nextPageToken"]): + yield item - if "nextPageToken" in response: - for item in self.get_videos(playlist_id, response["nextPageToken"]): + def get_videos(self, playlist_id, token=None): + req = {"part": "snippet", "maxResults": "50", "playlistId": playlist_id} + if token: + req.update({"pageToken": token}) + res = self.json_response("playlistItems", req) + + for item in res["items"]: + yield "http://youtube.com/watch?v=" + item["snippet"]["resourceId"]["videoId"] + + if "nextPageToken" in res: + for item in self.get_videos(playlist_id, res["nextPageToken"]): yield item def decrypt(self, pyfile): - match_id = re.match(self.__pattern__, self.pyfile.url) - new_links = [] - playlist_id = match_id.group(1) + match_obj = re.match(self.__pattern__, pyfile.url) + match_type, match_result = match_obj.group(1), match_obj.group(2) + playlist_ids = [] + + #: is a channel username or just a playlist id? + if match_type == "user": + ids = self.get_playlists(match_result) + playlist_ids.extend(ids) + else: + playlist_ids.append(match_result) + + self.logDebug("Playlist IDs = %s" % playlist_ids) + + if not playlist_ids: + self.fail("Wrong url") + + for id in playlist_ids: + self.logDebug("Processing playlist id: %s" % id) + + playlist_name, channel_title = self.get_playlist_baseinfos(id) + video_links = [x for x in self.get_videos(id)] + + self.logInfo("%s videos found on playlist \"%s\" (channel \"%s\")" % (len(video_links), playlist_name, channel_title)) + + if not video_links: + continue - new_links.extend(self.get_videos(playlist_id)) + self.logDebug("Video links = %s" % video_links) - self.packages.append((self.pyfile.package().name, new_links, self.pyfile.package().name)) + folder = join(self.config['general']['download_folder'], channel_title, playlist_name) + self.packages.append((playlist_name, video_links, folder)) #Note: folder is NOT used actually! diff --git a/module/plugins/hoster/BayfilesCom.py b/module/plugins/hoster/BayfilesCom.py index a696bac26..a7a2c75d4 100644 --- a/module/plugins/hoster/BayfilesCom.py +++ b/module/plugins/hoster/BayfilesCom.py @@ -26,11 +26,11 @@ from module.common.json_layer import json_loads class BayfilesCom(SimpleHoster): __name__ = "BayfilesCom" __type__ = "hoster" - __pattern__ = r"http://(?:www\.)?bayfiles\.(?:com|net)/file/\w+/\w+/.*" - __version__ = "0.05" + __pattern__ = r"https?://(?:www\.)?bayfiles\.(com|net)/file/(?P<ID>[a-zA-Z0-9]+/[a-zA-Z0-9]+/[^/]+)" + __version__ = "0.06" __description__ = """Bayfiles.com plugin - free only""" - __author_name__ = ("zoidberg") - __author_mail__ = ("zoidberg@mujmail.cz") + __author_name__ = ("zoidberg", "Walter Purcaro") + __author_mail__ = ("zoidberg@mujmail.cz", "vuolter@gmail.com") FILE_INFO_PATTERN = r'<p title="(?P<N>[^"]+)">[^<]*<strong>(?P<S>[0-9., ]+)(?P<U>[kKMG])i?B</strong></p>' FILE_OFFLINE_PATTERN = r'(<p>The requested file could not be found.</p>|<title>404 Not Found</title>)' @@ -53,7 +53,7 @@ class BayfilesCom(SimpleHoster): self.parseError('VARS') vfid, delay = found.groups() - response = json_loads(self.load('http://bayfiles.com/ajax_download', get={ + response = json_loads(self.load('https://bayfiles.com/ajax_download', get={ "_": time() * 1000, "action": "startTimer", "vfid": vfid}, decode=True)) @@ -64,12 +64,12 @@ class BayfilesCom(SimpleHoster): self.setWait(int(delay)) self.wait() - self.html = self.load('http://bayfiles.com/ajax_download', get={ + self.html = self.load('https://bayfiles.com/ajax_download', get={ "token": response['token'], "action": "getLink", "vfid": vfid}) - # Get final link and download + # Get final link and download found = re.search(self.LINK_PATTERN, self.html) if not found: self.parseError("Free link") @@ -90,9 +90,9 @@ class BayfilesCom(SimpleHoster): "notfound": re.compile(r"<title>404 Not Found</title>") }) if check == "waitforfreeslots": - self.retry(60, 300, "Wait for free slot") + self.retry(30, 60 * 5, "Wait for free slot") elif check == "notfound": - self.retry(60, 300, "404 Not found") + self.retry(30, 60 * 5, "404 Not found") getInfo = create_getInfo(BayfilesCom) |