]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/aparat.py
[polskieradio] Fix extraction
[yt-dlp.git] / youtube_dl / extractor / aparat.py
CommitLineData
5f6a1245 1# coding: utf-8
5fcf2dbe
PH
2from __future__ import unicode_literals
3
aa94a6d3
PH
4from .common import InfoExtractor
5from ..utils import (
6 ExtractorError,
7 HEADRequest,
8)
9
10
11class AparatIE(InfoExtractor):
12 _VALID_URL = r'^https?://(?:www\.)?aparat\.com/(?:v/|video/video/embed/videohash/)(?P<id>[a-zA-Z0-9]+)'
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
b1c6f21c 32 embed_url = 'http://www.aparat.com/video/video/embed/vt/frame/showvideo/yes/videohash/' + video_id
aa94a6d3
PH
33 webpage = self._download_webpage(embed_url, video_id)
34
b1c6f21c
YCH
35 file_list = self._parse_json(self._search_regex(
36 r'fileList\s*=\s*JSON\.parse\(\'([^\']+)\'\)', webpage, 'file list'), video_id)
37 for i, item in enumerate(file_list[0]):
38 video_url = item['file']
aa94a6d3
PH
39 req = HEADRequest(video_url)
40 res = self._request_webpage(
27e1400f 41 req, video_id, note='Testing video URL %d' % i, errnote=False)
aa94a6d3
PH
42 if res:
43 break
44 else:
27e1400f 45 raise ExtractorError('No working video URLs found')
aa94a6d3 46
27e1400f 47 title = self._search_regex(r'\s+title:\s*"([^"]+)"', webpage, 'title')
aa94a6d3 48 thumbnail = self._search_regex(
c0e46412 49 r'image:\s*"([^"]+)"', webpage, 'thumbnail', fatal=False)
aa94a6d3
PH
50
51 return {
52 'id': video_id,
53 'title': title,
54 'url': video_url,
55 'ext': 'mp4',
56 'thumbnail': thumbnail,
641eb10d 57 'age_limit': self._family_friendly_search(webpage),
aa94a6d3 58 }