1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2024-12-02 05:07:55 +01:00

[BrainPOP] Optimize regex and extractor, improve metadata, and add subscription video detection

This commit is contained in:
Nehal Patel 2016-07-12 19:08:03 -05:00
parent b00d17edea
commit 7022e24b1d

View File

@ -2,42 +2,44 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import (
remove_end
)
class BrainPOPIE(InfoExtractor): class BrainPOPIE(InfoExtractor):
_VALID_URL = r'https?:\/\/(?:(.+)\.)?brainpop\.com\/(?P<id>[^\r\n]+)' _VALID_URL = r'https?:\/\/(?:(.+)\.)?brainpop\.com\/[^/]+/[^/]+/(?P<id>[^/?#&]+)'
_TEST = { _TEST = {
'url': 'https://www.brainpop.com/english/freemovies/williamshakespeare/', 'url': 'https://www.brainpop.com/english/freemovies/williamshakespeare/',
'md5': '676d936271b628dc05e4cec377751919', 'md5': '676d936271b628dc05e4cec377751919',
'info_dict': { 'info_dict': {
'id': 'english/freemovies/williamshakespeare/', 'id': '3026',
'display_id': 'williamshakespeare',
'ext': 'mp4', 'ext': 'mp4',
'title': 'William Shakespeare - BrainPOP', 'title': 'William Shakespeare',
'thumbnail': 're:^https?://.*\.png$', '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!', '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): def _real_extract(self, url):
video_id = self._match_id(url) display_id = self._match_id(url)
webpage = self._download_webpage(url, video_id) webpage = self._download_webpage(url, display_id)
self.report_extraction(video_id) content = self._parse_json(self._html_search_regex(r'var content = ([^;]*)', webpage, 'content'), display_id)
if content['category']['unit']['topic']['free'] == 'no':
self.raise_login_required('%s is only available for users with Subscriptions' % display_id)
global_content = self._parse_json(self._html_search_regex(r'var global_content = ([^;]*)', webpage, 'global content').replace("'", '"'), display_id)
cdn_path = global_content.get('cdn_path', 'https://cdn.brainpop.com')
movie_cdn_path = global_content.get('movie_cdn_path', 'https://svideos.brainpop.com')
ec_token = self._html_search_regex(r"ec_token : '([^']*)'", webpage, 'token') ec_token = self._html_search_regex(r"ec_token : '([^']*)'", webpage, 'token')
settings = self._parse_json(self._html_search_regex(r'var settings = ([^;]*)', webpage, 'settings'), video_id) screenshots = content['category']['unit']['topic'].get('screenshots', {})
title = settings['title'] thumbnails = [{'url': cdn_path + screenshot} for screenshot in screenshots]
description = settings['description']
global_content = self._parse_json(self._html_search_regex(r'var global_content = ([^;]*)', webpage, 'global content').replace("'", '"'), video_id)
cdn_path = global_content['cdn_path']
movie_cdn_path = global_content['movie_cdn_path']
content = self._parse_json(self._html_search_regex(r'var content = ([^;]*)', webpage, 'content'), video_id)
movies = content['category']['unit']['topic']['movies'] movies = content['category']['unit']['topic']['movies']
screenshots = content['category']['unit']['topic']['screenshots']
formats = [] formats = []
formats.append({ formats.append({
'url': movie_cdn_path + movies['mp4'] + '?' + ec_token, 'url': movie_cdn_path + movies['mp4'] + '?' + ec_token,
@ -51,16 +53,13 @@ class BrainPOPIE(InfoExtractor):
}) })
self._sort_formats(formats) self._sort_formats(formats)
thumbnails = [] settings = self._parse_json(self._html_search_regex(r'var settings = ([^;]*)', webpage, 'settings'), display_id)
for (i, screenshot) in enumerate(screenshots):
thumbnails.append({
'url': cdn_path + screenshot,
})
return { return {
'id': video_id, 'id': content['category']['unit']['topic']['EntryID'],
'title': title, 'display_id': display_id,
'formats': formats, 'title': remove_end(settings['title'], ' - BrainPOP'),
'description': settings['description'],
'thumbnails': thumbnails, 'thumbnails': thumbnails,
'description': description, 'formats': formats,
} }