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.

53 lines
1.8 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. "view_count": int,
  15. "thumbnail": "re:^https?://",
  16. },
  17. 'add_ie': ['Youtube']
  18. }
  19. def _real_extract(self, url):
  20. mobj = re.match(self._VALID_URL, url)
  21. video_id = mobj.group('id')
  22. webpage = self._download_webpage(url, video_id)
  23. youtube_id = self._html_search_regex(
  24. r'(?s)id="jsid-video-post-container".*?data-external-id="([^"]+)"',
  25. webpage, 'video ID')
  26. description = self._html_search_regex(
  27. r'(?s)<div class="video-caption">.*?<p>(.*?)</p>', webpage,
  28. 'description', fatal=False)
  29. view_count_str = self._html_search_regex(
  30. r'<p><b>([0-9][0-9,]*)</b> views</p>', webpage, 'view count',
  31. fatal=False)
  32. view_count = (
  33. None if view_count_str is None
  34. else int(view_count_str.replace(',', '')))
  35. return {
  36. '_type': 'url_transparent',
  37. 'url': youtube_id,
  38. 'ie_key': 'Youtube',
  39. 'id': video_id,
  40. 'title': self._og_search_title(webpage),
  41. 'description': description,
  42. 'view_count': view_count,
  43. 'thumbnail': self._og_search_thumbnail(webpage),
  44. }