-
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prevent downloading playlist with format selection
- Loading branch information
1 parent
846fb29
commit 4a87ea5
Showing
9 changed files
with
129 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package formats | ||
|
||
import ( | ||
"encoding/json" | ||
"log/slog" | ||
"os/exec" | ||
"sync" | ||
|
||
"github.com/marcopeocchi/yt-dlp-web-ui/v3/server/config" | ||
) | ||
|
||
func ParseURL(url string) (*Metadata, error) { | ||
cmd := exec.Command(config.Instance().DownloaderPath, url, "-J") | ||
|
||
stdout, err := cmd.Output() | ||
if err != nil { | ||
slog.Error("failed to retrieve metadata", slog.String("err", err.Error())) | ||
return nil, err | ||
} | ||
|
||
slog.Info( | ||
"retrieving metadata", | ||
slog.String("caller", "getFormats"), | ||
slog.String("url", url), | ||
) | ||
|
||
info := &Metadata{URL: url} | ||
best := &Format{} | ||
|
||
var ( | ||
wg sync.WaitGroup | ||
decodingError error | ||
) | ||
|
||
wg.Add(2) | ||
|
||
go func() { | ||
decodingError = json.Unmarshal(stdout, &info) | ||
wg.Done() | ||
}() | ||
|
||
go func() { | ||
decodingError = json.Unmarshal(stdout, &best) | ||
wg.Done() | ||
}() | ||
|
||
wg.Wait() | ||
|
||
if decodingError != nil { | ||
return nil, err | ||
} | ||
|
||
info.Best = *best | ||
|
||
return info, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package formats | ||
|
||
// Used to deser the formats in the -J output | ||
type Metadata struct { | ||
Type string `json:"_type"` | ||
Formats []Format `json:"formats"` | ||
Best Format `json:"best"` | ||
Thumbnail string `json:"thumbnail"` | ||
Title string `json:"title"` | ||
URL string `json:"url"` | ||
Entries []Metadata `json:"entries"` // populated if url is playlist | ||
} | ||
|
||
func (m *Metadata) IsPlaylist() bool { | ||
return m.Type == "playlist" | ||
} | ||
|
||
// A skimmed yt-dlp format node | ||
type Format struct { | ||
Format_id string `json:"format_id"` | ||
Format_note string `json:"format_note"` | ||
FPS float32 `json:"fps"` | ||
Resolution string `json:"resolution"` | ||
VCodec string `json:"vcodec"` | ||
ACodec string `json:"acodec"` | ||
Size float32 `json:"filesize_approx"` | ||
Language string `json:"language"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters