Skip to content
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

Integrate the first party YouTube client into Via #1103

Closed
wants to merge 9 commits into from

Conversation

jon-betts
Copy link
Contributor

@jon-betts jon-betts commented Jul 19, 2023

Requires:

Review notes

  • This includes an enormous commit which is mostly just format changes in the requirements
  • This is looking up a matching transcript based on a list of preferences
    • I don't think we should do this for LMS
    • I think the LMS should either do this for us, or make the user pick

Testing notes

# By default, the mock reports that URLs are not YouTube URLs.
youtube_service.get_video_id.return_value = None

return youtube_service
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This violated the principal of least surprise for me. This is only required in one test, so I moved it there.

"api.youtube.transcript",
video_id=youtube_service.get_video_id.return_value,
transcript_id="en.a",
)
Copy link
Contributor Author

@jon-betts jon-betts Jul 19, 2023

Choose a reason for hiding this comment

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

These tests are very intense. I really don't think we should be doing this anyway here which might reduce this effect


if not youtube_service.enabled:
raise HTTPUnauthorized()

video_id = youtube_service.get_video_id(url)
video_url = youtube_service.canonical_video_url(video_id)
video_title = youtube_service.get_video_title(video_id)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think part of the reason these tests aren't as nice as they could be is we have too many atomic calls.

The new method returns a single object with all these items inside it. It would be good to unify these.

if not video_id:
raise BadURL(f"Unsupported video URL: {url}", url=url)

_, client_config = Configuration.extract_from_params(kwargs)
video_url = youtube_service.canonical_video_url(video_id)
video_title = youtube_service.get_video_title(video_id)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved these down, because we can early return if the video id isn't valid. Rather than doing lots of strange stuff.

return transcript_id

# Then look up a transcript matching our preferences
video = youtube_service.get_video_info(video_url=url)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could look this up in the parent, but I chose to keep it separate for now.

We could look to unify the look up with a call like:

youtube_service.get_video_info(video_url=url, get_captions=True)

Where we could use V3 stuff if get_captions=False or the V1 stuff if it's true etc.

@jon-betts jon-betts force-pushed the yt-cc-integrate branch 2 times, most recently from 51ae7a8 to 6f8b07a Compare July 19, 2023 19:42
@jon-betts jon-betts changed the base branch from yt-cc-client to recompile-reqs July 19, 2023 19:43
@jon-betts jon-betts force-pushed the yt-cc-integrate branch 3 times, most recently from 87ed39a to 6458ef0 Compare July 20, 2023 17:13
@jon-betts jon-betts changed the base branch from recompile-reqs to yt-cc-client July 20, 2023 18:21
@jon-betts jon-betts added tech debt and removed wip labels Jul 20, 2023
@seanh seanh self-assigned this Jul 21, 2023
@jon-betts jon-betts requested a review from seanh July 24, 2023 15:15
@seanh seanh added the blocked label Jul 28, 2023
@seanh
Copy link
Contributor

seanh commented Jul 28, 2023

Labeling this as blocked just because it's waiting for me to get some more urgent PRs done before I can review this. I promise I'm working my way round to reviewing this ASAP!

Copy link
Contributor

@seanh seanh left a comment

Choose a reason for hiding this comment

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

Not a proper review yet but just as a first-pass: I think the video_url argument to get_video_info() can be removed as it's unused, and the via.video.lang query param should be removed as nothing's going to be using it

Comment on lines +90 to +92
def get_video_info(self, video_id=None, video_url=None) -> Video:
if video_url:
video_id = self.get_video_id(video_url)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def get_video_info(self, video_id=None, video_url=None) -> Video:
if video_url:
video_id = self.get_video_id(video_url)
def get_video_info(self, video_id) -> Video:

The video_url argument isn't needed: this is only called by get_transcript() below and it always passes video_id never video_url

Comment on lines +77 to +79
# Try the `via.video.lang` param first
if transcript_id := via_config.get("video", {}).get("lang"):
return transcript_id
Copy link
Contributor

@seanh seanh Aug 2, 2023

Choose a reason for hiding this comment

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

Suggested change
# Try the `via.video.lang` param first
if transcript_id := via_config.get("video", {}).get("lang"):
return transcript_id

We should remove this as it'll be dead code: nothing is ever going to be passing the via.video.lang param. We can add support for this query param back in a later PR when we need it

@jon-betts jon-betts force-pushed the yt-cc-client branch 3 times, most recently from 0a7ed32 to 5ec410d Compare August 2, 2023 19:28
Jon Betts added 4 commits August 3, 2023 14:24
@seanh
Copy link
Contributor

seanh commented Aug 15, 2023

Closing this, I think it was superseded by #1160

@seanh seanh closed this Aug 15, 2023
@seanh seanh deleted the yt-cc-integrate branch August 15, 2023 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants