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.

73 lines
2.8 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. 'uploader_id': 'UCdEH6EjDKwtTe-sO2f0_1XA',
  22. 'uploader': 'CompilationChannel',
  23. 'upload_date': '20131110',
  24. "view_count": int,
  25. "thumbnail": "re:^https?://",
  26. },
  27. 'add_ie': ['Youtube']
  28. }, {
  29. 'url': 'http://9gag.tv/p/KklwM/alternate-banned-opening-scene-of-gravity?ref=fsidebar',
  30. 'info_dict': {
  31. 'id': 'KklwM',
  32. 'ext': 'mp4',
  33. 'display_id': 'alternate-banned-opening-scene-of-gravity',
  34. "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.",
  35. 'title': "Banned Opening Scene Of \"Gravity\" That Changes The Whole Movie",
  36. 'uploader': 'Krishna Shenoi',
  37. 'upload_date': '20140401',
  38. 'uploader_id': 'krishnashenoi93',
  39. },
  40. }]
  41. def _real_extract(self, url):
  42. mobj = re.match(self._VALID_URL, url)
  43. video_id = mobj.group('numid') or mobj.group('id')
  44. display_id = mobj.group('display_id') or video_id
  45. webpage = self._download_webpage(url, display_id)
  46. post_view = json.loads(self._html_search_regex(
  47. r'var postView = new app\.PostView\({\s*post:\s*({.+?}),\s*posts:\s*prefetchedCurrentPost', webpage, 'post view'))
  48. youtube_id = post_view['videoExternalId']
  49. title = post_view['title']
  50. description = post_view['description']
  51. view_count = str_to_int(post_view['externalView'])
  52. thumbnail = post_view.get('thumbnail_700w') or post_view.get('ogImageUrl') or post_view.get('thumbnail_300w')
  53. return {
  54. '_type': 'url_transparent',
  55. 'url': youtube_id,
  56. 'ie_key': 'Youtube',
  57. 'id': video_id,
  58. 'display_id': display_id,
  59. 'title': title,
  60. 'description': description,
  61. 'view_count': view_count,
  62. 'thumbnail': thumbnail,
  63. }