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.

55 lines
1.8 KiB

  1. import json
  2. import re
  3. from .common import InfoExtractor
  4. class ViddlerIE(InfoExtractor):
  5. _VALID_URL = r'(?P<domain>https?://(?:www\.)?viddler\.com)/(?:v|embed|player)/(?P<id>[a-z0-9]+)'
  6. _TEST = {
  7. u"url": u"http://www.viddler.com/v/43903784",
  8. u'file': u'43903784.mp4',
  9. u'md5': u'fbbaedf7813e514eb7ca30410f439ac9',
  10. u'info_dict': {
  11. u"title": u"Video Made Easy",
  12. u"uploader": u"viddler",
  13. u"duration": 100.89,
  14. }
  15. }
  16. def _real_extract(self, url):
  17. mobj = re.match(self._VALID_URL, url)
  18. video_id = mobj.group('id')
  19. embed_url = mobj.group('domain') + u'/embed/' + video_id
  20. webpage = self._download_webpage(embed_url, video_id)
  21. video_sources_code = self._search_regex(
  22. r"(?ms)sources\s*:\s*(\{.*?\})", webpage, u'video URLs')
  23. video_sources = json.loads(video_sources_code.replace("'", '"'))
  24. formats = [{
  25. 'url': video_url,
  26. 'format': format_id,
  27. } for video_url, format_id in video_sources.items()]
  28. title = self._html_search_regex(
  29. r"title\s*:\s*'([^']*)'", webpage, u'title')
  30. uploader = self._html_search_regex(
  31. r"authorName\s*:\s*'([^']*)'", webpage, u'uploader', fatal=False)
  32. duration_s = self._html_search_regex(
  33. r"duration\s*:\s*([0-9.]*)", webpage, u'duration', fatal=False)
  34. duration = float(duration_s) if duration_s else None
  35. thumbnail = self._html_search_regex(
  36. r"thumbnail\s*:\s*'([^']*)'",
  37. webpage, u'thumbnail', fatal=False)
  38. return {
  39. '_type': 'video',
  40. 'id': video_id,
  41. 'title': title,
  42. 'thumbnail': thumbnail,
  43. 'uploader': uploader,
  44. 'duration': duration,
  45. 'formats': formats,
  46. }