diff options
author | Philipp Hagemeister <phihag@phihag.de> | 2013-12-05 14:29:08 +0100 |
---|---|---|
committer | Philipp Hagemeister <phihag@phihag.de> | 2013-12-05 14:29:08 +0100 |
commit | 7fc3fa0545f8a07414e8c97be9862a3c2f79bb98 (patch) | |
tree | 85de96d6f0276e9663ea96768a95991b3f8d6a28 /youtube_dl/extractor | |
parent | 29030c0a4c2f4dded5a310add940aae0791f9d73 (diff) |
[9gag] Add extractor
Diffstat (limited to 'youtube_dl/extractor')
-rw-r--r-- | youtube_dl/extractor/__init__.py | 1 | ||||
-rw-r--r-- | youtube_dl/extractor/ninegag.py | 41 |
2 files changed, 42 insertions, 0 deletions
diff --git a/youtube_dl/extractor/__init__.py b/youtube_dl/extractor/__init__.py index bd996483b..a77e98d49 100644 --- a/youtube_dl/extractor/__init__.py +++ b/youtube_dl/extractor/__init__.py @@ -102,6 +102,7 @@ from .nbc import NBCNewsIE from .newgrounds import NewgroundsIE from .nhl import NHLIE, NHLVideocenterIE from .niconico import NiconicoIE +from .ninegag import NineGagIE from .nowvideo import NowVideoIE from .ooyala import OoyalaIE from .orf import ORFIE diff --git a/youtube_dl/extractor/ninegag.py b/youtube_dl/extractor/ninegag.py new file mode 100644 index 000000000..cc00ffbcc --- /dev/null +++ b/youtube_dl/extractor/ninegag.py @@ -0,0 +1,41 @@ +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 = { + u"url": u"http://9gag.tv/v/1912", + u"file": u"1912.mp4", + u"info_dict": { + 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!)", + u"title": u"\"People Are Awesome 2013\" Is Absolutely Awesome" + }, + u'add_ie': [u'Youtube'] + } + + 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* + data-video-meta="([^"]+)"''', webpage, u'video metadata') + + 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']), + 'thumbnail': data['thumbnail_url'], + } |