Add Artist link

This commit is contained in:
Carl Pearson
2025-05-02 05:51:52 -06:00
parent 9abe867c31
commit 90c3398ba3
4 changed files with 46 additions and 17 deletions

View File

@@ -115,9 +115,10 @@ func downloadPostHandler(c echo.Context) error {
}
type Meta struct {
title string
artist string
uploadDate time.Time
title string
artist string
uploadDate time.Time
uploaderUrl string
}
func getYtdlpTitle(url string, args []string) (string, error) {
@@ -191,6 +192,16 @@ func getYtdlpUploadDate(url string, args []string) (time.Time, error) {
return uploadDate, nil
}
func getYtdlpUploaderUrl(url string, args []string) (string, error) {
args = append(args, "--simulate", "--print", "%(uploader_url)s", url)
stdout, _, err := ytdlp.Run(args...)
if err != nil {
log.Errorln(err)
return "", err
}
return strings.TrimSpace(string(stdout)), nil
}
func getYtdlpMeta(url string, args []string) (Meta, error) {
meta := Meta{}
@@ -208,6 +219,10 @@ func getYtdlpMeta(url string, args []string) (Meta, error) {
if err != nil {
return meta, err
}
meta.uploaderUrl, err = getYtdlpUploaderUrl(url, args)
if err != nil {
return meta, err
}
return meta, nil
}
@@ -569,9 +584,10 @@ func startDownload(originalID uint, videoURL string, audioOnly bool) {
}
log.Debugf("original metadata %v", origMeta)
err = db.Model(&originals.Original{}).Where("id = ?", originalID).Updates(map[string]interface{}{
"title": origMeta.title,
"artist": origMeta.artist,
"upload_date": origMeta.uploadDate,
"title": origMeta.title,
"artist": origMeta.artist,
"upload_date": origMeta.uploadDate,
"uploader_url": origMeta.uploaderUrl,
}).Error
if err != nil {
log.Errorln("couldn't store metadata:", err)