Skip to content

Conversation

@zrose584
Copy link
Contributor

No description provided.


info['endcard'] = []
for e in deep_get(player_response, "endscreen", "endscreenRenderer", "elements", default=[]):
e = parse_endcard(e["endscreenElementRenderer"])
Copy link
Owner

Choose a reason for hiding this comment

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

use get function

Comment on lines +573 to +581

def dbg_assert(val, msg):
import os
if val: return

if os.getenv('YT_EXTR_DBG'):
raise AssertionError(msg)
else:
print(f"W: {msg}")
Copy link
Owner

Choose a reason for hiding this comment

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

Remove, don't want to add an ad-hoc debugging framework just for logging unknown ctypes. Especially not one that uses os environment variables instead of the in-built settings. Can think about adding better debugging message handling in youtube-local in the future but not like this

Comment on lines +571 to +581
{% if endcard %}
<details class="endcard-dropdown">
<summary>Endcard</summary>
<div class="dropdown-content">
{% for e in endcard %}
{{ common_elements.item(e) }}
<!-- {{ e }} -->
{% endfor %}
</div>
</details>
{% endif %}
Copy link
Owner

Choose a reason for hiding this comment

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

Why not add the video at the top of the related videos similar to the layout in YouTube's "Watch Next" feature instead of adding another button to the interface?

Comment on lines +755 to +772
def parse_endcard(card):
"""
parses a single endcard into a format that's easier to handle.
from: https://git.gir.st/subscriptionfeed.git/blob/737a2f6f:/app/common/innertube.py#l301
"""
card = card.get('endscreenElementRenderer', card) #only sometimes nested
ctype = card['style'].lower()
if ctype == "video":
if not 'endpoint' in card: return None # title == "This video is unavailable."
video_id = card['endpoint']['watchEndpoint']['videoId']
return {'type': ctype,
'video_id': video_id,
'title': extract_str(card['title']),
'approx_view_count': extract_str(card['metadata']),
'thumbnail': f"/https://i.ytimg.com/vi/{video_id}/default.jpg",
'duration': extract_str(card["thumbnailOverlays"][0]["thumbnailOverlayTimeStatusRenderer"]["text"])
# XXX: no channel name
}
Copy link
Owner

Choose a reason for hiding this comment

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

This code needs to use the deep_get function. Never extract information from json like this: card['endpoint']['watchEndpoint']['videoId'], that will cause the entire code to fail when YouTube changes their json.

Also some lines need to be split up onto multiple lines to not exceed 79 character line limit. And use ', not ", for strings. See https://github.com/user234683/youtube-local/blob/master/HACKING.md for coding guidelines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants