From 45abe2051dafed38f4c8319a7bfe9bdbf3e372b4 Mon Sep 17 00:00:00 2001 From: Nehal Patel Date: Wed, 6 Jul 2016 23:36:29 -0500 Subject: [PATCH] [BrainPOP] Add new extractor --- youtube_dl/extractor/brainpop.py | 47 ++++++++++++++++++++++++++++++ youtube_dl/extractor/extractors.py | 1 + 2 files changed, 48 insertions(+) create mode 100644 youtube_dl/extractor/brainpop.py diff --git a/youtube_dl/extractor/brainpop.py b/youtube_dl/extractor/brainpop.py new file mode 100644 index 000000000..6b3dd6a92 --- /dev/null +++ b/youtube_dl/extractor/brainpop.py @@ -0,0 +1,47 @@ +# coding: utf-8 +from __future__ import unicode_literals + +from .common import InfoExtractor + + +class BrainPOPIE(InfoExtractor): + _VALID_URL = r'https?:\/\/(?:(.+)\.)?brainpop\.com\/(?P[^\r\n]+)' + _TEST = { + 'url': 'https://www.brainpop.com/english/freemovies/williamshakespeare/', + 'md5': '676d936271b628dc05e4cec377751919', + 'info_dict': { + 'id': 'english/freemovies/williamshakespeare/', + 'ext': 'mp4', + 'title': 'William Shakespeare - BrainPOP', + 'thumbnail': 're:^https?://.*\.png$', + 'description': 'He could do comedies, tragedies, histories and poetry. Learn about the greatest playwright in the history of the English language!', + } + } + + def _real_extract(self, url): + video_id = self._match_id(url) + webpage = self._download_webpage(url, video_id) + + self.report_extraction(video_id) + + ec_token = self._html_search_regex(r'ec_token : \'(.+)\'', webpage, "token") + movie_cdn_path = self._html_search_regex(r'movie_cdn_path : \'(.+)\'', webpage, "cdn path") + mp4 = self._html_search_regex(r'mp4":"([^"]*)', webpage, "mp4") + + url = movie_cdn_path + mp4.replace("\\", "") + "?" + ec_token + + title = self._html_search_regex(r'type":"Movie","name":"([^"]*)"', webpage, "title") + + thumbnail_cdn = self._html_search_regex(r"'cdn_path' : '([^']*)'", webpage, "thumbnail cdn") + thumbnail_image = self._html_search_regex(r'type":"Movie","name":"[^"]*","image":"([^"]*)"', webpage, "thumbnail") + thumbnail = thumbnail_cdn + thumbnail_image.replace("\\", "") + + description = self._html_search_regex(r'type":"Movie","name":"[^"]*","image":"[^"]*","description":"([^"]*)"', webpage, "description") + + return { + 'id': video_id, + 'url': url, + 'title': title, + 'thumbnail': thumbnail, + 'description': description, + } diff --git a/youtube_dl/extractor/extractors.py b/youtube_dl/extractor/extractors.py index 4e2a2f2e9..cc45f5c23 100644 --- a/youtube_dl/extractor/extractors.py +++ b/youtube_dl/extractor/extractors.py @@ -93,6 +93,7 @@ from .bokecc import BokeCCIE from .bpb import BpbIE from .br import BRIE from .bravotv import BravoTVIE +from .brainpop import BrainPOPIE from .breakcom import BreakIE from .brightcove import ( BrightcoveLegacyIE,