2 from __future__ 
import unicode_literals
 
   4 from .common 
import InfoExtractor
 
  11 class AparatIE(InfoExtractor
): 
  12     _VALID_URL 
= r
'^https?://(?:www\.)?aparat\.com/(?:v/|video/video/embed/videohash/)(?P<id>[a-zA-Z0-9]+)' 
  15         'url': 'http://www.aparat.com/v/wP8On', 
  16         'md5': '131aca2e14fe7c4dcb3c4877ba300c89', 
  20             'title': 'تیم گلکسی 11 - زومیت', 
  23         # 'skip': 'Extremely unreliable', 
  26     def _real_extract(self
, url
): 
  27         video_id 
= self
._match
_id
(url
) 
  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 
= 'http://www.aparat.com/video/video/embed/vt/frame/showvideo/yes/videohash/' + video_id
 
  33         webpage 
= self
._download
_webpage
(embed_url
, video_id
) 
  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'] 
  39             req = HEADRequest(video_url) 
  40             res = self._request_webpage( 
  41                 req, video_id, note='Testing video URL 
%d' % i, errnote=False) 
  45             raise ExtractorError('No working video URLs found
') 
  47         title = self._search_regex(r'\s
+title
:\s
*"([^"]+)"', webpage, 'title') 
  48         thumbnail = self._search_regex( 
  49             r'image:\s*"([^
"]+)"', webpage, 'thumbnail
', fatal=False) 
  56             'thumbnail
': thumbnail, 
  57             'age_limit
': self._family_friendly_search(webpage),