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.

57 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. 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. embed_url = ('http://www.aparat.com/video/video/embed/videohash/' +
  27. video_id + '/vt/frame')
  28. webpage = self._download_webpage(embed_url, video_id)
  29. video_urls = re.findall(r'fileList\[[0-9]+\]\s*=\s*"([^"]+)"', webpage)
  30. for i, video_url in enumerate(video_urls):
  31. req = HEADRequest(video_url)
  32. res = self._request_webpage(
  33. req, video_id, note='Testing video URL %d' % i, errnote=False)
  34. if res:
  35. break
  36. else:
  37. raise ExtractorError('No working video URLs found')
  38. title = self._search_regex(r'\s+title:\s*"([^"]+)"', webpage, 'title')
  39. thumbnail = self._search_regex(
  40. r'\s+image:\s*"([^"]+)"', webpage, 'thumbnail', fatal=False)
  41. return {
  42. 'id': video_id,
  43. 'title': title,
  44. 'url': video_url,
  45. 'ext': 'mp4',
  46. 'thumbnail': thumbnail,
  47. }