Retrieve upload URL
This commit is contained in:
24
handlers.go
24
handlers.go
@@ -117,6 +117,7 @@ func downloadPostHandler(c echo.Context) error {
|
|||||||
type Meta struct {
|
type Meta struct {
|
||||||
title string
|
title string
|
||||||
artist string
|
artist string
|
||||||
|
uploadDate time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func getYtdlpTitle(url string, args []string) (string, error) {
|
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
|
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) {
|
func getYtdlpMeta(url string, args []string) (Meta, error) {
|
||||||
|
|
||||||
meta := Meta{}
|
meta := Meta{}
|
||||||
@@ -185,6 +204,10 @@ func getYtdlpMeta(url string, args []string) (Meta, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return meta, err
|
return meta, err
|
||||||
}
|
}
|
||||||
|
meta.uploadDate, err = getYtdlpUploadDate(url, args)
|
||||||
|
if err != nil {
|
||||||
|
return meta, err
|
||||||
|
}
|
||||||
|
|
||||||
return meta, nil
|
return meta, nil
|
||||||
}
|
}
|
||||||
@@ -548,6 +571,7 @@ func startDownload(originalID uint, videoURL string, audioOnly bool) {
|
|||||||
err = db.Model(&originals.Original{}).Where("id = ?", originalID).Updates(map[string]interface{}{
|
err = db.Model(&originals.Original{}).Where("id = ?", originalID).Updates(map[string]interface{}{
|
||||||
"title": origMeta.title,
|
"title": origMeta.title,
|
||||||
"artist": origMeta.artist,
|
"artist": origMeta.artist,
|
||||||
|
"upload_date": origMeta.uploadDate,
|
||||||
}).Error
|
}).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorln("couldn't store metadata:", err)
|
log.Errorln("couldn't store metadata:", err)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package originals
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
"ytdlp-site/database"
|
"ytdlp-site/database"
|
||||||
"ytdlp-site/transcodes"
|
"ytdlp-site/transcodes"
|
||||||
|
|
||||||
@@ -27,6 +28,7 @@ type Original struct {
|
|||||||
URL string
|
URL string
|
||||||
Title string
|
Title string
|
||||||
Artist string
|
Artist string
|
||||||
|
UploadDate time.Time
|
||||||
Status Status
|
Status Status
|
||||||
Audio bool // video download requested
|
Audio bool // video download requested
|
||||||
Video bool // audio download requested
|
Video bool // audio download requested
|
||||||
|
|||||||
Reference in New Issue
Block a user