Skip to content

Commit

Permalink
feat: now urls like youtu.be/ID is supported
Browse files Browse the repository at this point in the history
  • Loading branch information
nlif-m committed Jun 23, 2023
1 parent 2b71454 commit 77c3a18
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ytdlp/ytdlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func (yt *Ytdlp) GetVersion() (version string, err error) {
}

var youtubeVideoRegexp = regexp.MustCompile(`(https:\/\/|)(www\.|)youtube\.com\/watch\?v=.+`)
var youtubeVideoRegexp2 = regexp.MustCompile(`(https:\/\/|)youtu\.be\/.+`)
var youtubePlaylistRegexp = regexp.MustCompile(`(https:\/\/|)(www\.|)youtube\.com\/playlist\?list=.+`)
var vkVideoRegexp = regexp.MustCompile(`(https:\/\/|)vk\.com\/video(s|).+`)

Expand All @@ -89,10 +90,16 @@ func (yt *Ytdlp) IsDownloadable(rawURL string) (ytType YtdlpURLType, URL string,
if URL != "" {
return YoutubeVideoType, URL, true
}
URL = youtubeVideoRegexp2.FindString(rawURL)
if URL != "" {
return YoutubeVideoType, URL, true
}

URL = youtubePlaylistRegexp.FindString(rawURL)
if URL != "" {
return YoutubePlaylistType, URL, true
}

URL = vkVideoRegexp.FindString(rawURL)
if URL != "" {
return VkVideoType, URL, true
Expand Down
2 changes: 2 additions & 0 deletions ytdlp/ytdlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ func TestIsDownloadable(t *testing.T) {
{"https://www.youtube.com/watch?v=123456789zxcvbnasdfqwew", YoutubeVideoType, true},
{"www.youtube.com/watch?v=123456789zxcvbnasdfqwew", YoutubeVideoType, true},
{"youtube.com/watch?v=123456789zxcvbnasdfqwew", YoutubeVideoType, true},
{"https://youtu.be/312u8fdjaf", YoutubeVideoType, true},
{"youtu.be/312u8fdjaf", YoutubeVideoType, true},

{"https://www.youtube.com/playlist?list=1234345sdfjlka", YoutubePlaylistType, true},
{"www.youtube.com/playlist?list=1234345sdfjlka", YoutubePlaylistType, true},
Expand Down

0 comments on commit 77c3a18

Please sign in to comment.