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.

70 lines
2.4 KiB

  1. from __future__ import unicode_literals
  2. import json
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import ExtractorError
  6. class FunnyOrDieIE(InfoExtractor):
  7. _VALID_URL = r'https?://(?:www\.)?funnyordie\.com/(?P<type>embed|videos)/(?P<id>[0-9a-f]+)(?:$|[?#/])'
  8. _TESTS = [{
  9. 'url': 'http://www.funnyordie.com/videos/0732f586d7/heart-shaped-box-literal-video-version',
  10. 'md5': 'bcd81e0c4f26189ee09be362ad6e6ba9',
  11. 'info_dict': {
  12. 'id': '0732f586d7',
  13. 'ext': 'mp4',
  14. 'title': 'Heart-Shaped Box: Literal Video Version',
  15. 'description': 'md5:ea09a01bc9a1c46d9ab696c01747c338',
  16. 'thumbnail': 're:^http:.*\.jpg$',
  17. },
  18. }, {
  19. 'url': 'http://www.funnyordie.com/embed/e402820827',
  20. 'md5': '29f4c5e5a61ca39dfd7e8348a75d0aad',
  21. 'info_dict': {
  22. 'id': 'e402820827',
  23. 'ext': 'mp4',
  24. 'title': 'Please Use This Song (Jon Lajoie)',
  25. 'description': 'Please use this to sell something. www.jonlajoie.com',
  26. 'thumbnail': 're:^http:.*\.jpg$',
  27. },
  28. }]
  29. def _real_extract(self, url):
  30. mobj = re.match(self._VALID_URL, url)
  31. video_id = mobj.group('id')
  32. webpage = self._download_webpage(url, video_id)
  33. links = re.findall(r'<source src="([^"]+/v)[^"]+\.([^"]+)" type=\'video', webpage)
  34. if not links:
  35. raise ExtractorError('No media links available for %s' % video_id)
  36. links.sort(key=lambda link: 1 if link[1] == 'mp4' else 0)
  37. bitrates = self._html_search_regex(r'<source src="[^"]+/v,((?:\d+,)+)\.mp4\.csmil', webpage, 'video bitrates')
  38. bitrates = [int(b) for b in bitrates.rstrip(',').split(',')]
  39. bitrates.sort()
  40. formats = []
  41. for bitrate in bitrates:
  42. for link in links:
  43. formats.append({
  44. 'url': '%s%d.%s' % (link[0], bitrate, link[1]),
  45. 'format_id': '%s-%d' % (link[1], bitrate),
  46. 'vbr': bitrate,
  47. })
  48. post_json = self._search_regex(
  49. r'fb_post\s*=\s*(\{.*?\});', webpage, 'post details')
  50. post = json.loads(post_json)
  51. return {
  52. 'id': video_id,
  53. 'title': post['name'],
  54. 'description': post.get('description'),
  55. 'thumbnail': post.get('picture'),
  56. 'formats': formats,
  57. }