]>
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 | |
70851a95 S |
37 | file_list = self._parse_json( |
38 | self._search_regex( | |
9c4a83a1 | 39 | r'var options\s*=\s*JSON\.parse\(\'([^\']+)\'\)', webpage, |
70851a95 S |
40 | 'file list'), |
41 | video_id) | |
42 | ||
9c4a83a1 AI |
43 | title = file_list['plugins']['sabaPlayerPlugin']['title'] |
44 | ||
70851a95 | 45 | formats = [] |
9c4a83a1 AI |
46 | for list in file_list['plugins']['sabaPlayerPlugin']['multiSRC']: |
47 | for item in list: | |
48 | file_url = url_or_none(item.get('src')) | |
49 | if not file_url: | |
50 | continue | |
51 | ext = mimetype2ext(item.get('type')) | |
52 | label = item.get('label') | |
53 | formats.append({ | |
54 | 'url': file_url, | |
55 | 'ext': ext, | |
56 | 'format_id': label or ext, | |
57 | 'height': int_or_none(self._search_regex( | |
58 | r'(\d+)[pP]', label or '', 'height', default=None)), | |
59 | }) | |
70851a95 S |
60 | self._sort_formats(formats) |
61 | ||
9c4a83a1 | 62 | thumbnail = file_list['poster'] |
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 | } |