mirror of
https://github.com/l1ving/youtube-dl
synced 2025-02-10 23:03:01 +08:00
Fixed nowvideo extractor
This commit is contained in:
parent
ef1498dc3c
commit
0e04cdfa3c
@ -1,28 +1,75 @@
|
|||||||
from __future__ import unicode_literals
|
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(InfoExtractor):
|
||||||
class NowVideoIE(NovaMovIE):
|
|
||||||
IE_NAME = 'nowvideo'
|
IE_NAME = 'nowvideo'
|
||||||
IE_DESC = '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.<'
|
_FILE_DELETED_REGEX = r'>This file no longer exists on our servers.<'
|
||||||
_FILEKEY_REGEX = r'var fkzd="([^"]+)";'
|
_FILEKEY_REGEX = r'var fkzd="([^"]+)";'
|
||||||
_TITLE_REGEX = r'<h4>([^<]+)</h4>'
|
_STEPKEY_REGEX = r'<input type="hidden" name="stepkey" value="(.+)">'
|
||||||
_DESCRIPTION_REGEX = r'</h4>\s*<p>([^<]+)</p>'
|
|
||||||
|
|
||||||
_TEST = {
|
_TEST = {
|
||||||
'url': 'http://www.nowvideo.ch/video/0mw0yow7b6dxa',
|
'url': 'http://www.nowvideo.li/video/edb2ded3aa118',
|
||||||
'md5': 'f8fbbc8add72bd95b7850c6a02fc8817',
|
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '0mw0yow7b6dxa',
|
'id': 'edb2ded3aa118',
|
||||||
'ext': 'flv',
|
'ext': 'mp4',
|
||||||
'title': 'youtubedl test video _BaW_jenozKc.mp4',
|
'title': 'test'
|
||||||
'description': 'Description',
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user