-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BrainPOP] Add new extractor (Closes #10000) #10025
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
45abe20
[BrainPOP] Add new extractor
nehalvpatel f56a9db
[BrainPOP] Clean up code and account for non-mandatory fields
nehalvpatel b00d17e
[BrainPOP] Switch from regex to parsing JSON and include both resolut…
nehalvpatel 7022e24
[BrainPOP] Optimize regex and extractor, improve metadata, and add su…
nehalvpatel f02b57d
[BrainPOP] Trim code and make optional metadata less brittle
nehalvpatel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# coding: utf-8 | ||
from __future__ import unicode_literals | ||
|
||
from .common import InfoExtractor | ||
from ..utils import ( | ||
remove_end | ||
) | ||
|
||
|
||
class BrainPOPIE(InfoExtractor): | ||
_VALID_URL = r'https?:\/\/(?:(.+)\.)?brainpop\.com\/[^/]+/[^/]+/(?P<id>[^/?#&]+)' | ||
_TEST = { | ||
'url': 'https://www.brainpop.com/english/freemovies/williamshakespeare/', | ||
'md5': '676d936271b628dc05e4cec377751919', | ||
'info_dict': { | ||
'id': '3026', | ||
'display_id': 'williamshakespeare', | ||
'ext': 'mp4', | ||
'title': 'William Shakespeare', | ||
'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): | ||
display_id = self._match_id(url) | ||
webpage = self._download_webpage(url, display_id) | ||
|
||
content = self._parse_json(self._html_search_regex(r'var content = ([^;]*)', webpage, 'content JSON'), display_id) | ||
topic = content['category']['unit']['topic'] | ||
|
||
if 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 JSON').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') | ||
|
||
thumbnails = [{'url': cdn_path + screenshot} for screenshot in topic.get('screenshots', {})] | ||
|
||
movies = topic['movies'] | ||
formats = [] | ||
formats.append({ | ||
'url': movie_cdn_path + movies['mp4'] + '?' + ec_token, | ||
'height': 768, | ||
'width': 768, | ||
}) | ||
formats.append({ | ||
'url': movie_cdn_path + movies['mp4_small'] + '?' + ec_token, | ||
'height': 480, | ||
'width': 480, | ||
}) | ||
self._sort_formats(formats) | ||
|
||
settings = self._parse_json(self._html_search_regex(r'var settings = ([^;]*)', webpage, 'settings JSON', '{}'), display_id) | ||
|
||
return { | ||
'id': topic['EntryID'], | ||
'display_id': display_id, | ||
'title': remove_end(settings.get('title', display_id), ' - BrainPOP'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also extract title from |
||
'description': settings.get('description', ''), | ||
'thumbnails': thumbnails, | ||
'formats': formats, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
title
should be mandatoryThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Such a pattern is OK if
title
is missing insettings
. @nehalvpatel Do you have an example?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
title
can be extracted from<title>(.*)</title>
also. One of them should be fatal, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either way is fine. In general
<title>
is better than extracting from embedded data as the former is less likely to change. If there's an example that<title>
orsettings['title']
is missing, a fallback should be provided, otherwise the extraction should be fatal.