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.

75 lines
2.8 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. class NineGagIE(InfoExtractor):
  5. IE_NAME = '9gag'
  6. _VALID_URL = r'''(?x)^https?://(?:www\.)?9gag\.tv/
  7. (?:
  8. v/(?P<numid>[0-9]+)|
  9. p/(?P<id>[a-zA-Z0-9]+)/(?P<display_id>[^?#/]+)
  10. )
  11. '''
  12. _TESTS = [{
  13. "url": "http://9gag.tv/v/1912",
  14. "info_dict": {
  15. "id": "1912",
  16. "ext": "mp4",
  17. "description": "This 3-minute video will make you smile and then make you feel untalented and insignificant. Anyway, you should share this awesomeness. (Thanks, Dino!)",
  18. "title": "\"People Are Awesome 2013\" Is Absolutely Awesome",
  19. "view_count": int,
  20. "thumbnail": "re:^https?://",
  21. },
  22. 'add_ie': ['Youtube']
  23. },
  24. {
  25. 'url': 'http://9gag.tv/p/KklwM/alternate-banned-opening-scene-of-gravity?ref=fsidebar',
  26. 'info_dict': {
  27. 'id': 'KklwM',
  28. 'ext': 'mp4',
  29. 'display_id': 'alternate-banned-opening-scene-of-gravity',
  30. "description": "While Gravity was a pretty awesome movie already, YouTuber Krishna Shenoi came up with a way to improve upon it, introducing a much better solution to Sandra Bullock's seemingly endless tumble in space. The ending is priceless.",
  31. 'title': "Banned Opening Scene Of \"Gravity\" That Changes The Whole Movie",
  32. },
  33. }]
  34. def _real_extract(self, url):
  35. mobj = re.match(self._VALID_URL, url)
  36. video_id = mobj.group('numid') or mobj.group('id')
  37. display_id = mobj.group('display_id') or video_id
  38. webpage = self._download_webpage(url, display_id)
  39. youtube_id = self._html_search_regex(
  40. r'(?s)id="jsid-video-post-container".*?data-external-id="([^"]+)"',
  41. webpage, 'video ID')
  42. title = self._html_search_regex(
  43. r'(?s)id="jsid-video-post-container".*?data-title="([^"]+)"',
  44. webpage, 'title', default=None)
  45. if not title:
  46. title = self._og_search_title(webpage)
  47. description = self._html_search_regex(
  48. r'(?s)<div class="video-caption">.*?<p>(.*?)</p>', webpage,
  49. 'description', fatal=False)
  50. view_count_str = self._html_search_regex(
  51. r'<p><b>([0-9][0-9,]*)</b> views</p>', webpage, 'view count',
  52. fatal=False)
  53. view_count = (
  54. None if view_count_str is None
  55. else int(view_count_str.replace(',', '')))
  56. return {
  57. '_type': 'url_transparent',
  58. 'url': youtube_id,
  59. 'ie_key': 'Youtube',
  60. 'id': video_id,
  61. 'display_id': display_id,
  62. 'title': title,
  63. 'description': description,
  64. 'view_count': view_count,
  65. 'thumbnail': self._og_search_thumbnail(webpage),
  66. }