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)

View File

@@ -24,16 +24,17 @@ const (
type Original struct {
gorm.Model
UserID uint
URL string
Title string
Artist string
UploadDate time.Time
Status Status
Audio bool // video download requested
Video bool // audio download requested
Watched bool
Timestamp float64
UserID uint
URL string
Title string
Artist string
UploadDate time.Time
UploaderUrl string
Status Status
Audio bool // video download requested
Video bool // audio download requested
Watched bool
Timestamp float64
Playlist bool // part of a playlist
PlaylistID uint // Playlist.ID (if part of a playlist)

View File

@@ -10,4 +10,12 @@
.video-list {
grid-template-columns: 1fr;
}
}
.video-artist-link {
a,
a:visited {
color: gray;
}
}

View File

@@ -35,7 +35,11 @@
<div class="video-title video-title-bare {{$bareHidden}}">
{{.Title}}
</div>
<div class="video-info">{{.Artist}}</div>
{{if (eq .UploaderUrl "")}}
<div class="video-info video-artist-bare">{{.Artist}}</div>
{{else}}
<div class="video-info video-artist-link"><a href="{{.UploaderUrl}}">{{.Artist}}</a></div>
{{end}}
<div class="video-info"><a href="{{.URL}}">{{.URL}}</a></div>
<div class="video-info video-status">{{.Status}}</div>
<div class="video-info">