Skip to content
This repository has been archived by the owner on Oct 25, 2020. It is now read-only.

Fixed search for itags and urls according to YouTube API Pattern #41

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

setup(
name="yturl",
version="2.0.2",
version="2.0.3",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't bump the version until the release tests pass, which are not run here. Please remove this. :-)

python_requires=">=3.5",
description="Gets direct media URLs to YouTube media",
long_description=README,
Expand Down
12 changes: 9 additions & 3 deletions yturl.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,15 @@ def itags_for_video(video_id):
try:
streams = api_response["url_encoded_fmt_stream_map"].split(",")
except KeyError:
raise NotImplementedError(
"Live and streaming videos are unsupported."
) from None
try:
import json
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't import inline, do it with the others.

return collections.OrderedDict([(i['itag'], i['url']) for i in
json.loads(api_response['player_response'])['streamingData'][
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure this isn't black formatted, so CI won't be happy :-)

'formats']])
except:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use bare except, check the exceptions you actually care about. For example, this will even catch keyboard interrupts...

raise NotImplementedError(
"Live and streaming videos are unsupported."
) from None

videos = [parse_qs_single(stream) for stream in streams]
return collections.OrderedDict((vid["itag"], vid["url"]) for vid in videos)
Expand Down