You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.9 KiB

10 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. HEADRequest,
  7. )
  8. class AparatIE(InfoExtractor):
  9. _VALID_URL = r'^https?://(?:www\.)?aparat\.com/(?:v/|video/video/embed/videohash/)(?P<id>[a-zA-Z0-9]+)'
  10. _TEST = {
  11. 'url': 'http://www.aparat.com/v/wP8On',
  12. 'md5': '131aca2e14fe7c4dcb3c4877ba300c89',
  13. 'info_dict': {
  14. 'id': 'wP8On',
  15. 'ext': 'mp4',
  16. 'title': 'تیم گلکسی 11 - زومیت',
  17. 'age_limit': 0,
  18. },
  19. # 'skip': 'Extremely unreliable',
  20. }
  21. def _real_extract(self, url):
  22. video_id = self._match_id(url)
  23. # Note: There is an easier-to-parse configuration at
  24. # http://www.aparat.com/video/video/config/videohash/%video_id
  25. # but the URL in there does not work
  26. embed_url = 'http://www.aparat.com/video/video/embed/vt/frame/showvideo/yes/videohash/' + video_id
  27. webpage = self._download_webpage(embed_url, video_id)
  28. file_list = self._parse_json(self._search_regex(
  29. r'fileList\s*=\s*JSON\.parse\(\'([^\']+)\'\)', webpage, 'file list'), video_id)
  30. for i, item in enumerate(file_list[0]):
  31. video_url = item['file']
  32. req = HEADRequest(video_url)
  33. res = self._request_webpage(
  34. req, video_id, note='Testing video URL %d' % i, errnote=False)
  35. if res:
  36. break
  37. else:
  38. raise ExtractorError('No working video URLs found')
  39. title = self._search_regex(r'\s+title:\s*"([^"]+)"', webpage, 'title')
  40. thumbnail = self._search_regex(
  41. r'image:\s*"([^"]+)"', webpage, 'thumbnail', fatal=False)
  42. return {
  43. 'id': video_id,
  44. 'title': title,
  45. 'url': video_url,
  46. 'ext': 'mp4',
  47. 'thumbnail': thumbnail,
  48. 'age_limit': self._family_friendly_search(webpage),
  49. }