Retrieve upload URL

This commit is contained in:
Carl Pearson
2025-05-02 05:39:15 -06:00
parent ccfaefbf46
commit 9abe867c31
2 changed files with 39 additions and 13 deletions

View File

@@ -115,8 +115,9 @@ func downloadPostHandler(c echo.Context) error {
}
type Meta struct {
title string
artist string
title string
artist string
uploadDate time.Time
}
func getYtdlpTitle(url string, args []string) (string, error) {
@@ -172,6 +173,24 @@ func getYtdlpArtist(url string, args []string) (string, error) {
return strings.TrimSpace(string(stdout)), nil
}
func getYtdlpUploadDate(url string, args []string) (time.Time, error) {
args = append(args, "--simulate", "--print", "%(upload_date>%Y-%m-%d)s", url)
stdout, _, err := ytdlp.Run(args...)
if err != nil {
log.Errorln(err)
return time.Time{}, err
}
dateStr := strings.TrimSpace(string(stdout))
uploadDate, err := time.Parse("2006-01-02", dateStr)
if err != nil {
return time.Time{}, fmt.Errorf("failed to parse date '%s': %w", dateStr, err)
}
return uploadDate, nil
}
func getYtdlpMeta(url string, args []string) (Meta, error) {
meta := Meta{}
@@ -185,6 +204,10 @@ func getYtdlpMeta(url string, args []string) (Meta, error) {
if err != nil {
return meta, err
}
meta.uploadDate, err = getYtdlpUploadDate(url, args)
if err != nil {
return meta, err
}
return meta, nil
}
@@ -546,8 +569,9 @@ 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,
"title": origMeta.title,
"artist": origMeta.artist,
"upload_date": origMeta.uploadDate,
}).Error
if err != nil {
log.Errorln("couldn't store metadata:", err)

View File

@@ -2,6 +2,7 @@ package originals
import (
"sync"
"time"
"ytdlp-site/database"
"ytdlp-site/transcodes"
@@ -23,15 +24,16 @@ const (
type Original struct {
gorm.Model
UserID uint
URL string
Title string
Artist string
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
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)