subsyt/internal/metadata/metadata.go
Viktor Varland 6ff2d53c2d
Some checks are pending
build / build (push) Waiting to run
feat: use rss to fetch list of videos
This uses RSS to fetch a list of videos to avoid the vid being invisible
due to "restrictions", then downloads the videos one-by-one instead of
scraping and parsing the channel page using yt-dlp.

We lose metadata for the entire channel (show-level) so introducing a
hack to download just the metadata of a channel.
2025-09-08 22:30:57 +02:00

93 lines
1.8 KiB
Go

package metadata
import (
"fmt"
"log"
"os"
"path/filepath"
"regexp"
"strings"
"git.meatbag.se/varl/subsyt/internal/model"
"git.meatbag.se/varl/subsyt/internal/nfo"
)
func findFiles(scanPath string, ext string) ([]string, error) {
var result []string
err := filepath.Walk(scanPath, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() && strings.HasSuffix(path, ext) {
result = append(result, path)
}
return nil
})
if err != nil {
return nil, fmt.Errorf("error walking directory: %w", err)
}
return result, nil
}
func Generate(outDir string, title string, dryRun bool) {
showDir := filepath.Join(outDir, title)
log.Printf("Writing NFO's for %s\n", showDir)
if dryRun {
return
}
infojsons, err := findFiles(showDir, ".info.json")
if err != nil {
panic(err)
}
show := regexp.MustCompile("s(NA)")
season := regexp.MustCompile(`s\d\d\d\d`)
for index, path := range infojsons {
log.Println(index, path)
switch {
case show.MatchString(path):
show := model.LoadShow(path)
nfo.WriteShowInfo(show, filepath.Join(showDir, "tvshow.nfo"))
showBanner(show, showDir)
showFanart(show, showDir)
case season.MatchString(path):
ep := model.LoadEpisode(path)
nfo.WriteEpisodeNFO(ep, path)
default:
log.Printf("no match for '%s'\n", path)
}
os.Remove(path)
}
images, err := findFiles(showDir, ".jpg")
if err != nil {
panic(err)
}
for index, path := range images {
log.Println(index, path)
switch {
case show.MatchString(path):
showPoster(path, showDir)
case season.MatchString(path):
episodeImage(path)
default:
log.Printf("no match for '%s'\n", path)
}
}
del := filepath.Join(showDir, "sNA")
log.Printf("removing '%s'\n", del)
err = os.RemoveAll(del)
if err != nil {
log.Println("failed to remove", err)
}
}