1
0
mirror of https://github.com/l1ving/youtube-dl synced 2025-02-05 03:02:54 +08:00

Fixed nowvideo extractor

This commit is contained in:
Marco Ferragina 2015-11-09 12:03:34 +01:00
parent ef1498dc3c
commit 0e04cdfa3c

View File

@ -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<id>[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'<h4>([^<]+)</h4>'
_DESCRIPTION_REGEX = r'</h4>\s*<p>([^<]+)</p>'
_STEPKEY_REGEX = r'<input type="hidden" name="stepkey" value="(.+)">'
_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
}