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

fix: youtube short url path with timestamp parsing #545

Merged
merged 2 commits into from
Oct 11, 2023
Merged
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- Minor: Use Twitter OG tags if no Twitter credentials are configured. (#522)
- Minor: Support `x.com` for tweets. (#527)
- Minor: Increase tweet cache duration for non-credentialed requests to 24h. Currently not configurable. (#528)
- Fix: We do some more YouTube video ID parsing to ensure broken links (such as `youtube.com/watch?v=foobar?feature=share`) still return the actual video ID, since this is how the browser operates. (#488)
- Fix: We do some more YouTube video ID parsing to ensure broken links (such as `youtube.com/watch?v=foobar?feature=share`) still return the actual video ID, since this is how the browser operates. (#488, #545)
- Dev: Document the `log-development` setting. (#491)
- Dev: Document the `log-level` setting. (#490)
- Dev: Add some `pkg/utils/url.go` tests. (#525)
Expand Down
7 changes: 6 additions & 1 deletion internal/resolvers/youtube/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,10 @@ func getYoutubeVideoIDFromURL(url *url.URL) string {
}

func getYoutubeVideoIDFromURL2(url *url.URL) string {
return path.Base(url.Path)
v := path.Base(url.Path)
fields := strings.FieldsFunc(v, func(r rune) bool {
return r == '?' || r == '&'
})

return fields[0]
}
11 changes: 11 additions & 0 deletions internal/resolvers/youtube/video_shorturl_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ func TestVideoShortURLResolver(t *testing.T) {
ContentType: "application/json",
},
},
{
label: "Video with path semi-broken that we can fix",
inputURL: utils.MustParseURL("https://youtu.be/foobar&t=123"),
inputVideoID: "foobar",
inputReq: nil,
expectedResponse: &cache.Response{
Payload: []byte(`{"status":200,"thumbnail":"https://example.com/thumbnail.png","tooltip":"%3Cdiv%20style=%22text-align:%20left%3B%22%3E%0A%3Cb%3EVideo%20Title%3C%2Fb%3E%0A%3Cbr%3E%3Cb%3EChannel:%3C%2Fb%3E%20Channel%20Title%0A%3Cbr%3E%3Cb%3EDuration:%3C%2Fb%3E%2000:00:00%0A%3Cbr%3E%3Cb%3EPublished:%3C%2Fb%3E%2012%20Oct%202019%0A%3Cbr%3E%3Cb%3EViews:%3C%2Fb%3E%2050%0A%3Cbr%3E%3Cb%3E%3Cspan%20style=%22color:%20red%3B%22%3EAGE%20RESTRICTED%3C%2Fspan%3E%3C%2Fb%3E%0A%3Cbr%3E%3Cspan%20style=%22color:%20%232ecc71%3B%22%3E10%20likes%3C%2Fspan%3E\u0026nbsp%3B%E2%80%A2\u0026nbsp%3B%3Cspan%20style=%22color:%20%23808892%3B%22%3E5%20comments%3C%2Fspan%3E%0A%3C%2Fdiv%3E%0A"}`),
StatusCode: http.StatusOK,
ContentType: "application/json",
},
},
{
label: "404",
inputURL: utils.MustParseURL("https://youtu.be/404"),
Expand Down
Loading