diff --git a/youtube_dl/extractor/nowvideo.py b/youtube_dl/extractor/nowvideo.py index 17baa9679..c3dbb48c1 100644 --- a/youtube_dl/extractor/nowvideo.py +++ b/youtube_dl/extractor/nowvideo.py @@ -1,28 +1,75 @@ from __future__ import unicode_literals -from .novamov import NovaMovIE +from .common import InfoExtractor +from ..utils import encode_dict +from ..compat import ( + compat_urllib_request, + compat_urllib_parse, + compat_urlparse +) +from ..utils import ( + ExtractorError, +) +import re - -class NowVideoIE(NovaMovIE): +class NowVideoIE(InfoExtractor): IE_NAME = 'nowvideo' IE_DESC = 'NowVideo' - _VALID_URL = NovaMovIE._VALID_URL_TEMPLATE % {'host': 'nowvideo\.(?:ch|ec|sx|eu|at|ag|co|li)'} + _VALID_URL = r'http://(?:(?:www\.)?%(host)s/(?:file|video)/|(?:(?:embed|www)\.)%(host)s/embed\.php\?(?:.*?&)?v=)(?P[a-z\d]{13})' % {'host': 'nowvideo\.(?:ch|ec|sx|eu|at|ag|co|li)'} - _HOST = 'www.nowvideo.ch' + _HOST = 'www.nowvideo.li' _FILE_DELETED_REGEX = r'>This file no longer exists on our servers.<' _FILEKEY_REGEX = r'var fkzd="([^"]+)";' - _TITLE_REGEX = r'

([^<]+)

' - _DESCRIPTION_REGEX = r'\s*

([^<]+)

' + _STEPKEY_REGEX = r'' _TEST = { - 'url': 'http://www.nowvideo.ch/video/0mw0yow7b6dxa', - 'md5': 'f8fbbc8add72bd95b7850c6a02fc8817', + 'url': 'http://www.nowvideo.li/video/edb2ded3aa118', 'info_dict': { - 'id': '0mw0yow7b6dxa', - 'ext': 'flv', - 'title': 'youtubedl test video _BaW_jenozKc.mp4', - 'description': 'Description', + 'id': 'edb2ded3aa118', + 'ext': 'mp4', + 'title': 'test' } } + + def _real_extract(self, url): + mobj = re.match(self._VALID_URL, url) + video_id = mobj.group('id') + page = self._download_webpage(url, video_id, 'Downloading video page') + + if re.search(self._FILE_DELETED_REGEX, page) is not None: + raise ExtractorError('Video %s does not exist' % video_id, expected=True) + + stepkey_value = self._search_regex(self._STEPKEY_REGEX, page, 'stepkey', fatal=True) + + form_str = { + 'stepkey': stepkey_value, + } + post_data = compat_urllib_parse.urlencode(encode_dict(form_str)).encode('ascii') + req = compat_urllib_request.Request(url, post_data) + req.add_header('Content-type', 'application/x-www-form-urlencoded') + + post_result = self._download_webpage( + req, video_id, + note='Proceed to video...', errnote='unable to proceed', fatal=True) + + filekey = self._search_regex(self._FILEKEY_REGEX, post_result, 'token', fatal=True) + + api_response = self._download_webpage( + 'http://%s/api/player.api.php?key=%s&file=%s' % (self._HOST, filekey, video_id), video_id, + 'Downloading video api response') + + response = compat_urlparse.parse_qs(api_response) + + if 'error_msg' in response: + raise ExtractorError('%s returned error: %s' % (self.IE_NAME, response['error_msg'][0]), expected=True) + + video_url = response['url'][0] + title = response['title'][0] + + return { + 'id': video_id, + 'url': video_url, + 'title': title + }