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