]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/novamov.py
Implement a different adult sites checking algorithm
[youtube-dl] / youtube_dl / extractor / novamov.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7     ExtractorError,
8     compat_urlparse
9 )
10
11
12 class NovamovIE(InfoExtractor):
13     _VALID_URL = r'http://(?:(?:www\.)?novamov\.com/video/|(?:(?:embed|www)\.)novamov\.com/embed\.php\?v=)(?P<videoid>[a-z\d]{13})'
14
15     _TEST = {
16         'url': 'http://www.novamov.com/video/4rurhn9x446jj',
17         'file': '4rurhn9x446jj.flv',
18         'md5': '7205f346a52bbeba427603ba10d4b935',
19         'info_dict': {
20             'title': 'search engine optimization',
21             'description': 'search engine optimization is used to rank the web page in the google search engine'
22         }
23     }
24
25     def _real_extract(self, url):
26         mobj = re.match(self._VALID_URL, url)
27         video_id = mobj.group('videoid')
28
29         page = self._download_webpage('http://www.novamov.com/video/%s' % video_id,
30                                       video_id, 'Downloading video page')
31
32         if re.search(r'This file no longer exists on our servers!</h2>', page) is not None:
33             raise ExtractorError(u'Video %s does not exist' % video_id, expected=True)
34
35         filekey = self._search_regex(
36             r'flashvars\.filekey="(?P<filekey>[^"]+)";', page, 'filekey')
37
38         title = self._html_search_regex(
39             r'(?s)<div class="v_tab blockborder rounded5" id="v_tab1">\s*<h3>([^<]+)</h3>',
40             page, 'title', fatal=False)
41
42         description = self._html_search_regex(
43             r'(?s)<div class="v_tab blockborder rounded5" id="v_tab1">\s*<h3>[^<]+</h3><p>([^<]+)</p>',
44             page, 'description', fatal=False)
45
46         api_response = self._download_webpage(
47             'http://www.novamov.com/api/player.api.php?key=%s&file=%s' % (filekey, video_id),
48             video_id, 'Downloading video api response')
49
50         response = compat_urlparse.parse_qs(api_response)
51
52         if 'error_msg' in response:
53             raise ExtractorError('novamov returned error: %s' % response['error_msg'][0], expected=True)
54
55         video_url = response['url'][0]
56
57         return {
58             'id': video_id,
59             'url': video_url,
60             'title': title,
61             'description': description
62         }