-
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
[archiveorg] Fix extraction #23827
[archiveorg] Fix extraction #23827
Changes from 1 commit
8df0c2c
e910f49
b98d1c0
1326a5a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,9 +40,12 @@ def _real_extract(self, url): | |
video_id = self._match_id(url) | ||
webpage = self._download_webpage( | ||
'http://archive.org/embed/' + video_id, video_id) | ||
input_element_with_playlist = self._search_regex( | ||
r'(<\s*input.*\s*class\s*=\s*[\'"].*\s*js-play8-playlist\s*.*[\'"]\s*.*>)', | ||
webpage, 'jwplayer playlist') | ||
jwplayer_playlist = self._parse_json(self._search_regex( | ||
r"(?s)Play\('[^']+'\s*,\s*(\[.+\])\s*,\s*{.*?}\)", | ||
webpage, 'jwplayer playlist'), video_id) | ||
r'.*\s+value\s*=\s*[\'"](.+)[\'"][\s/]', | ||
input_element_with_playlist, 'playlist data'), video_id) | ||
info = self._parse_jwplayer_data( | ||
{'playlist': jwplayer_playlist}, video_id, base_url=url) | ||
|
||
|
@@ -52,7 +55,7 @@ def get_optional(metadata, field): | |
metadata = self._download_json( | ||
'http://archive.org/details/' + video_id, video_id, query={ | ||
'output': 'json', | ||
})['metadata'] | ||
}).get('metadata', {}) | ||
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. Point of this? 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. The idea is to make the extraction more resilient against website changes. With metadata being optional for downloading videos, it's probably better not to crash if the metadata element changes its name. 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. This is not enough. If you reconsider this optional then you must also:
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. You are right. Thanks. Commit 1326a5a fixes this by setting |
||
info.update({ | ||
'title': get_optional(metadata, 'title') or info.get('title'), | ||
'description': clean_html(get_optional(metadata, 'description')), | ||
|
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.
extract_attributes
.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.
Thanks for the pointer. I changed the code to use
extract_attributes()
in commit e910f49.It was still bugging me that I couldn't use
get_element_by_class()
in the line before as it only returns the content of the element and not the element (as the name of the function indicates). So I changedget_element_by_class()
(and it's associated functions) in commit b98d1c0 to accept an optionalinclude_tag
parameter. By default it's set toFalse
. So no existing code will be affected by it.This should prove useful in the future and make those functions more intuitive to use.
I also added tests to
test_utils.py
. While doing so I noticed thatget_element_by_class()
didn't work for class names starting with a hyphen. I fixed that, too.