1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
6 from ..compat
import compat_urlparse
16 class NovaMovIE(InfoExtractor
):
20 _VALID_URL_TEMPLATE
= r
'http://(?:(?:www\.)?%(host)s/(?:file|video)/|(?:(?:embed|www)\.)%(host)s/embed\.php\?(?:.*?&)?v=)(?P<id>[a-z\d]{13})'
21 _VALID_URL
= _VALID_URL_TEMPLATE
% {'host': 'novamov\.com'}
23 _HOST
= 'www.novamov.com'
25 _FILE_DELETED_REGEX
= r
'This file no longer exists on our servers!</h2>'
26 _FILEKEY_REGEX
= r
'flashvars\.filekey="(?P<filekey>[^"]+)";'
27 _TITLE_REGEX
= r
'(?s)<div class="v_tab blockborder rounded5" id="v_tab1">\s*<h3>([^<]+)</h3>'
28 _DESCRIPTION_REGEX
= r
'(?s)<div class="v_tab blockborder rounded5" id="v_tab1">\s*<h3>[^<]+</h3><p>([^<]+)</p>'
31 'url': 'http://www.novamov.com/video/4rurhn9x446jj',
32 'md5': '7205f346a52bbeba427603ba10d4b935',
34 'id': '4rurhn9x446jj',
36 'title': 'search engine optimization',
37 'description': 'search engine optimization is used to rank the web page in the google search engine'
39 'skip': '"Invalid token" errors abound (in web interface as well as youtube-dl, there is nothing we can do about it.)'
42 def _real_extract(self
, url
):
43 video_id
= self
._match
_id
(url
)
45 url
= 'http://%s/video/%s' % (self
._HOST
, video_id
)
47 webpage
= self
._download
_webpage
(
48 url
, video_id
, 'Downloading video page')
50 if re
.search(self
._FILE
_DELETED
_REGEX
, webpage
) is not None:
51 raise ExtractorError('Video %s does not exist' % video_id
, expected
=True)
53 def extract_filekey(default
=NO_DEFAULT
):
54 return self
._search
_regex
(
55 self
._FILEKEY
_REGEX
, webpage
, 'filekey', default
=default
)
57 filekey
= extract_filekey(default
=None)
60 fields
= self
._hidden
_inputs
(webpage
)
61 post_url
= self
._search
_regex
(
62 r
'<form[^>]+action=(["\'])(?P
<url
>.+?
)\
1', webpage,
63 'post url
', default=url, group='url
')
64 if not post_url.startswith('http
'):
65 post_url = compat_urlparse.urljoin(url, post_url)
66 request = sanitized_Request(
67 post_url, urlencode_postdata(encode_dict(fields)))
68 request.add_header('Content
-Type
', 'application
/x
-www
-form
-urlencoded
')
69 request.add_header('Referer
', post_url)
70 webpage = self._download_webpage(
71 request, video_id, 'Downloading
continue to the video page
')
73 filekey = extract_filekey()
75 title = self._html_search_regex(self._TITLE_REGEX, webpage, 'title
', fatal=False)
76 description = self._html_search_regex(self._DESCRIPTION_REGEX, webpage, 'description
', default='', fatal=False)
78 api_response = self._download_webpage(
79 'http
://%s/api
/player
.api
.php?key
=%s&file=%s' % (self._HOST, filekey, video_id), video_id,
80 'Downloading video api response
')
82 response = compat_urlparse.parse_qs(api_response)
84 if 'error_msg
' in response:
85 raise ExtractorError('%s returned error
: %s' % (self.IE_NAME, response['error_msg
'][0]), expected=True)
87 video_url = response['url
'][0]
93 'description
': description