]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/aparat.py
debian/watch: Make use of the signing key from upstream.
[youtubedl] / youtube_dl / extractor / aparat.py
1 #coding: utf-8
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7 ExtractorError,
8 HEADRequest,
9 )
10
11
12 class AparatIE(InfoExtractor):
13 _VALID_URL = r'^https?://(?:www\.)?aparat\.com/(?:v/|video/video/embed/videohash/)(?P<id>[a-zA-Z0-9]+)'
14
15 _TEST = {
16 u'url': u'http://www.aparat.com/v/wP8On',
17 u'file': u'wP8On.mp4',
18 u'md5': u'6714e0af7e0d875c5a39c4dc4ab46ad1',
19 u'info_dict': {
20 u"title": u"تیم گلکسی 11 - زومیت",
21 },
22 #u'skip': u'Extremely unreliable',
23 }
24
25 def _real_extract(self, url):
26 m = re.match(self._VALID_URL, url)
27 video_id = m.group('id')
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 embed_url = (u'http://www.aparat.com/video/video/embed/videohash/' +
33 video_id + u'/vt/frame')
34 webpage = self._download_webpage(embed_url, video_id)
35
36 video_urls = re.findall(r'fileList\[[0-9]+\]\s*=\s*"([^"]+)"', webpage)
37 for i, video_url in enumerate(video_urls):
38 req = HEADRequest(video_url)
39 res = self._request_webpage(
40 req, video_id, note=u'Testing video URL %d' % i, errnote=False)
41 if res:
42 break
43 else:
44 raise ExtractorError(u'No working video URLs found')
45
46 title = self._search_regex(r'\s+title:\s*"([^"]+)"', webpage, u'title')
47 thumbnail = self._search_regex(
48 r'\s+image:\s*"([^"]+)"', webpage, u'thumbnail', fatal=False)
49
50 return {
51 'id': video_id,
52 'title': title,
53 'url': video_url,
54 'ext': 'mp4',
55 'thumbnail': thumbnail,
56 }