funnyordie.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. _TESTS = [{
  8. 'url': 'http://www.funnyordie.com/videos/0732f586d7/heart-shaped-box-literal-video-version',
  9. 'md5': 'f647e9e90064b53b6e046e75d0241fbd',
  10. 'info_dict': {
  11. 'id': '0732f586d7',
  12. 'ext': 'mp4',
  13. 'title': 'Heart-Shaped Box: Literal Video Version',
  14. 'description': 'md5:ea09a01bc9a1c46d9ab696c01747c338',
  15. 'thumbnail': 're:^http:.*\.jpg$',
  16. },
  17. }, {
  18. 'url': 'http://www.funnyordie.com/embed/e402820827',
  19. 'md5': '0e0c5a7bf45c52b95cd16aa7f28be0b6',
  20. 'info_dict': {
  21. 'id': 'e402820827',
  22. 'ext': 'mp4',
  23. 'title': 'Please Use This Song (Jon Lajoie)',
  24. 'description': 'md5:2ed27d364f5a805a6dba199faaf6681d',
  25. 'thumbnail': 're:^http:.*\.jpg$',
  26. },
  27. }]
  28. def _real_extract(self, url):
  29. mobj = re.match(self._VALID_URL, url)
  30. video_id = mobj.group('id')
  31. webpage = self._download_webpage(url, video_id)
  32. video_url = self._search_regex(
  33. [r'type="video/mp4" src="(.*?)"', r'src="([^>]*?)" type=\'video/mp4\''],
  34. webpage, 'video URL', flags=re.DOTALL)
  35. post_json = self._search_regex(
  36. r'fb_post\s*=\s*(\{.*?\});', webpage, 'post details')
  37. post = json.loads(post_json)
  38. return {
  39. 'id': video_id,
  40. 'url': video_url,
  41. 'ext': 'mp4',
  42. 'title': post['name'],
  43. 'description': post.get('description'),
  44. 'thumbnail': post.get('picture'),
  45. }