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.

45 lines
1.5 KiB

  1. from __future__ import unicode_literals
  2. import json
  3. import re
  4. from .common import InfoExtractor
  5. class NineGagIE(InfoExtractor):
  6. IE_NAME = '9gag'
  7. _VALID_URL = r'^https?://(?:www\.)?9gag\.tv/v/(?P<id>[0-9]+)'
  8. _TEST = {
  9. "url": "http://9gag.tv/v/1912",
  10. "file": "1912.mp4",
  11. "info_dict": {
  12. "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!)",
  13. "title": "\"People Are Awesome 2013\" Is Absolutely Awesome"
  14. },
  15. 'add_ie': ['Youtube']
  16. }
  17. def _real_extract(self, url):
  18. mobj = re.match(self._VALID_URL, url)
  19. video_id = mobj.group('id')
  20. webpage = self._download_webpage(url, video_id)
  21. data_json = self._html_search_regex(r'''(?x)
  22. <div\s*id="tv-video"\s*data-video-source="youtube"\s*
  23. data-video-meta="([^"]+)"''', webpage, 'video metadata')
  24. data = json.loads(data_json)
  25. return {
  26. '_type': 'url_transparent',
  27. 'url': data['youtubeVideoId'],
  28. 'ie_key': 'Youtube',
  29. 'id': video_id,
  30. 'title': data['title'],
  31. 'description': data['description'],
  32. 'view_count': int(data['view_count']),
  33. 'like_count': int(data['statistic']['like']),
  34. 'dislike_count': int(data['statistic']['dislike']),
  35. 'thumbnail': data['thumbnail_url'],
  36. }