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