]>
Commit | Line | Data |
---|---|---|
cc253000 | 1 | from __future__ import unicode_literals |
2 | ||
3 | import re | |
4 | ||
5 | from .common import InfoExtractor | |
1cc79574 PH |
6 | from ..compat import ( |
7 | compat_urlparse, | |
8 | ) | |
cc253000 | 9 | from ..utils import ( |
10 | ExtractorError, | |
cc253000 | 11 | ) |
12 | ||
10bff13a | 13 | |
ce78943a S |
14 | class NovaMovIE(InfoExtractor): |
15 | IE_NAME = 'novamov' | |
16 | IE_DESC = 'NovaMov' | |
17 | ||
17c5a007 | 18 | _VALID_URL_TEMPLATE = r'http://(?:(?:www\.)?%(host)s/(?:file|video)/|(?:(?:embed|www)\.)%(host)s/embed\.php\?(?:.*?&)?v=)(?P<id>[a-z\d]{13})' |
60ccc59a | 19 | _VALID_URL = _VALID_URL_TEMPLATE % {'host': 'novamov\.com'} |
ce78943a S |
20 | |
21 | _HOST = 'www.novamov.com' | |
22 | ||
23 | _FILE_DELETED_REGEX = r'This file no longer exists on our servers!</h2>' | |
24 | _FILEKEY_REGEX = r'flashvars\.filekey="(?P<filekey>[^"]+)";' | |
25 | _TITLE_REGEX = r'(?s)<div class="v_tab blockborder rounded5" id="v_tab1">\s*<h3>([^<]+)</h3>' | |
26 | _DESCRIPTION_REGEX = r'(?s)<div class="v_tab blockborder rounded5" id="v_tab1">\s*<h3>[^<]+</h3><p>([^<]+)</p>' | |
cc253000 | 27 | |
28 | _TEST = { | |
29 | 'url': 'http://www.novamov.com/video/4rurhn9x446jj', | |
cc253000 | 30 | 'md5': '7205f346a52bbeba427603ba10d4b935', |
31 | 'info_dict': { | |
ce78943a S |
32 | 'id': '4rurhn9x446jj', |
33 | 'ext': 'flv', | |
cc253000 | 34 | 'title': 'search engine optimization', |
35 | 'description': 'search engine optimization is used to rank the web page in the google search engine' | |
90f479b6 PH |
36 | }, |
37 | 'skip': '"Invalid token" errors abound (in web interface as well as youtube-dl, there is nothing we can do about it.)' | |
cc253000 | 38 | } |
39 | ||
40 | def _real_extract(self, url): | |
41 | mobj = re.match(self._VALID_URL, url) | |
17c5a007 | 42 | video_id = mobj.group('id') |
cc253000 | 43 | |
ce78943a S |
44 | page = self._download_webpage( |
45 | 'http://%s/video/%s' % (self._HOST, video_id), video_id, 'Downloading video page') | |
cc253000 | 46 | |
ce78943a | 47 | if re.search(self._FILE_DELETED_REGEX, page) is not None: |
17c5a007 | 48 | raise ExtractorError('Video %s does not exist' % video_id, expected=True) |
cc253000 | 49 | |
ce78943a | 50 | filekey = self._search_regex(self._FILEKEY_REGEX, page, 'filekey') |
cc253000 | 51 | |
ce78943a | 52 | title = self._html_search_regex(self._TITLE_REGEX, page, 'title', fatal=False) |
ce78943a | 53 | description = self._html_search_regex(self._DESCRIPTION_REGEX, page, 'description', default='', fatal=False) |
cc253000 | 54 | |
10bff13a | 55 | api_response = self._download_webpage( |
ce78943a S |
56 | 'http://%s/api/player.api.php?key=%s&file=%s' % (self._HOST, filekey, video_id), video_id, |
57 | 'Downloading video api response') | |
cc253000 | 58 | |
59 | response = compat_urlparse.parse_qs(api_response) | |
60 | ||
61 | if 'error_msg' in response: | |
ce78943a | 62 | raise ExtractorError('%s returned error: %s' % (self.IE_NAME, response['error_msg'][0]), expected=True) |
cc253000 | 63 | |
64 | video_url = response['url'][0] | |
65 | ||
66 | return { | |
67 | 'id': video_id, | |
68 | 'url': video_url, | |
69 | 'title': title, | |
70 | 'description': description | |
5f6a1245 | 71 | } |