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.

43 lines
1.4 KiB

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