@@ -3,16 +3,10 @@ package dl
33import (
44 "bytes"
55 "context"
6- "encoding/json"
7- "fmt"
86 "io"
9- "os"
107 "os/exec"
11- "strconv"
128 "strings"
139 "testing"
14-
15- "github.com/photoprism/photoprism/pkg/fs"
1610)
1711
1812const (
@@ -22,74 +16,6 @@ const (
2216 subtitlesTestVideoRawURL = "https://www.youtube.com/watch?v=QRS8MkLhQmM"
2317)
2418
25- // Todo: Must be fixed, which might require an updated YT-DLP version or different request parameters.
26- func TestParseInfo (t * testing.T ) {
27- t .Skip ("todo: must be fixed, which might require an updated YT-DLP version or different request parameters" )
28-
29- if testing .Short () {
30- t .Skip ("skipping test in short mode." )
31- }
32-
33- for _ , c := range []struct {
34- url string
35- expectedTitle string
36- }{
37- {"https://soundcloud.com/avalonemerson/avalon-emerson-live-at-printworks-london-march-2017" ,
38- "Avalon Emerson Live at Printworks London 2017" },
39- {"https://www.infoq.com/presentations/Simple-Made-Easy" ,
40- "Simple Made Easy - InfoQ" },
41- {testVideoRawURL ,
42- "Cinematic Epic Deep Trailer - Background Music for Trailers and Film" },
43- } {
44- t .Run (c .url , func (t * testing.T ) {
45- ctx , cancelFn := context .WithCancel (context .Background ())
46- ydlResult , err := NewMetadata (ctx , c .url , Options {
47- DownloadThumbnail : true ,
48- })
49- if err != nil {
50- cancelFn ()
51- t .Errorf ("failed to parse: %v" , err )
52- return
53- }
54- cancelFn ()
55-
56- yi := ydlResult .Info
57- results := ydlResult .Formats ()
58-
59- if yi .Title != c .expectedTitle {
60- t .Errorf ("expected title %q got %q" , c .expectedTitle , yi .Title )
61- }
62-
63- if yi .Thumbnail != "" && len (yi .ThumbnailBytes ) == 0 {
64- t .Errorf ("expected thumbnail bytes" )
65- }
66-
67- var dummy map [string ]interface {}
68- if err := json .Unmarshal (ydlResult .RawJSON , & dummy ); err != nil {
69- t .Errorf ("failed to parse RawJSON" )
70- }
71-
72- if len (results ) == 0 {
73- t .Errorf ("expected formats" )
74- }
75-
76- for _ , f := range results {
77- if f .FormatID == "" {
78- t .Errorf ("expected to have FormatID" )
79- }
80- if f .Ext == "" {
81- t .Errorf ("expected to have Ext" )
82- }
83- if (f .ACodec == "" || f .ACodec == "none" ) &&
84- (f .VCodec == "" || f .VCodec == "none" ) &&
85- f .Ext == "" {
86- t .Errorf ("expected to have some media: audio %q video %q ext %q" , f .ACodec , f .VCodec , f .Ext )
87- }
88- }
89- })
90- }
91- }
92-
9319func TestPlaylist (t * testing.T ) {
9420 t .Skip ("skipping test because playlist URL is unreliable." )
9521
@@ -152,7 +78,7 @@ func TestChannel(t *testing.T) {
15278
15379func TestUnsupportedURL (t * testing.T ) {
15480 if testing .Short () {
155- t .Skip ("skipping test in short mode. " )
81+ t .Skip ("skipped download test in short mode" )
15682 }
15783
15884 _ , ydlResultErr := NewMetadata (context .Background (), "https://www.google.com" , Options {})
@@ -218,107 +144,9 @@ func TestSubtitles(t *testing.T) {
218144 }
219145}
220146
221- // Todo: Must be fixed, which might require an updated YT-DLP version or different request parameters.
222- func TestDownloadSections (t * testing.T ) {
223- t .Skip ("todo: must be fixed, which might require an updated YT-DLP version or different request parameters" )
224-
225- fileName := fs .Abs ("./testdata/duration_test_file" )
226- duration := 5
227-
228- defer func () {
229- _ = os .Remove (fileName )
230- }()
231-
232- cmd := exec .Command (FindFFmpegBin (), "-version" )
233- _ , err := cmd .Output ()
234-
235- if err != nil {
236- t .Errorf ("failed to check ffmpeg installed: %s" , err )
237- }
238-
239- ydlResult , ydlResultErr := NewMetadata (
240- context .Background (),
241- testVideoRawURL ,
242- Options {
243- DownloadSections : fmt .Sprintf ("*0:0-0:%d" , duration ),
244- })
245-
246- if ydlResult .Options .DownloadSections != "*0:0-0:5" {
247- t .Errorf ("failed to setup --download-sections" )
248- }
249-
250- if ydlResultErr != nil {
251- t .Errorf ("failed to download: %s" , ydlResultErr )
252- }
253-
254- dr , err := ydlResult .Download (context .Background (), "" )
255-
256- if err != nil {
257- t .Fatal (err )
258- }
259-
260- f , err := os .Create (fileName )
261-
262- if err != nil {
263- t .Fatal (err )
264- }
265-
266- defer f .Close ()
267-
268- _ , err = io .Copy (f , dr )
269- if err != nil {
270- t .Fatal (err )
271- }
272-
273- cmd = exec .Command (FindFFprobeBin (), "-v" , "quiet" , "-show_entries" , "format=duration" , fileName )
274- stdout , err := cmd .Output ()
275-
276- if err != nil {
277- t .Fatal (err )
278- }
279-
280- var gotDurationString string
281- output := string (stdout )
282- for _ , line := range strings .Split (output , "\n " ) {
283- if strings .Contains (line , "duration" ) {
284- if d , found := strings .CutPrefix (line , "duration=" ); found {
285- gotDurationString = d
286- }
287- }
288- }
289-
290- gotDuration , err := strconv .ParseFloat (gotDurationString , 32 )
291-
292- if err != nil {
293- t .Fatal (err )
294- }
295-
296- seconds := int (gotDuration )
297-
298- if seconds != duration {
299- t .Fatalf ("did not get expected duration of %d, but got %d" , duration , seconds )
300- }
301-
302- _ = dr .Close ()
303- }
304-
305- func TestErrorNotAPlaylist (t * testing.T ) {
306- if testing .Short () {
307- t .Skip ("skipping test in short mode." )
308- }
309-
310- _ , ydlResultErr := NewMetadata (context .Background (), testVideoRawURL , Options {
311- Type : TypePlaylist ,
312- DownloadThumbnail : false ,
313- })
314- if ydlResultErr != ErrNotAPlaylist {
315- t .Errorf ("expected is playlist error, got %s" , ydlResultErr )
316- }
317- }
318-
319147func TestErrorNotASingleEntry (t * testing.T ) {
320148 if testing .Short () {
321- t .Skip ("skipping test in short mode. " )
149+ t .Skip ("skipped download test in short mode" )
322150 }
323151
324152 _ , ydlResultErr := NewMetadata (context .Background (), playlistRawURL , Options {
@@ -331,40 +159,6 @@ func TestErrorNotASingleEntry(t *testing.T) {
331159 }
332160}
333161
334- // Todo: Must be fixed, which might require an updated YT-DLP version or different request parameters.
335- func TestOptionDownloader (t * testing.T ) {
336- t .Skip ("todo: must be fixed, which might require an updated YT-DLP version or different request parameters" )
337-
338- if testing .Short () {
339- t .Skip ("skipping test in short mode." )
340- }
341-
342- ydlResult , ydlResultErr := NewMetadata (
343- context .Background (),
344- testVideoRawURL ,
345- Options {
346- Downloader : "ffmpeg" ,
347- })
348-
349- if ydlResultErr != nil {
350- t .Fatalf ("failed to download: %s" , ydlResultErr )
351- }
352-
353- dr , err := ydlResult .Download (context .Background (), ydlResult .Info .Formats [0 ].FormatID )
354-
355- if err != nil {
356- t .Fatal (err )
357- }
358-
359- downloadBuf := & bytes.Buffer {}
360- _ , err = io .Copy (downloadBuf , dr )
361-
362- if err != nil {
363- t .Fatal (err )
364- }
365- dr .Close ()
366- }
367-
368162func TestInvalidOptionTypeField (t * testing.T ) {
369163 _ , err := NewMetadata (context .Background (), playlistRawURL , Options {
370164 Type : 42 ,
@@ -376,7 +170,7 @@ func TestInvalidOptionTypeField(t *testing.T) {
376170
377171func TestDownloadPlaylistEntry (t * testing.T ) {
378172 if testing .Short () {
379- t .Skip ("skipping test in short mode. " )
173+ t .Skip ("skipped download test in short mode" )
380174 }
381175
382176 // Download file by specifying the playlist index
0 commit comments