Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/youtube_media_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (y *YoutubeMediaFactory) CreateVideo(id string) (*core.Video, error) {
return nil, err
}

name := fmt.Sprintf("youtube[%s][%s][%s].mp4", resp.Id, video.FormatNote, audio.FormatNote)
name := fmt.Sprintf("youtube[%s][%s][%s].mp4", resp.Id, video.FormatNote, audio.FormatId)
videoPath := path.Join(os.TempDir(), name)

cmd := fmt.Sprintf("yt-dlp -f %s+%s https://youtu.be/%s -o %s", video.FormatId, audio.FormatId, resp.Id, videoPath)
Expand Down
9 changes: 9 additions & 0 deletions api/ytdlp_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type YtDlpResponse struct {
}

type YtDlpFormat struct {
Container string `json:"container"`
Ext string `json:"ext"`
FormatId string `json:"format_id"`
Format string `json:"format"`
Expand All @@ -67,10 +68,18 @@ type YtDlpFormat struct {
}

func (v YtDlpResponse) audioFormat() (*YtDlpFormat, error) {
var original *YtDlpFormat
for _, f := range v.Formats {
if f.FormatId == "140" {
return f, nil
}
if f.Container == "m4a_dash" && strings.Contains(f.Format, "original (default), medium") {
original = f
}
}

if original != nil {
return original, nil
}

return nil, fmt.Errorf("140 not found for %s", v.Id)
Expand Down