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.

60 lines
1.9 KiB

10 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. HEADRequest,
  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': '6714e0af7e0d875c5a39c4dc4ab46ad1',
  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. embed_url = ('http://www.aparat.com/video/video/embed/videohash/' +
  28. video_id + '/vt/frame')
  29. webpage = self._download_webpage(embed_url, video_id)
  30. video_urls = [video_url.replace('\\/', '/') for video_url in re.findall(
  31. r'(?:fileList\[[0-9]+\]\s*=|"file"\s*:)\s*"([^"]+)"', webpage)]
  32. for i, video_url in enumerate(video_urls):
  33. req = HEADRequest(video_url)
  34. res = self._request_webpage(
  35. req, video_id, note='Testing video URL %d' % i, errnote=False)
  36. if res:
  37. break
  38. else:
  39. raise ExtractorError('No working video URLs found')
  40. title = self._search_regex(r'\s+title:\s*"([^"]+)"', webpage, 'title')
  41. thumbnail = self._search_regex(
  42. r'image:\s*"([^"]+)"', webpage, 'thumbnail', fatal=False)
  43. return {
  44. 'id': video_id,
  45. 'title': title,
  46. 'url': video_url,
  47. 'ext': 'mp4',
  48. 'thumbnail': thumbnail,
  49. 'age_limit': self._family_friendly_search(webpage),
  50. }