aparat.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. int_or_none,
  6. mimetype2ext,
  7. url_or_none,
  8. )
  9. class AparatIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?aparat\.com/(?:v/|video/video/embed/videohash/)(?P<id>[a-zA-Z0-9]+)'
  11. _TEST = {
  12. 'url': 'http://www.aparat.com/v/wP8On',
  13. 'md5': '131aca2e14fe7c4dcb3c4877ba300c89',
  14. 'info_dict': {
  15. 'id': 'wP8On',
  16. 'ext': 'mp4',
  17. 'title': 'تیم گلکسی 11 - زومیت',
  18. 'age_limit': 0,
  19. },
  20. # 'skip': 'Extremely unreliable',
  21. }
  22. def _real_extract(self, url):
  23. video_id = self._match_id(url)
  24. # Note: There is an easier-to-parse configuration at
  25. # http://www.aparat.com/video/video/config/videohash/%video_id
  26. # but the URL in there does not work
  27. webpage = self._download_webpage(
  28. 'http://www.aparat.com/video/video/embed/vt/frame/showvideo/yes/videohash/' + video_id,
  29. video_id)
  30. file_list = self._parse_json(
  31. self._search_regex(
  32. r'var options\s*=\s*JSON\.parse\(\'([^\']+)\'\)', webpage,
  33. 'file list'),
  34. video_id)
  35. title = file_list['plugins']['sabaPlayerPlugin']['title']
  36. formats = []
  37. for list in file_list['plugins']['sabaPlayerPlugin']['multiSRC']:
  38. for item in list:
  39. file_url = url_or_none(item.get('src'))
  40. if not file_url:
  41. continue
  42. ext = mimetype2ext(item.get('type'))
  43. label = item.get('label')
  44. formats.append({
  45. 'url': file_url,
  46. 'ext': ext,
  47. 'format_id': label or ext,
  48. 'height': int_or_none(self._search_regex(
  49. r'(\d+)[pP]', label or '', 'height', default=None)),
  50. })
  51. self._sort_formats(formats)
  52. thumbnail = file_list['poster']
  53. return {
  54. 'id': video_id,
  55. 'title': title,
  56. 'thumbnail': thumbnail,
  57. 'age_limit': self._family_friendly_search(webpage),
  58. 'formats': formats,
  59. }