1
0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2024-11-16 12:03:28 +01:00
youtube-dl/youtube_dl/extractor/ninegag.py

46 lines
1.5 KiB
Python
Raw Normal View History

2014-01-28 18:55:06 +01:00
from __future__ import unicode_literals
2013-12-05 14:29:08 +01:00
import json
import re
from .common import InfoExtractor
class NineGagIE(InfoExtractor):
IE_NAME = '9gag'
_VALID_URL = r'^https?://(?:www\.)?9gag\.tv/v/(?P<id>[0-9]+)'
_TEST = {
2014-01-28 18:55:06 +01:00
"url": "http://9gag.tv/v/1912",
"file": "1912.mp4",
"info_dict": {
"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!)",
"title": "\"People Are Awesome 2013\" Is Absolutely Awesome"
2013-12-05 14:29:08 +01:00
},
2014-01-28 18:55:06 +01:00
'add_ie': ['Youtube']
2013-12-05 14:29:08 +01:00
}
def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('id')
webpage = self._download_webpage(url, video_id)
data_json = self._html_search_regex(r'''(?x)
<div\s*id="tv-video"\s*data-video-source="youtube"\s*
2014-01-28 18:55:06 +01:00
data-video-meta="([^"]+)"''', webpage, 'video metadata')
2013-12-05 14:29:08 +01:00
data = json.loads(data_json)
return {
'_type': 'url_transparent',
'url': data['youtubeVideoId'],
'ie_key': 'Youtube',
'id': video_id,
'title': data['title'],
'description': data['description'],
'view_count': int(data['view_count']),
2013-12-05 18:29:07 +01:00
'like_count': int(data['statistic']['like']),
'dislike_count': int(data['statistic']['dislike']),
2013-12-05 14:29:08 +01:00
'thumbnail': data['thumbnail_url'],
}