1 from __future__ import unicode_literals
5 from .common import InfoExtractor
18 class NovaMovIE(InfoExtractor):
22 _VALID_URL_TEMPLATE = r'http://(?:(?:www\.)?%(host)s/(?:file|video)/|(?:(?:embed|www)\.)%(host)s/embed\.php\?(?:.*?&)?v=)(?P<id>[a-z\d]{13})'
23 _VALID_URL = _VALID_URL_TEMPLATE % {'host': 'novamov\.com'}
25 _HOST = 'www.novamov.com'
27 _FILE_DELETED_REGEX = r'This file no longer exists on our servers!</h2>'
28 _FILEKEY_REGEX = r'flashvars\.filekey="(?P<filekey>[^"]+)";'
29 _TITLE_REGEX = r'(?s)<div class="v_tab blockborder rounded5" id="v_tab1">\s*<h3>([^<]+)</h3>'
30 _DESCRIPTION_REGEX = r'(?s)<div class="v_tab blockborder rounded5" id="v_tab1">\s*<h3>[^<]+</h3><p>([^<]+)</p>'
33 'url': 'http://www.novamov.com/video/4rurhn9x446jj',
34 'md5': '7205f346a52bbeba427603ba10d4b935',
36 'id': '4rurhn9x446jj',
38 'title': 'search engine optimization',
39 'description': 'search engine optimization is used to rank the web page in the google search engine'
41 'skip': '"Invalid token" errors abound (in web interface as well as youtube-dl, there is nothing we can do about it.)'
44 def _real_extract(self, url):
45 mobj = re.match(self._VALID_URL, url)
46 video_id = mobj.group('id')
48 url = 'http://%s/video/%s' % (self._HOST, video_id)
50 webpage = self._download_webpage(
51 url, video_id, 'Downloading video page')
53 if re.search(self._FILE_DELETED_REGEX, webpage) is not None:
54 raise ExtractorError('Video %s does not exist' % video_id, expected=True)
56 def extract_filekey(default=NO_DEFAULT):
57 return self._search_regex(
58 self._FILEKEY_REGEX, webpage, 'filekey', default=default)
60 filekey = extract_filekey(default=None)
63 fields = self._hidden_inputs(webpage)
64 post_url = self._search_regex(
65 r'<form[^>]+action=(["\'])(?P<url>.+?)\1', webpage,
66 'post url', default=url, group='url')
67 if not post_url.startswith('http'):
68 post_url = compat_urlparse.urljoin(url, post_url)
69 request = compat_urllib_request.Request(
70 post_url, urlencode_postdata(encode_dict(fields)))
71 request.add_header('Content-Type', 'application/x-www-form-urlencoded')
72 request.add_header('Referer', post_url)
73 webpage = self._download_webpage(
74 request, video_id, 'Downloading continue to the video page')
76 filekey = extract_filekey()
78 title = self._html_search_regex(self._TITLE_REGEX, webpage, 'title', fatal=False)
79 description = self._html_search_regex(self._DESCRIPTION_REGEX, webpage, 'description', default='', fatal=False)
81 api_response = self._download_webpage(
82 'http://%s/api/player.api.php?key=%s&file=%s' % (self._HOST, filekey, video_id), video_id,
83 'Downloading video api response')
85 response = compat_urlparse.parse_qs(api_response)
87 if 'error_msg' in response:
88 raise ExtractorError('%s returned error: %s' % (self.IE_NAME, response['error_msg'][0]), expected=True)
90 video_url = response['url'][0]
96 'description': description