Skip to content
This repository has been archived by the owner on Aug 12, 2020. It is now read-only.

Commit

Permalink
Restructure tests
Browse files Browse the repository at this point in the history
  • Loading branch information
corny committed Jul 22, 2020
1 parent 9d5caf4 commit 75b13b9
Showing 1 changed file with 50 additions and 69 deletions.
119 changes: 50 additions & 69 deletions video_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,43 @@ import (
"github.com/stretchr/testify/require"
)

func TestInvalidURLs(t *testing.T) {
urls := []string{
"https://www.youtube.com/",
"https://www.facebook.com/video.php?v=10153820411888896",
}

for _, url := range urls {
t.Run(url, func(t *testing.T) {
_, err := GetVideoInfo(context.Background(), url)
assert.EqualError(t, err, "invalid youtube URL, no video id")
})
}
}

// Run a single test with:
func TestVideoInfo(t *testing.T) {

tests := []struct {
url string
errorMessage string
duration time.Duration
published time.Time
title string
uploader string
description string
song string
artist string
videoID string
skip bool
duration time.Duration
published time.Time
title string
uploader string
description string
song string
artist string
}{
{
url: "https://www.youtube.com/",
errorMessage: "invalid youtube URL, no video id",
},
{
url: "https://www.facebook.com/video.php?v=10153820411888896",
errorMessage: "invalid youtube URL, no video id",
},
//{
// url: "https://www.youtube.com/watch?v=TDgn8k9uyW4",
//},
{
url: "https://www.youtube.com/watch?v=BaW_jenozKc",
videoID: "BaW_jenozKc",
title: `youtube-dl test video "'/\ä↭𝕐`,
uploader: "Philipp Hagemeister",
duration: time.Second * 10,
published: newDate(2012, 10, 2),
description: "test chars: \"'/\\ä↭𝕐\ntest URL: https://github.com/rg3/youtube-dl/iss...\n\nThis is a test video for youtube-dl.\n\nFor more information, contact phihag@phihag.de .",
},
{
url: "https://www.youtube.com/watch?v=YQHsXMglC9A",
videoID: "YQHsXMglC9A",
title: "Adele - Hello",
uploader: "AdeleVEVO",
duration: time.Second * 367,
Expand All @@ -55,7 +57,7 @@ func TestVideoInfo(t *testing.T) {
description: "‘Hello' is taken from the new album, 25, out November 20. http://adele.com\nAvailable now from iTunes http://smarturl.it/itunes25 \nAvailable now from Amazon http://smarturl.it/25amazon \nAvailable now from Google Play http://smarturl.it/25gplay\nAvailable now at Target (US Only): http://smarturl.it/target25\n\nDirected by Xavier Dolan, @XDolan\n\nFollow Adele on:\n\nFacebook - https://www.facebook.com/Adele\nTwitter - https://twitter.com/Adele \nInstagram - http://instagram.com/Adele\n\nhttp://vevo.ly/jzAuJ1\n\nCommissioner: Phil Lee\nProduction Company: Believe Media/Sons of Manual/Metafilms\nDirector: Xavier Dolan\nExecutive Producer: Jannie McInnes\nProducer: Nancy Grant/Xavier Dolan\nCinematographer: André Turpin\nProduction design : Colombe Raby\nEditor: Xavier Dolan\nAdele's lover : Tristan Wilds",
},
{
url: "https://www.youtube.com/watch?v=H-30B0cqh88",
videoID: "H-30B0cqh88",
title: "Kung Fu Panda 3 Official Trailer #3 (2016) - Jack Black, Angelina Jolie Animated Movie HD",
uploader: "Movieclips Trailers",
duration: time.Second * 145,
Expand All @@ -66,15 +68,16 @@ func TestVideoInfo(t *testing.T) {
// Test VEVO video with age protection
// https://github.com/ytdl-org/youtube-dl/issues/956
{
url: "https://www.youtube.com/watch?v=07FYdnEawAQ",
videoID: "07FYdnEawAQ",
skip: true,
title: `Justin Timberlake - Tunnel Vision (Official Music Video) (Explicit)`,
uploader: "justintimberlakeVEVO",
duration: time.Second * 419,
published: newDate(2013, 7, 3),
description: "Executive Producer: Jeff Nicholas \nProduced by Jonathan Craven and Nathan Scherrer \nDirected by Jonathan Craven, Simon McLoughlin and Jeff Nicholas for The Uprising Creative (http://theuprisingcreative.com) \nDirector Of Photography: Sing Howe Yam \nEditor: Jacqueline London\n\nOfficial music video by Justin Timberlake performing Tunnel Vision (Explicit). (C) 2013 RCA Records, a division of Sony Music Entertainment\n\n#JustinTimberlake #TunnelVision #Vevo #Pop #OfficialMuiscVideo",
},
{
url: "https://www.youtube.com/watch?v=qHGTs1NSB1s",
videoID: "qHGTs1NSB1s",
title: "Why Linus Torvalds doesn't use Ubuntu or Debian",
uploader: "TFiR",
description: `Subscribe to our weekly newsletter: https://www.tfir.io/dnl
Expand All @@ -88,7 +91,7 @@ Linus gives the practical reasons why he doesn't use Ubuntu or Debian.`,
},
// 256k DASH audio (format 141) via DASH manifest
{
url: "https://www.youtube.com/watch?v=a9LDPn-MO4I",
videoID: "a9LDPn-MO4I",
title: "UHDTV TEST 8K VIDEO.mp4",
uploader: "8KVIDEO",
description: "",
Expand All @@ -98,24 +101,29 @@ Linus gives the practical reasons why he doesn't use Ubuntu or Debian.`,
}

for _, tt := range tests {
t.Run(tt.url, func(t *testing.T) {
t.Run(tt.videoID, func(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
client := newTestClient(t)
info, err := client.GetVideoInfo(context.Background(), tt.url)

if tt.errorMessage != "" {
// we expect an error
assert.EqualError(err, tt.errorMessage)
} else {
if assert.NoError(err) {
assert.Equal(tt.duration, info.Duration, "Duration mismatch")
assert.Equal(tt.title, info.Title, "Title mismatch")
assert.Equal(tt.published, info.DatePublished, "DatePublished mismatch")
assert.Equal(tt.uploader, info.Uploader, "Uploader mismatch")
assert.Equal(tt.song, info.Song, "Song mismatch")
assert.Equal(tt.artist, info.Artist, "Artist mismatch")
assert.Equal(tt.description, info.Description, "Description mismatch")
info, err := GetVideoInfo(context.Background(), tt.videoID)

require.NoError(err)
assert.Equal(tt.duration, info.Duration, "Duration mismatch")
assert.Equal(tt.title, info.Title, "Title mismatch")
assert.Equal(tt.published, info.DatePublished, "DatePublished mismatch")
assert.Equal(tt.uploader, info.Uploader, "Uploader mismatch")
assert.Equal(tt.song, info.Song, "Song mismatch")
assert.Equal(tt.artist, info.Artist, "Artist mismatch")
assert.Equal(tt.description, info.Description, "Description mismatch")

if assert.Greater(len(info.Formats), 10) {
if tt.skip {
t.Skip()
}

format := info.Formats.Worst(FormatResolutionKey)[0]
_, err = client.GetDownloadURL(context.Background(), info, format)
assert.NoError(err)
}
})
}
Expand Down Expand Up @@ -146,33 +154,6 @@ func TestExtractIDfromInvalidURL(t *testing.T) {
assert.Equal(t, "", extractVideoID(uri))
}

func TestGetDownloadURL(t *testing.T) {
testCases := []string{
"FrG4TEcSuRg",
"jgVhBThJdXc",
"MXgnIP4rMoI",
"peBgUMT26jM",
"aQZDbBGBJsM",
"cRS4mS4gKwg",
"0fllyJTBsRU",
}
for _, id := range testCases {
t.Run(id, func(t *testing.T) {
client := newTestClient(t)
info, err := client.GetVideoInfo(context.Background(), "https://www.youtube.com/watch?v="+id)
require.NoError(t, err)

if len(info.Formats) == 0 {
t.Fatal("empty format list")
}

format := info.Formats.Worst(FormatResolutionKey)[0]
_, err = client.GetDownloadURL(context.Background(), info, format)
assert.NoError(t, err)
})
}
}

func TestDownloadVideo(t *testing.T) {
client := newTestClient(t)
info, err := client.GetVideoInfo(context.Background(), "https://www.youtube.com/watch?v=FrG4TEcSuRg")
Expand Down

0 comments on commit 75b13b9

Please sign in to comment.