From 778000a1df24f907c58242300a5c4c7f4b6300ae Mon Sep 17 00:00:00 2001 From: Ni Ndogo Date: Tue, 30 Oct 2018 15:28:29 +0300 Subject: [PATCH] Clean ups as requested --- youtube_dl/extractor/porntrex.py | 56 ++++++++++---------------------- 1 file changed, 17 insertions(+), 39 deletions(-) diff --git a/youtube_dl/extractor/porntrex.py b/youtube_dl/extractor/porntrex.py index c30deb671..139e6acd6 100644 --- a/youtube_dl/extractor/porntrex.py +++ b/youtube_dl/extractor/porntrex.py @@ -11,43 +11,19 @@ from ..utils import ( class PornTrexIE(InfoExtractor): - '''Class for downloading Porntrex video.''' _NETRC_MACHINE = 'porntrex' - _VALID_URL = r'https?://(?:www\.)?porntrex\.com/video/(?P[0-9]+)/.*' + _VALID_URL = r'https?://(?:www\.)?porntrex\.com/video/(?P[0-9]+)/' _TEST = { - 'url': 'https://www.porntrex.com/video/519351/\ - be-ariyana-adin-breaking-and-entering-this-pussy', + 'url': 'https://www.porntrex.com/video/519351/be-ariyana-adin-breaking-and-entering-this-pussy', 'info_dict': { 'id': '519351', 'ext': 'mp4', 'title': 'BE - Ariyana Adin - Breaking And Entering This Pussy', 'uploader': 'brand95', - 'description': 'BE - Ariyana Adin - Breaking And Entering This \ -Pussy', + 'description': 'BE - Ariyana Adin - Breaking And Entering This Pussy', } } - def get_resolution(self, url): - '''Video resolution extraction from url''' - try: - resolution = ((url.split('.')[2])).split('_')[2] - except IndexError: - resolution = '480p' - return resolution - - def get_protocol(self, url): - '''Video protocol extraction from url''' - return url.split(':')[0] - - def get_thumbnails(self, html): - '''Each video has 10 thumbnails - extracted here.''' - thumbnails_regex = re.compile(r'href="(http.*?/screenshots/\d+.jpg/)"') - thumbnails_list = re.findall(thumbnails_regex, html) - thumbnails = [] - for thumbs in thumbnails_list: - thumbnails.append({'url': thumbs}) - return thumbnails - def _login(self): username, password = self._get_login_info() if username is None: @@ -82,7 +58,7 @@ Pussy', private_string = 'Only active members can watch private videos.' is_video_private_regex = re.compile(private_string) - if (re.findall(is_video_private_regex, webpage)): + if re.findall(is_video_private_regex, webpage): self.raise_login_required() title = self._html_search_regex( @@ -93,32 +69,34 @@ Pussy', r'(.+?)', re.DOTALL) uploader = re.findall(uploader_regex, webpage)[0].strip() + thumbnails_regex = re.compile(r'href="(http.*?/screenshots/\d+.jpg/)"') + thumbnails_list = re.findall(thumbnails_regex, webpage) + thumbnails = [] + for thumbs in thumbnails_list: + thumbnails.append({'url': thumbs}) formats = [] for x, _ in enumerate(url2): formats.append({'url': url2[x], 'ext': url2[x].split('.')[-1], - 'resolution': self.get_resolution(url2[x]), - 'protocol': self.get_protocol(url2[x]), + 'protocol': url2[x].split(':')[0], }) - # self.get_thumbnails(webpage) + self._sort_formats(formats) - print(formats) return { 'id': video_id, 'title': title, 'description': self._og_search_description(webpage), 'uploader': uploader, - 'thumbnails': self.get_thumbnails(webpage), + 'thumbnails': thumbnails, 'formats': formats, } class PornTrexPlayListIE(InfoExtractor): - '''Class for downloading Porntrex video playlists.''' _NETRC_MACHINE = 'porntrex' _VALID_URL = \ - r'https?://(?:www\.)?porntrex\.com/playlists/(?P[0-9]+)/.*' + r'https?://(?:www\.)?porntrex\.com/playlists/(?P[0-9]+)/' _TEST = { 'url': 'https://www.porntrex.com/playlists/60671/les45/', 'info_dict': { @@ -130,9 +108,6 @@ class PornTrexPlayListIE(InfoExtractor): } } - def playlist_title(self, html): - return self._html_search_regex(r'(.+?)', html, 'title',) - def _real_extract(self, url): playlist_id = self._match_id(url) webpage = self._download_webpage(url, playlist_id) @@ -150,6 +125,9 @@ class PornTrexPlayListIE(InfoExtractor): return { '_type': 'playlist', 'id': playlist_id, - 'title': self.playlist_title(webpage), + 'title': self._html_search_regex( + r'(.+?)', + webpage, + 'title',), 'entries': entries, }