]>
Commit | Line | Data |
---|---|---|
5f6a1245 | 1 | # coding: utf-8 |
5fcf2dbe PH |
2 | from __future__ import unicode_literals |
3 | ||
aa94a6d3 PH |
4 | import re |
5 | ||
6 | from .common import InfoExtractor | |
7 | from ..utils import ( | |
8 | ExtractorError, | |
9 | HEADRequest, | |
10 | ) | |
11 | ||
12 | ||
13 | class AparatIE(InfoExtractor): | |
14 | _VALID_URL = r'^https?://(?:www\.)?aparat\.com/(?:v/|video/video/embed/videohash/)(?P<id>[a-zA-Z0-9]+)' | |
15 | ||
16 | _TEST = { | |
5fcf2dbe PH |
17 | 'url': 'http://www.aparat.com/v/wP8On', |
18 | 'md5': '6714e0af7e0d875c5a39c4dc4ab46ad1', | |
19 | 'info_dict': { | |
20 | 'id': 'wP8On', | |
21 | 'ext': 'mp4', | |
22 | 'title': 'تیم گلکسی 11 - زومیت', | |
641eb10d | 23 | 'age_limit': 0, |
aa94a6d3 | 24 | }, |
5fcf2dbe | 25 | # 'skip': 'Extremely unreliable', |
aa94a6d3 PH |
26 | } |
27 | ||
28 | def _real_extract(self, url): | |
27e1400f | 29 | video_id = self._match_id(url) |
aa94a6d3 PH |
30 | |
31 | # Note: There is an easier-to-parse configuration at | |
32 | # http://www.aparat.com/video/video/config/videohash/%video_id | |
33 | # but the URL in there does not work | |
5fcf2dbe PH |
34 | embed_url = ('http://www.aparat.com/video/video/embed/videohash/' + |
35 | video_id + '/vt/frame') | |
aa94a6d3 PH |
36 | webpage = self._download_webpage(embed_url, video_id) |
37 | ||
c0e46412 S |
38 | video_urls = [video_url.replace('\\/', '/') for video_url in re.findall( |
39 | r'(?:fileList\[[0-9]+\]\s*=|"file"\s*:)\s*"([^"]+)"', webpage)] | |
aa94a6d3 PH |
40 | for i, video_url in enumerate(video_urls): |
41 | req = HEADRequest(video_url) | |
42 | res = self._request_webpage( | |
27e1400f | 43 | req, video_id, note='Testing video URL %d' % i, errnote=False) |
aa94a6d3 PH |
44 | if res: |
45 | break | |
46 | else: | |
27e1400f | 47 | raise ExtractorError('No working video URLs found') |
aa94a6d3 | 48 | |
27e1400f | 49 | title = self._search_regex(r'\s+title:\s*"([^"]+)"', webpage, 'title') |
aa94a6d3 | 50 | thumbnail = self._search_regex( |
c0e46412 | 51 | r'image:\s*"([^"]+)"', webpage, 'thumbnail', fatal=False) |
aa94a6d3 PH |
52 | |
53 | return { | |
54 | 'id': video_id, | |
55 | 'title': title, | |
56 | 'url': video_url, | |
57 | 'ext': 'mp4', | |
58 | 'thumbnail': thumbnail, | |
641eb10d | 59 | 'age_limit': self._family_friendly_search(webpage), |
aa94a6d3 | 60 | } |