]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/aparat.py
remove unnecessary assignment parenthesis
[youtube-dl] / youtube_dl / extractor / aparat.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6     int_or_none,
7     mimetype2ext,
8 )
9
10
11 class AparatIE(InfoExtractor):
12     _VALID_URL = r'https?://(?:www\.)?aparat\.com/(?:v/|video/video/embed/videohash/)(?P<id>[a-zA-Z0-9]+)'
13
14     _TEST = {
15         'url': 'http://www.aparat.com/v/wP8On',
16         'md5': '131aca2e14fe7c4dcb3c4877ba300c89',
17         'info_dict': {
18             'id': 'wP8On',
19             'ext': 'mp4',
20             'title': 'تیم گلکسی 11 - زومیت',
21             'age_limit': 0,
22         },
23         # 'skip': 'Extremely unreliable',
24     }
25
26     def _real_extract(self, url):
27         video_id = self._match_id(url)
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
32         webpage = self._download_webpage(
33             'http://www.aparat.com/video/video/embed/vt/frame/showvideo/yes/videohash/' + video_id,
34             video_id)
35
36         title = self._search_regex(r'\s+title:\s*"([^"]+)"', webpage, 'title')
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
60         thumbnail = self._search_regex(
61             r'image:\s*"([^"]+)"', webpage, 'thumbnail', fatal=False)
62
63         return {
64             'id': video_id,
65             'title': title,
66             'thumbnail': thumbnail,
67             'age_limit': self._family_friendly_search(webpage),
68             'formats': formats,
69         }