Skip to content

Commit

Permalink
Merge pull request #405 from wader/add-gif
Browse files Browse the repository at this point in the history
Add gif support
  • Loading branch information
wader authored Nov 13, 2023
2 parents 594cde8 + 3640dd3 commit cc83c4f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 19 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ can handle most format and codecs. Default configuration can transcode to these
|-|-|-|-|-|
|alac|mp4|alac|||
|flac|flac|flac|||
|gif|gif||gif||
|m4a|mp4|aac|||
|mp3|mp3|mp3|||
|ogg|ogg|vorbis, opus|||
Expand Down
45 changes: 26 additions & 19 deletions internal/ydls/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,12 @@ func TestFormats(t *testing.T) {

for _, c := range []struct {
MediaRawURL string
hasAudio bool
hasVideo bool
expectedFilename string
}{
{soundcloudTestAudioURL, false, "Avalon Emerson Live at Printworks London"},
{youtubeTestVideoURL, true, "TEST VIDEO"},
{soundcloudTestAudioURL, true, false, "Avalon Emerson Live at Printworks London"},
{youtubeTestVideoURL, false, true, "TEST VIDEO"},
} {
for formatName, format := range ydls.Config.Formats {
if firstFormat, _ := format.Formats.First(); firstFormat == "rss" {
Expand All @@ -115,14 +116,21 @@ func TestFormats(t *testing.T) {
defer leakChecks(t)()

requireVideo := false
requireAudio := false
for _, s := range format.Streams {
if s.Media == MediaVideo && s.Required {
requireVideo = true
break
}
if s.Media == MediaAudio && s.Required {
requireAudio = true
}
}
if requireVideo && !c.hasVideo {
t.Logf("skip, format require video and test stream has no video only\n")
t.Logf("skip, format require video but test stream has no video\n")
return
}
if requireAudio && !c.hasAudio {
t.Logf("skip, format require audio but test stream has no audio\n")
return
}

Expand Down Expand Up @@ -168,27 +176,26 @@ func TestFormats(t *testing.T) {
return
}

// TODO: rewrite and add video only test?
// look for audio
audioFound := false
for _, f := range format.Streams {
if f.Media != MediaAudio {
continue
if c.hasAudio {
audioFound := false
for _, f := range format.Streams {
if f.Media != MediaAudio {
continue
}
if !f.CodecNames.Member(pi.AudioCodec()) {
t.Errorf("expected codec %s found %s", f.CodecNames, pi.AudioCodec())
return
}
audioFound = true
break
}
if !f.CodecNames.Member(pi.AudioCodec()) {
t.Errorf("expected codec %s found %s", f.CodecNames, pi.AudioCodec())
return
if requireVideo && !audioFound {
t.Errorf("no audio found")
}
audioFound = true
break
}
if !audioFound {
t.Errorf("no audio found")
}

if c.hasVideo {
videoFound := false
// look for video
for _, f := range format.Streams {
if f.Media != MediaVideo {
continue
Expand Down
16 changes: 16 additions & 0 deletions ydls.json
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,22 @@
],
"Ext": "mxf",
"MIMEType": "application/mxf"
},
"gif": {
"Formats": [
"gif"
],
"Streams": [
{
"Required": true,
"Specifier": "v:0",
"Codecs": [
"gif"
]
}
],
"Ext": "gif",
"MIMEType": "image/gif"
}
}
}

0 comments on commit cc83c4f

Please sign in to comment.