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.

69 lines
2.1 KiB

10 years ago
  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. )
  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. webpage = self._download_webpage(
  27. 'http://www.aparat.com/video/video/embed/vt/frame/showvideo/yes/videohash/' + video_id,
  28. video_id)
  29. title = self._search_regex(r'\s+title:\s*"([^"]+)"', webpage, 'title')
  30. file_list = self._parse_json(
  31. self._search_regex(
  32. r'fileList\s*=\s*JSON\.parse\(\'([^\']+)\'\)', webpage,
  33. 'file list'),
  34. video_id)
  35. formats = []
  36. for item in file_list[0]:
  37. file_url = item.get('file')
  38. if not file_url:
  39. continue
  40. ext = mimetype2ext(item.get('type'))
  41. label = item.get('label')
  42. formats.append({
  43. 'url': file_url,
  44. 'ext': ext,
  45. 'format_id': label or ext,
  46. 'height': int_or_none(self._search_regex(
  47. r'(\d+)[pP]', label or '', 'height', default=None)),
  48. })
  49. self._sort_formats(formats)
  50. thumbnail = self._search_regex(
  51. r'image:\s*"([^"]+)"', webpage, 'thumbnail', fatal=False)
  52. return {
  53. 'id': video_id,
  54. 'title': title,
  55. 'thumbnail': thumbnail,
  56. 'age_limit': self._family_friendly_search(webpage),
  57. 'formats': formats,
  58. }