From 6d0f924cbf7a9ce668eca000bd6d89207b073c4c Mon Sep 17 00:00:00 2001 From: nindogo Date: Sun, 21 Apr 2019 23:06:54 +0300 Subject: [PATCH] Set up Base class for shared methods. Reorganised the script adding a PornTrexBaseIE class that will be used for shared methods. Currently hosting only two methods: 1. _login 2. _real_initialize --- youtube_dl/extractor/porntrex.py | 60 +++++++++----------------------- 1 file changed, 17 insertions(+), 43 deletions(-) diff --git a/youtube_dl/extractor/porntrex.py b/youtube_dl/extractor/porntrex.py index e253510d9..085ded422 100644 --- a/youtube_dl/extractor/porntrex.py +++ b/youtube_dl/extractor/porntrex.py @@ -10,19 +10,7 @@ from ..utils import ( ) -class PornTrexIE(InfoExtractor): - _NETRC_MACHINE = 'porntrex' - _VALID_URL = r'https?://(?:www\.)?porntrex\.com/video/(?P[0-9]+)/' - _TEST = { - 'url': 'https://www.porntrex.com/video/350451/naomi-woods-the-list', - 'info_dict': { - 'id': '350451', - 'ext': 'mp4', - 'title': 'Naomi Woods - The List in 4k', - 'uploader': 'delman', - 'description': 'Naomi Woods The List', - } - } +class PornTrexBaseIE(InfoExtractor): def _login(self): username, password = self._get_login_info() @@ -53,6 +41,21 @@ class PornTrexIE(InfoExtractor): def _real_initialize(self): self._login() + +class PornTrexIE(PornTrexBaseIE): + _NETRC_MACHINE = 'porntrex' + _VALID_URL = r'https?://(?:www\.)?porntrex\.com/video/(?P[0-9]+)/' + _TEST = { + 'url': 'https://www.porntrex.com/video/350451/naomi-woods-the-list', + 'info_dict': { + 'id': '350451', + 'ext': 'mp4', + 'title': 'Naomi Woods - The List in 4k', + 'uploader': 'delman', + 'description': 'Naomi Woods The List', + } + } + def _real_extract(self, url): video_id = self._match_id(url) webpage = self._download_webpage(url, video_id) @@ -94,7 +97,7 @@ class PornTrexIE(InfoExtractor): } -class PornTrexPlayListIE(InfoExtractor): +class PornTrexPlayListIE(PornTrexBaseIE): _NETRC_MACHINE = 'porntrex' _VALID_URL = \ r'https?://(?:www\.)?porntrex\.com/playlists/(?P[0-9]+)/' @@ -111,35 +114,6 @@ class PornTrexPlayListIE(InfoExtractor): } } - def _login(self): - username, password = self._get_login_info() - if username is None: - return - - login_page = self._download_webpage( - 'https://www.porntrex.com/login/', None, 'Downloading login page') - - login_form = self._hidden_inputs(login_page) - - login_form.update({ - 'username': username.encode('utf-8'), - 'pass': password.encode('utf-8'), - 'remember_me': str(1).encode('utf-8'), - }) - - login_page = self._download_webpage( - 'https://www.porntrex.com/ajax-login/', None, - note='Logging in', - data=urlencode_postdata(login_form)) - - if re.search(r'generic-error hidden', login_page): - raise ExtractorError( - 'Unable to login, incorrect username and/or password', - expected=True) - - def _real_initialize(self): - self._login() - def _real_extract(self, url): playlist_id = self._match_id(url) webpage = self._download_webpage(url, playlist_id)