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.

70 lines
2.2 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. 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. title = self._search_regex(r'\s+title:\s*"([^"]+)"', webpage, 'title')
  31. file_list = self._parse_json(
  32. self._search_regex(
  33. r'fileList\s*=\s*JSON\.parse\(\'([^\']+)\'\)', webpage,
  34. 'file list'),
  35. video_id)
  36. formats = []
  37. for item in file_list[0]:
  38. file_url = url_or_none(item.get('file'))
  39. if not file_url:
  40. continue
  41. ext = mimetype2ext(item.get('type'))
  42. label = item.get('label')
  43. formats.append({
  44. 'url': file_url,
  45. 'ext': ext,
  46. 'format_id': label or ext,
  47. 'height': int_or_none(self._search_regex(
  48. r'(\d+)[pP]', label or '', 'height', default=None)),
  49. })
  50. self._sort_formats(formats)
  51. thumbnail = self._search_regex(
  52. r'image:\s*"([^"]+)"', webpage, 'thumbnail', fatal=False)
  53. return {
  54. 'id': video_id,
  55. 'title': title,
  56. 'thumbnail': thumbnail,
  57. 'age_limit': self._family_friendly_search(webpage),
  58. 'formats': formats,
  59. }