[utils] imporove parse_duration to handle more formats
[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 ..compat import compat_urlparse
7 from ..utils import (
8     ExtractorError,
9     NO_DEFAULT,
10     sanitized_Request,
11     urlencode_postdata,
12 )
13
14
15 class NovaMovIE(InfoExtractor):
16     IE_NAME = 'novamov'
17     IE_DESC = 'NovaMov'
18
19     _VALID_URL_TEMPLATE = r'http://(?:(?:www\.)?%(host)s/(?:file|video|mobile/#/videos)/|(?:(?:embed|www)\.)%(host)s/embed\.php\?(?:.*?&)?v=)(?P<id>[a-z\d]{13})'
20     _VALID_URL = _VALID_URL_TEMPLATE % {'host': 'novamov\.com'}
21
22     _HOST = 'www.novamov.com'
23
24     _FILE_DELETED_REGEX = r'This file no longer exists on our servers!</h2>'
25     _FILEKEY_REGEX = r'flashvars\.filekey=(?P<filekey>"?[^"]+"?);'
26     _TITLE_REGEX = r'(?s)<div class="v_tab blockborder rounded5" id="v_tab1">\s*<h3>([^<]+)</h3>'
27     _DESCRIPTION_REGEX = r'(?s)<div class="v_tab blockborder rounded5" id="v_tab1">\s*<h3>[^<]+</h3><p>([^<]+)</p>'
28     _URL_TEMPLATE = 'http://%s/video/%s'
29
30     _TEST = None
31
32     def _check_existence(self, webpage, video_id):
33         if re.search(self._FILE_DELETED_REGEX, webpage) is not None:
34             raise ExtractorError('Video %s does not exist' % video_id, expected=True)
35
36     def _real_extract(self, url):
37         video_id = self._match_id(url)
38
39         url = self._URL_TEMPLATE % (self._HOST, video_id)
40
41         webpage = self._download_webpage(
42             url, video_id, 'Downloading video page')
43
44         self._check_existence(webpage, video_id)
45
46         def extract_filekey(default=NO_DEFAULT):
47             filekey = self._search_regex(
48                 self._FILEKEY_REGEX, webpage, 'filekey', default=default)
49             if filekey is not default and (filekey[0] != '"' or filekey[-1] != '"'):
50                 return self._search_regex(
51                     r'var\s+%s\s*=\s*"([^"]+)"' % re.escape(filekey), webpage, 'filekey', default=default)
52             else:
53                 return filekey
54
55         filekey = extract_filekey(default=None)
56
57         if not filekey:
58             fields = self._hidden_inputs(webpage)
59             post_url = self._search_regex(
60                 r'<form[^>]+action=(["\'])(?P<url>.+?)\1', webpage,
61                 'post url', default=url, group='url')
62             if not post_url.startswith('http'):
63                 post_url = compat_urlparse.urljoin(url, post_url)
64             request = sanitized_Request(
65                 post_url, urlencode_postdata(fields))
66             request.add_header('Content-Type', 'application/x-www-form-urlencoded')
67             request.add_header('Referer', post_url)
68             webpage = self._download_webpage(
69                 request, video_id, 'Downloading continue to the video page')
70             self._check_existence(webpage, video_id)
71
72         filekey = extract_filekey()
73
74         title = self._html_search_regex(self._TITLE_REGEX, webpage, 'title')
75         description = self._html_search_regex(self._DESCRIPTION_REGEX, webpage, 'description', default='', fatal=False)
76
77         api_response = self._download_webpage(
78             'http://%s/api/player.api.php?key=%s&file=%s' % (self._HOST, filekey, video_id), video_id,
79             'Downloading video api response')
80
81         response = compat_urlparse.parse_qs(api_response)
82
83         if 'error_msg' in response:
84             raise ExtractorError('%s returned error: %s' % (self.IE_NAME, response['error_msg'][0]), expected=True)
85
86         video_url = response['url'][0]
87
88         return {
89             'id': video_id,
90             'url': video_url,
91             'title': title,
92             'description': description
93         }
94
95
96 class WholeCloudIE(NovaMovIE):
97     IE_NAME = 'wholecloud'
98     IE_DESC = 'WholeCloud'
99
100     _VALID_URL = NovaMovIE._VALID_URL_TEMPLATE % {'host': '(?:wholecloud\.net|movshare\.(?:net|sx|ag))'}
101
102     _HOST = 'www.wholecloud.net'
103
104     _FILE_DELETED_REGEX = r'>This file no longer exists on our servers.<'
105     _TITLE_REGEX = r'<strong>Title:</strong> ([^<]+)</p>'
106     _DESCRIPTION_REGEX = r'<strong>Description:</strong> ([^<]+)</p>'
107
108     _TEST = {
109         'url': 'http://www.wholecloud.net/video/559e28be54d96',
110         'md5': 'abd31a2132947262c50429e1d16c1bfd',
111         'info_dict': {
112             'id': '559e28be54d96',
113             'ext': 'flv',
114             'title': 'dissapeared image',
115             'description': 'optical illusion  dissapeared image  magic illusion',
116         }
117     }
118
119
120 class NowVideoIE(NovaMovIE):
121     IE_NAME = 'nowvideo'
122     IE_DESC = 'NowVideo'
123
124     _VALID_URL = NovaMovIE._VALID_URL_TEMPLATE % {'host': 'nowvideo\.(?:to|ch|ec|sx|eu|at|ag|co|li)'}
125
126     _HOST = 'www.nowvideo.to'
127
128     _FILE_DELETED_REGEX = r'>This file no longer exists on our servers.<'
129     _TITLE_REGEX = r'<h4>([^<]+)</h4>'
130     _DESCRIPTION_REGEX = r'</h4>\s*<p>([^<]+)</p>'
131
132     _TEST = {
133         'url': 'http://www.nowvideo.sx/video/f1d6fce9a968b',
134         'md5': '12c82cad4f2084881d8bc60ee29df092',
135         'info_dict': {
136             'id': 'f1d6fce9a968b',
137             'ext': 'flv',
138             'title': 'youtubedl test video BaWjenozKc',
139             'description': 'Description',
140         },
141     }
142
143
144 class VideoWeedIE(NovaMovIE):
145     IE_NAME = 'videoweed'
146     IE_DESC = 'VideoWeed'
147
148     _VALID_URL = NovaMovIE._VALID_URL_TEMPLATE % {'host': 'videoweed\.(?:es|com)'}
149
150     _HOST = 'www.videoweed.es'
151
152     _FILE_DELETED_REGEX = r'>This file no longer exists on our servers.<'
153     _TITLE_REGEX = r'<h1 class="text_shadow">([^<]+)</h1>'
154     _URL_TEMPLATE = 'http://%s/file/%s'
155
156     _TEST = {
157         'url': 'http://www.videoweed.es/file/b42178afbea14',
158         'md5': 'abd31a2132947262c50429e1d16c1bfd',
159         'info_dict': {
160             'id': 'b42178afbea14',
161             'ext': 'flv',
162             'title': 'optical illusion  dissapeared image magic illusion',
163             'description': ''
164         },
165     }
166
167
168 class CloudTimeIE(NovaMovIE):
169     IE_NAME = 'cloudtime'
170     IE_DESC = 'CloudTime'
171
172     _VALID_URL = NovaMovIE._VALID_URL_TEMPLATE % {'host': 'cloudtime\.to'}
173
174     _HOST = 'www.cloudtime.to'
175
176     _FILE_DELETED_REGEX = r'>This file no longer exists on our servers.<'
177     _TITLE_REGEX = r'<div[^>]+class=["\']video_det["\'][^>]*>\s*<strong>([^<]+)</strong>'
178
179     _TEST = None
180
181
182 class AuroraVidIE(NovaMovIE):
183     IE_NAME = 'auroravid'
184     IE_DESC = 'AuroraVid'
185
186     _VALID_URL = NovaMovIE._VALID_URL_TEMPLATE % {'host': 'auroravid\.to'}
187
188     _HOST = 'www.auroravid.to'
189
190     _FILE_DELETED_REGEX = r'This file no longer exists on our servers!<'
191
192     _TEST = {
193         'url': 'http://www.auroravid.to/video/4rurhn9x446jj',
194         'md5': '7205f346a52bbeba427603ba10d4b935',
195         'info_dict': {
196             'id': '4rurhn9x446jj',
197             'ext': 'flv',
198             'title': 'search engine optimization',
199             'description': 'search engine optimization is used to rank the web page in the google search engine'
200         },
201         'skip': '"Invalid token" errors abound (in web interface as well as youtube-dl, there is nothing we can do about it.)'
202     }