mirror of
https://github.com/miniflux/v2.git
synced 2025-08-06 17:41:00 +00:00
feat(rewrite): add support for YouTube Shorts video URL pattern
This commit is contained in:
parent
8a014c6abc
commit
919ee8fa1b
3 changed files with 109 additions and 16 deletions
|
@ -66,7 +66,7 @@ func TestRewriteWithNoMatchingRule(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestRewriteWithYoutubeLink(t *testing.T) {
|
||||
func TestRewriteYoutubeVideoLink(t *testing.T) {
|
||||
config.Opts = config.NewOptions()
|
||||
|
||||
controlEntry := &model.Entry{
|
||||
|
@ -86,7 +86,47 @@ func TestRewriteWithYoutubeLink(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestRewriteWithYoutubeLinkAndCustomEmbedURL(t *testing.T) {
|
||||
func TestRewriteYoutubeShortLink(t *testing.T) {
|
||||
config.Opts = config.NewOptions()
|
||||
|
||||
controlEntry := &model.Entry{
|
||||
URL: "https://www.youtube.com/shorts/1LUWKWZkPjo",
|
||||
Title: `A title`,
|
||||
Content: `<iframe width="650" height="350" frameborder="0" src="https://www.youtube-nocookie.com/embed/1LUWKWZkPjo" allowfullscreen></iframe><br>Video Description`,
|
||||
}
|
||||
testEntry := &model.Entry{
|
||||
URL: "https://www.youtube.com/shorts/1LUWKWZkPjo",
|
||||
Title: `A title`,
|
||||
Content: `Video Description`,
|
||||
}
|
||||
ApplyContentRewriteRules(testEntry, ``)
|
||||
|
||||
if !reflect.DeepEqual(testEntry, controlEntry) {
|
||||
t.Errorf(`Not expected output: got "%+v" instead of "%+v"`, testEntry, controlEntry)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRewriteIncorrectYoutubeLink(t *testing.T) {
|
||||
config.Opts = config.NewOptions()
|
||||
|
||||
controlEntry := &model.Entry{
|
||||
URL: "https://www.youtube.com/some-page",
|
||||
Title: `A title`,
|
||||
Content: `Video Description`,
|
||||
}
|
||||
testEntry := &model.Entry{
|
||||
URL: "https://www.youtube.com/some-page",
|
||||
Title: `A title`,
|
||||
Content: `Video Description`,
|
||||
}
|
||||
ApplyContentRewriteRules(testEntry, ``)
|
||||
|
||||
if !reflect.DeepEqual(testEntry, controlEntry) {
|
||||
t.Errorf(`Not expected output: got "%+v" instead of "%+v"`, testEntry, controlEntry)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRewriteYoutubeLinkAndCustomEmbedURL(t *testing.T) {
|
||||
os.Clearenv()
|
||||
os.Setenv("YOUTUBE_EMBED_URL_OVERRIDE", "https://invidious.custom/embed/")
|
||||
|
||||
|
@ -115,6 +155,46 @@ func TestRewriteWithYoutubeLinkAndCustomEmbedURL(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestRewriteYoutubeVideoLinkUsingInvidious(t *testing.T) {
|
||||
config.Opts = config.NewOptions()
|
||||
controlEntry := &model.Entry{
|
||||
URL: "https://www.youtube.com/watch?v=1234",
|
||||
Title: `A title`,
|
||||
Content: `<iframe width="650" height="350" frameborder="0" src="https://yewtu.be/embed/1234" allowfullscreen></iframe><br>Video Description`,
|
||||
}
|
||||
testEntry := &model.Entry{
|
||||
URL: "https://www.youtube.com/watch?v=1234",
|
||||
Title: `A title`,
|
||||
Content: `Video Description`,
|
||||
}
|
||||
|
||||
ApplyContentRewriteRules(testEntry, `add_youtube_video_using_invidious_player`)
|
||||
|
||||
if !reflect.DeepEqual(testEntry, controlEntry) {
|
||||
t.Errorf(`Not expected output: got "%+v" instead of "%+v"`, testEntry, controlEntry)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRewriteYoutubeShortLinkUsingInvidious(t *testing.T) {
|
||||
config.Opts = config.NewOptions()
|
||||
controlEntry := &model.Entry{
|
||||
URL: "https://www.youtube.com/shorts/1LUWKWZkPjo",
|
||||
Title: `A title`,
|
||||
Content: `<iframe width="650" height="350" frameborder="0" src="https://yewtu.be/embed/1LUWKWZkPjo" allowfullscreen></iframe><br>Video Description`,
|
||||
}
|
||||
testEntry := &model.Entry{
|
||||
URL: "https://www.youtube.com/shorts/1LUWKWZkPjo",
|
||||
Title: `A title`,
|
||||
Content: `Video Description`,
|
||||
}
|
||||
|
||||
ApplyContentRewriteRules(testEntry, `add_youtube_video_using_invidious_player`)
|
||||
|
||||
if !reflect.DeepEqual(testEntry, controlEntry) {
|
||||
t.Errorf(`Not expected output: got "%+v" instead of "%+v"`, testEntry, controlEntry)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRewriteWithInexistingCustomRule(t *testing.T) {
|
||||
controlEntry := &model.Entry{
|
||||
URL: "https://www.youtube.com/watch?v=1234",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue