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.

59 lines
1.8 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. },
  19. # 'skip': 'Extremely unreliable',
  20. }
  21. def _real_extract(self, url):
  22. m = re.match(self._VALID_URL, url)
  23. video_id = m.group('id')
  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 = re.findall(r'fileList\[[0-9]+\]\s*=\s*"([^"]+)"', webpage)
  31. for i, video_url in enumerate(video_urls):
  32. req = HEADRequest(video_url)
  33. res = self._request_webpage(
  34. req, video_id, note=u'Testing video URL %d' % i, errnote=False)
  35. if res:
  36. break
  37. else:
  38. raise ExtractorError(u'No working video URLs found')
  39. title = self._search_regex(r'\s+title:\s*"([^"]+)"', webpage, u'title')
  40. thumbnail = self._search_regex(
  41. r'\s+image:\s*"([^"]+)"', webpage, u'thumbnail', fatal=False)
  42. return {
  43. 'id': video_id,
  44. 'title': title,
  45. 'url': video_url,
  46. 'ext': 'mp4',
  47. 'thumbnail': thumbnail,
  48. }