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 video_id = self._match_id(url)
47 url = 'http://%s/video/%s' % (self._HOST, video_id)
49 webpage = self._download_webpage(
50 url, video_id, 'Downloading video page')
52 if re.search(self._FILE_DELETED_REGEX, webpage) is not None:
53 raise ExtractorError('Video %s does not exist' % video_id, expected=True)
55 def extract_filekey(default=NO_DEFAULT):
56 return self._search_regex(
57 self._FILEKEY_REGEX, webpage, 'filekey', default=default)
59 filekey = extract_filekey(default=None)
62 fields = self._hidden_inputs(webpage)
63 post_url = self._search_regex(
64 r'<form[^>]+action=(["\'])(?P<url>.+?)\1', webpage,
65 'post url', default=url, group='url')
66 if not post_url.startswith('http'):
67 post_url = compat_urlparse.urljoin(url, post_url)
68 request = compat_urllib_request.Request(
69 post_url, urlencode_postdata(encode_dict(fields)))
70 request.add_header('Content-Type', 'application/x-www-form-urlencoded')
71 request.add_header('Referer', post_url)
72 webpage = self._download_webpage(
73 request, video_id, 'Downloading continue to the video page')
75 filekey = extract_filekey()
77 title = self._html_search_regex(self._TITLE_REGEX, webpage, 'title', fatal=False)
78 description = self._html_search_regex(self._DESCRIPTION_REGEX, webpage, 'description', default='', fatal=False)
80 api_response = self._download_webpage(
81 'http://%s/api/player.api.php?key=%s&file=%s' % (self._HOST, filekey, video_id), video_id,
82 'Downloading video api response')
84 response = compat_urlparse.parse_qs(api_response)
86 if 'error_msg' in response:
87 raise ExtractorError('%s returned error: %s' % (self.IE_NAME, response['error_msg'][0]), expected=True)
89 video_url = response['url'][0]
95 'description': description