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.

53 lines
1.8 KiB

  1. from __future__ import unicode_literals
  2. import json
  3. import re
  4. from .common import InfoExtractor
  5. class FunnyOrDieIE(InfoExtractor):
  6. _VALID_URL = r'https?://(?:www\.)?funnyordie\.com/(?P<type>embed|videos)/(?P<id>[0-9a-f]+)(?:$|[?#/])'
  7. _TEST = {
  8. 'url': 'http://www.funnyordie.com/videos/0732f586d7/heart-shaped-box-literal-video-version',
  9. 'file': '0732f586d7.mp4',
  10. 'md5': 'f647e9e90064b53b6e046e75d0241fbd',
  11. 'info_dict': {
  12. 'description': ('Lyrics changed to match the video. Spoken cameo '
  13. 'by Obscurus Lupa (from ThatGuyWithTheGlasses.com). Based on a '
  14. 'concept by Dustin McLean (DustFilms.com). Performed, edited, '
  15. 'and written by David A. Scott.'),
  16. 'title': 'Heart-Shaped Box: Literal Video Version',
  17. },
  18. }
  19. def _real_extract(self, url):
  20. mobj = re.match(self._VALID_URL, url)
  21. video_id = mobj.group('id')
  22. webpage = self._download_webpage(url, video_id)
  23. video_url = self._search_regex(
  24. [r'type="video/mp4" src="(.*?)"', r'src="([^>]*?)" type=\'video/mp4\''],
  25. webpage, 'video URL', flags=re.DOTALL)
  26. if mobj.group('type') == 'embed':
  27. post_json = self._search_regex(
  28. r'fb_post\s*=\s*(\{.*?\});', webpage, 'post details')
  29. post = json.loads(post_json)
  30. title = post['name']
  31. description = post.get('description')
  32. thumbnail = post.get('picture')
  33. else:
  34. title = self._og_search_title(webpage)
  35. description = self._og_search_description(webpage)
  36. thumbnail = None
  37. return {
  38. 'id': video_id,
  39. 'url': video_url,
  40. 'ext': 'mp4',
  41. 'title': title,
  42. 'description': description,
  43. 'thumbnail': thumbnail,
  44. }