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.

56 lines
1.8 KiB

  1. #coding: utf-8
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. HEADRequest,
  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. u'url': u'http://www.aparat.com/v/wP8On',
  12. u'file': u'wP8On.mp4',
  13. u'md5': u'6714e0af7e0d875c5a39c4dc4ab46ad1',
  14. u'info_dict': {
  15. u"title": u"تیم گلکسی 11 - زومیت",
  16. },
  17. #u'skip': u'Extremely unreliable',
  18. }
  19. def _real_extract(self, url):
  20. m = re.match(self._VALID_URL, url)
  21. video_id = m.group('id')
  22. # Note: There is an easier-to-parse configuration at
  23. # http://www.aparat.com/video/video/config/videohash/%video_id
  24. # but the URL in there does not work
  25. embed_url = (u'http://www.aparat.com/video/video/embed/videohash/' +
  26. video_id + u'/vt/frame')
  27. webpage = self._download_webpage(embed_url, video_id)
  28. video_urls = re.findall(r'fileList\[[0-9]+\]\s*=\s*"([^"]+)"', webpage)
  29. for i, video_url in enumerate(video_urls):
  30. req = HEADRequest(video_url)
  31. res = self._request_webpage(
  32. req, video_id, note=u'Testing video URL %d' % i, errnote=False)
  33. if res:
  34. break
  35. else:
  36. raise ExtractorError(u'No working video URLs found')
  37. title = self._search_regex(r'\s+title:\s*"([^"]+)"', webpage, u'title')
  38. thumbnail = self._search_regex(
  39. r'\s+image:\s*"([^"]+)"', webpage, u'thumbnail', fatal=False)
  40. return {
  41. 'id': video_id,
  42. 'title': title,
  43. 'url': video_url,
  44. 'ext': 'mp4',
  45. 'thumbnail': thumbnail,
  46. }