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