From d2272fcf6e2796583b516f4786733577459dec43 Mon Sep 17 00:00:00 2001 From: felix <m.p.isaev@yandex.com> Date: Mon, 6 Apr 2015 09:54:19 +0200 Subject: [PATCH 1/2] crooksandliars.com extractor --- youtube_dl/extractor/__init__.py | 1 + youtube_dl/extractor/crooksandliars.py | 71 ++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 youtube_dl/extractor/crooksandliars.py diff --git a/youtube_dl/extractor/__init__.py b/youtube_dl/extractor/__init__.py index 7eb9b4fbbb..dc272af826 100644 --- a/youtube_dl/extractor/__init__.py +++ b/youtube_dl/extractor/__init__.py @@ -90,6 +90,7 @@ from .commonmistakes import CommonMistakesIE, UnicodeBOMIE from .condenast import CondeNastIE from .cracked import CrackedIE from .criterion import CriterionIE +from .crooksandliars import CrooksAndLiarsIE, CrooksAndLiarsArticleIE from .crunchyroll import ( CrunchyrollIE, CrunchyrollShowPlaylistIE diff --git a/youtube_dl/extractor/crooksandliars.py b/youtube_dl/extractor/crooksandliars.py new file mode 100644 index 0000000000..afccca3545 --- /dev/null +++ b/youtube_dl/extractor/crooksandliars.py @@ -0,0 +1,71 @@ +from __future__ import unicode_literals + +import json + +from .common import InfoExtractor +from ..utils import ( + mimetype2ext, +) + + +class CrooksAndLiarsIE(InfoExtractor): + _VALID_URL = r'(?:https?:)?//embed.crooksandliars.com/embed/(?P<id>[A-Za-z0-9]+)(?:$|[?#])' + + _TESTS = [{ + 'url': 'https://embed.crooksandliars.com/embed/8RUoRhRi', + 'info_dict': { + 'id': 'https://embed.crooksandliars.com/embed/8RUoRhRi', + 'title': "Fox & Friends Says Protecting Atheists From Discrimination Is Anti-Christian!", + 'description': "Fox News, Fox & Friends Weekend, April 4, 2015. Read more... http://crooksandliars.com/2015/04/fox-friends-says-protecting-atheists", + 'timestamp': 1428207000, + 'thumbnail': '//crooksandliars.com/files/mediaposters/2015/04/31235.jpg?ts=1428207050', + 'uploader': "Heather", + } + }] + + def _real_extract(self, url): + video_id = self._match_id(url) + webpage = self._download_webpage(url, video_id) + + manifest = json.loads(self._html_search_regex(r'var manifest = ({.*?})\n', webpage, 'manifest JSON')) + + formats = [] + for item in manifest['flavors']: + if not item['mime'].startswith('video/'): # XXX: or item['exclude']? + continue + formats.append({ + 'format_id': item['type'], + 'ext': mimetype2ext(item['mime']), + 'url': item['url'], + }) + + # XXX: manifest['url']? + return { + 'url': url, + 'id': video_id, + 'uploader': manifest['author'], + 'title': manifest['title'], + 'description': manifest['description'], + 'thumbnail': manifest['poster'], + 'duration': manifest['duration'], + 'timestamp': int(manifest['created']), + 'formats': formats, + } + +class CrooksAndLiarsArticleIE(InfoExtractor): + _VALID_URL = r'(?:https?:)?//crooksandliars.com/\d+/\d+/(?P<id>[a-z\-]+)(?:/|$)' + + _TESTS = [{ + 'url': 'http://crooksandliars.com/2015/04/fox-friends-says-protecting-atheists', + 'only_matching': True, + }] + + def _real_extract(self, url): + video_id = self._match_id(url) + webpage = self._download_webpage(url, video_id) + player_url = self._proto_relative_url(self._html_search_regex(r'<iframe src="(//embed.crooksandliars.com/.*)"', webpage, 'embedded player')) + + return { + '_type': 'url', + 'url': player_url + } From 6e53c91608d1c43a9fe1614f13a15db74e877a91 Mon Sep 17 00:00:00 2001 From: felix <m.p.isaev@yandex.com> Date: Mon, 6 Apr 2015 10:12:43 +0200 Subject: [PATCH 2/2] [crooksandliars] resolve protocol-relative URLs --- youtube_dl/extractor/crooksandliars.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/youtube_dl/extractor/crooksandliars.py b/youtube_dl/extractor/crooksandliars.py index afccca3545..cee0603f44 100644 --- a/youtube_dl/extractor/crooksandliars.py +++ b/youtube_dl/extractor/crooksandliars.py @@ -18,7 +18,7 @@ class CrooksAndLiarsIE(InfoExtractor): 'title': "Fox & Friends Says Protecting Atheists From Discrimination Is Anti-Christian!", 'description': "Fox News, Fox & Friends Weekend, April 4, 2015. Read more... http://crooksandliars.com/2015/04/fox-friends-says-protecting-atheists", 'timestamp': 1428207000, - 'thumbnail': '//crooksandliars.com/files/mediaposters/2015/04/31235.jpg?ts=1428207050', + 'thumbnail': 'https://crooksandliars.com/files/mediaposters/2015/04/31235.jpg?ts=1428207050', 'uploader': "Heather", } }] @@ -46,7 +46,7 @@ class CrooksAndLiarsIE(InfoExtractor): 'uploader': manifest['author'], 'title': manifest['title'], 'description': manifest['description'], - 'thumbnail': manifest['poster'], + 'thumbnail': self._proto_relative_url(manifest['poster']), 'duration': manifest['duration'], 'timestamp': int(manifest['created']), 'formats': formats,