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.

68 lines
2.5 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. import json
  4. from .common import InfoExtractor
  5. from ..utils import str_to_int
  6. class NineGagIE(InfoExtractor):
  7. IE_NAME = '9gag'
  8. _VALID_URL = r'''(?x)^https?://(?:www\.)?9gag\.tv/
  9. (?:
  10. v/(?P<numid>[0-9]+)|
  11. p/(?P<id>[a-zA-Z0-9]+)/(?P<display_id>[^?#/]+)
  12. )
  13. '''
  14. _TESTS = [{
  15. "url": "http://9gag.tv/v/1912",
  16. "info_dict": {
  17. "id": "1912",
  18. "ext": "mp4",
  19. "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!)",
  20. "title": "\"People Are Awesome 2013\" Is Absolutely Awesome",
  21. "view_count": int,
  22. "thumbnail": "re:^https?://",
  23. },
  24. 'add_ie': ['Youtube']
  25. },
  26. {
  27. 'url': 'http://9gag.tv/p/KklwM/alternate-banned-opening-scene-of-gravity?ref=fsidebar',
  28. 'info_dict': {
  29. 'id': 'KklwM',
  30. 'ext': 'mp4',
  31. 'display_id': 'alternate-banned-opening-scene-of-gravity',
  32. "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.",
  33. 'title': "Banned Opening Scene Of \"Gravity\" That Changes The Whole Movie",
  34. },
  35. }]
  36. def _real_extract(self, url):
  37. mobj = re.match(self._VALID_URL, url)
  38. video_id = mobj.group('numid') or mobj.group('id')
  39. display_id = mobj.group('display_id') or video_id
  40. webpage = self._download_webpage(url, display_id)
  41. post_view = json.loads(self._html_search_regex(
  42. r'var postView = new app\.PostView\({ post: ({.+?}),', webpage, 'post view'))
  43. youtube_id = post_view['videoExternalId']
  44. title = post_view['title']
  45. description = post_view['description']
  46. view_count = str_to_int(post_view['externalView'])
  47. thumbnail = post_view.get('thumbnail_700w') or post_view.get('ogImageUrl') or post_view.get('thumbnail_300w')
  48. return {
  49. '_type': 'url_transparent',
  50. 'url': youtube_id,
  51. 'ie_key': 'Youtube',
  52. 'id': video_id,
  53. 'display_id': display_id,
  54. 'title': title,
  55. 'description': description,
  56. 'view_count': view_count,
  57. 'thumbnail': thumbnail,
  58. }