]>
Commit | Line | Data |
---|---|---|
aa94a6d3 PH |
1 | from .common import InfoExtractor |
2 | from ..utils import ( | |
29f7c58a | 3 | get_element_by_id, |
70851a95 | 4 | int_or_none, |
2943397e | 5 | merge_dicts, |
70851a95 | 6 | mimetype2ext, |
3052a30d | 7 | url_or_none, |
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]+)' |
bfd973ec | 13 | _EMBED_REGEX = [r'<iframe .*?src="(?P<url>http://www\.aparat\.com/video/[^"]+)"'] |
aa94a6d3 | 14 | |
2943397e | 15 | _TESTS = [{ |
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 - زومیت', | |
2943397e S |
22 | 'description': 'md5:096bdabcdcc4569f2b8a5e903a3b3028', |
23 | 'duration': 231, | |
24 | 'timestamp': 1387394859, | |
25 | 'upload_date': '20131218', | |
26 | 'view_count': int, | |
aa94a6d3 | 27 | }, |
2943397e S |
28 | }, { |
29 | # multiple formats | |
30 | 'url': 'https://www.aparat.com/v/8dflw/', | |
31 | 'only_matching': True, | |
32 | }] | |
aa94a6d3 | 33 | |
99d6f946 | 34 | def _parse_options(self, webpage, video_id, fatal=True): |
35 | return self._parse_json(self._search_regex( | |
36 | r'options\s*=\s*({.+?})\s*;', webpage, 'options', default='{}'), video_id) | |
37 | ||
aa94a6d3 | 38 | def _real_extract(self, url): |
27e1400f | 39 | video_id = self._match_id(url) |
aa94a6d3 | 40 | |
99d6f946 | 41 | # If available, provides more metadata |
2943397e | 42 | webpage = self._download_webpage(url, video_id, fatal=False) |
99d6f946 | 43 | options = self._parse_options(webpage, video_id, fatal=False) |
2943397e | 44 | |
99d6f946 | 45 | if not options: |
2943397e S |
46 | webpage = self._download_webpage( |
47 | 'http://www.aparat.com/video/video/embed/vt/frame/showvideo/yes/videohash/' + video_id, | |
99d6f946 | 48 | video_id, 'Downloading embed webpage') |
49 | options = self._parse_options(webpage, video_id) | |
9c4a83a1 | 50 | |
70851a95 | 51 | formats = [] |
29f7c58a | 52 | for sources in (options.get('multiSRC') or []): |
2943397e S |
53 | for item in sources: |
54 | if not isinstance(item, dict): | |
55 | continue | |
9c4a83a1 AI |
56 | file_url = url_or_none(item.get('src')) |
57 | if not file_url: | |
58 | continue | |
2943397e S |
59 | item_type = item.get('type') |
60 | if item_type == 'application/vnd.apple.mpegurl': | |
61 | formats.extend(self._extract_m3u8_formats( | |
62 | file_url, video_id, 'mp4', | |
63 | entry_protocol='m3u8_native', m3u8_id='hls', | |
64 | fatal=False)) | |
65 | else: | |
66 | ext = mimetype2ext(item.get('type')) | |
67 | label = item.get('label') | |
68 | formats.append({ | |
69 | 'url': file_url, | |
70 | 'ext': ext, | |
71 | 'format_id': 'http-%s' % (label or ext), | |
72 | 'height': int_or_none(self._search_regex( | |
73 | r'(\d+)[pP]', label or '', 'height', | |
74 | default=None)), | |
75 | }) | |
54f37eea | 76 | self._sort_formats(formats) |
2943397e S |
77 | |
78 | info = self._search_json_ld(webpage, video_id, default={}) | |
70851a95 | 79 | |
2943397e | 80 | if not info.get('title'): |
29f7c58a | 81 | info['title'] = get_element_by_id('videoTitle', webpage) or \ |
82 | self._html_search_meta(['og:title', 'twitter:title', 'DC.Title', 'title'], webpage, fatal=True) | |
aa94a6d3 | 83 | |
2943397e | 84 | return merge_dicts(info, { |
aa94a6d3 | 85 | 'id': video_id, |
2943397e | 86 | 'thumbnail': url_or_none(options.get('poster')), |
29f7c58a | 87 | 'duration': int_or_none(options.get('duration')), |
70851a95 | 88 | 'formats': formats, |
2943397e | 89 | }) |