]>
Commit | Line | Data |
---|---|---|
5f6a1245 | 1 | # coding: utf-8 |
5fcf2dbe PH |
2 | from __future__ import unicode_literals |
3 | ||
aa94a6d3 PH |
4 | from .common import InfoExtractor |
5 | from ..utils import ( | |
70851a95 S |
6 | int_or_none, |
7 | mimetype2ext, | |
aa94a6d3 PH |
8 | ) |
9 | ||
10 | ||
11 | class AparatIE(InfoExtractor): | |
70851a95 | 12 | _VALID_URL = r'https?://(?:www\.)?aparat\.com/(?:v/|video/video/embed/videohash/)(?P<id>[a-zA-Z0-9]+)' |
aa94a6d3 PH |
13 | |
14 | _TEST = { | |
5fcf2dbe | 15 | 'url': 'http://www.aparat.com/v/wP8On', |
b1c6f21c | 16 | 'md5': '131aca2e14fe7c4dcb3c4877ba300c89', |
5fcf2dbe PH |
17 | 'info_dict': { |
18 | 'id': 'wP8On', | |
19 | 'ext': 'mp4', | |
20 | 'title': 'تیم گلکسی 11 - زومیت', | |
641eb10d | 21 | 'age_limit': 0, |
aa94a6d3 | 22 | }, |
5fcf2dbe | 23 | # 'skip': 'Extremely unreliable', |
aa94a6d3 PH |
24 | } |
25 | ||
26 | def _real_extract(self, url): | |
27e1400f | 27 | video_id = self._match_id(url) |
aa94a6d3 PH |
28 | |
29 | # Note: There is an easier-to-parse configuration at | |
30 | # http://www.aparat.com/video/video/config/videohash/%video_id | |
31 | # but the URL in there does not work | |
70851a95 S |
32 | webpage = self._download_webpage( |
33 | 'http://www.aparat.com/video/video/embed/vt/frame/showvideo/yes/videohash/' + video_id, | |
34 | video_id) | |
aa94a6d3 | 35 | |
27e1400f | 36 | title = self._search_regex(r'\s+title:\s*"([^"]+)"', webpage, 'title') |
70851a95 S |
37 | |
38 | file_list = self._parse_json( | |
39 | self._search_regex( | |
40 | r'fileList\s*=\s*JSON\.parse\(\'([^\']+)\'\)', webpage, | |
41 | 'file list'), | |
42 | video_id) | |
43 | ||
44 | formats = [] | |
45 | for item in file_list[0]: | |
46 | file_url = item.get('file') | |
47 | if not file_url: | |
48 | continue | |
49 | ext = mimetype2ext(item.get('type')) | |
50 | label = item.get('label') | |
51 | formats.append({ | |
52 | 'url': file_url, | |
53 | 'ext': ext, | |
54 | 'format_id': label or ext, | |
55 | 'height': int_or_none(self._search_regex( | |
56 | r'(\d+)[pP]', label or '', 'height', default=None)), | |
57 | }) | |
58 | self._sort_formats(formats) | |
59 | ||
aa94a6d3 | 60 | thumbnail = self._search_regex( |
c0e46412 | 61 | r'image:\s*"([^"]+)"', webpage, 'thumbnail', fatal=False) |
aa94a6d3 PH |
62 | |
63 | return { | |
64 | 'id': video_id, | |
65 | 'title': title, | |
aa94a6d3 | 66 | 'thumbnail': thumbnail, |
641eb10d | 67 | 'age_limit': self._family_friendly_search(webpage), |
70851a95 | 68 | 'formats': formats, |
aa94a6d3 | 69 | } |