Skip to content

Commit

Permalink
Fix #56 Can't download ARTE series
Browse files Browse the repository at this point in the history
Arte.tv has closed its API to get collection. So, I have to scrap the site to collect episodes..

Actors, Directors and aother credits are now collected and writtend down into NFO file.
  • Loading branch information
simulot committed Feb 1, 2021
1 parent 6e9a153 commit da9cb1c
Show file tree
Hide file tree
Showing 13 changed files with 465 additions and 205 deletions.
2 changes: 1 addition & 1 deletion cmd/aspiratv/config.go
Expand Up @@ -121,7 +121,7 @@ func (c *config) Check() {
}

for _, m := range c.WatchList {
m.Pitch = strings.ToLower(m.Pitch)
// m.Pitch = strings.ToLower(m.Pitch)
m.Show = strings.ToLower(m.Show)
m.Title = strings.ToLower(m.Title)
if len(m.ShowRootPath) == 0 {
Expand Down
6 changes: 2 additions & 4 deletions cmd/aspiratv/download.go
Expand Up @@ -76,10 +76,8 @@ func (a *app) DownloadShow(ctx context.Context, p providers.Provider, m *provide
cancel()
}()
id := 1000 + atomic.AddInt32(&dlID, 1)
ShowPath := m.Match.ShowRootPath
if len(ShowPath) == 0 {
ShowPath = a.Config.Destinations[m.Match.Destination]
}
ShowPath := m.ShowPath

itemName = filepath.Base(m.Metadata.GetMediaPath(ShowPath))

err := p.GetMediaDetails(ctx, m) // Side effect: Episode number can be determined at this point.
Expand Down
21 changes: 15 additions & 6 deletions cmd/aspiratv/main.go
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"path"
"regexp"

"fmt"
Expand All @@ -17,6 +18,7 @@ import (

flag "github.com/spf13/pflag"

"github.com/simulot/aspiratv/metadata/nfo"
"github.com/simulot/aspiratv/mylog"
"github.com/simulot/aspiratv/net/myhttp"
"github.com/simulot/aspiratv/providers"
Expand Down Expand Up @@ -396,23 +398,30 @@ showLoop:
}
seen[m.ID] = true

mediaBasePath := filepath.Base(m.Metadata.GetMediaPath(m.Match.ShowRootPath))
if m.Match.ShowRootPath == "" {
m.ShowPath = path.Join(a.Config.Destinations[m.Match.Destination], nfo.FileNameCleaner(m.Metadata.GetMediaInfo().Showtitle))
} else {
m.ShowPath = m.Match.ShowRootPath
}

mediaBaseName := filepath.Base(m.Metadata.GetMediaPath(m.ShowPath))

select {
case <-ctx.Done():
a.logger.Trace().Printf("[%s] Context done, received %s", p.Name(), ctx.Err())
break showLoop
default:
if !m.Metadata.Accepted(m.Match) {
a.logger.Trace().Printf("[%s] %s is filtered out.", p.Name(), mediaBasePath)
a.logger.Trace().Printf("[%s] %s is filtered out.", p.Name(), mediaBaseName)
} else if a.Config.Force || a.MustDownload(ctx, p, m) {
a.logger.Trace().Printf("[%s] Download of %q submitted", p.Name(), mediaBasePath)
a.logger.Trace().Printf("[%s] Download of %q submitted", p.Name(), mediaBaseName)
showCount++
if !a.Config.Headless {
providerBar.SetTotal(showCount, false)
}
a.SubmitDownload(ctx, &wg, p, m, pc, providerBar)
} else {
a.logger.Trace().Printf("[%s] %s already downloaded.", p.Name(), mediaBasePath)
a.logger.Trace().Printf("[%s] %s already downloaded.", p.Name(), mediaBaseName)
}
if ctx.Err() != nil {
a.logger.Debug().Printf("[%s] PullShows received %s", p.Name(), ctx.Err())
Expand All @@ -436,13 +445,13 @@ showLoop:

// MustDownload check if the show isn't yet downloaded.
func (a *app) MustDownload(ctx context.Context, p providers.Provider, m *providers.Media) bool {
mediaPath := m.Metadata.GetMediaPath(m.Match.ShowRootPath)
mediaPath := m.Metadata.GetMediaPath(m.ShowPath)
mediaExists, err := fileExists(mediaPath)
if mediaExists {
return false
}

mediaPath = m.Metadata.GetMediaPathMatcher(m.Match.ShowRootPath)
mediaPath = m.Metadata.GetMediaPathMatcher(m.ShowPath)
files, err := filepath.Glob(mediaPath)
if err != nil {
log.Fatalf("Can't glob %s: %v", mediaPath, err)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -14,6 +14,7 @@ require (
github.com/gocolly/colly v1.2.0
github.com/golang/protobuf v1.3.2 // indirect
github.com/google/go-cmp v0.4.0
github.com/jawher/mow.cli v1.2.0 // indirect
github.com/kennygrant/sanitize v1.2.4 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca // indirect
Expand All @@ -26,5 +27,4 @@ require (
golang.org/x/sys v0.0.0-20190904005037-43c01164e931 // indirect
google.golang.org/appengine v1.6.2 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/yaml.v2 v2.2.4 // indirect
)
9 changes: 9 additions & 0 deletions go.sum
Expand Up @@ -29,10 +29,13 @@ github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/jawher/mow.cli v1.2.0 h1:e6ViPPy+82A/NFF/cfbq3Lr6q4JHKT9tyHwTCcUQgQw=
github.com/jawher/mow.cli v1.2.0/go.mod h1:y+pcA3jBAdo/GIZx/0rFjw/K2bVEODP9rfZOfaiq8Ko=
github.com/kennygrant/sanitize v1.2.4 h1:gN25/otpP5vAsO2djbMhF/LQX6R7+O1TB4yv8NzpJ3o=
github.com/kennygrant/sanitize v1.2.4/go.mod h1:LGsjYYtgxbetdg5owWB2mpgUL6e2nfw2eObZ0u0qvak=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
Expand All @@ -42,7 +45,10 @@ github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca h1:NugYot0LIVPxT
github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca/go.mod h1:uugorj2VCxiV1x+LzaIdVa9b4S4qGAcH6cbhh4qVxOU=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
Expand Down Expand Up @@ -75,6 +81,7 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b h1:mSUCVIwDx4hfXJfWsOPfdzEHxzb2Xjl6BQ8YgPnazQA=
golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand All @@ -87,3 +94,5 @@ gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.5 h1:ymVxjfMaHvXD8RqPRmzHHsB3VvucivSkIAvJFDI5O3c=
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
19 changes: 10 additions & 9 deletions metadata/nfo/episodedetails.go
Expand Up @@ -23,18 +23,18 @@ func (n *EpisodeDetails) GetMediaInfo() *MediaInfo {
}

// getSeasonPath give the path for the series' season
func (n *EpisodeDetails) getSeasonPath(destination string) string {
func (n *EpisodeDetails) getSeasonPath() string {
season := "Season "
if n.Season <= 0 {
season += "00"
} else {
season += fmt.Sprintf("%02d", n.Season)
}
return filepath.Join(destination, season)
return season
}

// GetMediaPath gives the full filename of given media
func (n EpisodeDetails) GetMediaPath(destination string) string {
func (n EpisodeDetails) GetMediaPath(showPath string) string {
cleanTitle := FileNameCleaner(n.Title)
cleanShow := FileNameCleaner(n.Showtitle)
var episode string
Expand All @@ -44,11 +44,11 @@ func (n EpisodeDetails) GetMediaPath(destination string) string {
episode = n.Aired.Time().Format("2006-01-02")
}
if cleanTitle == "" {
return filepath.Join(n.getSeasonPath(destination), cleanShow+" - "+episode+".mp4")
return filepath.Join(showPath, n.getSeasonPath(), cleanShow+" - "+episode+".mp4")

}

return filepath.Join(n.getSeasonPath(destination), cleanShow+" - "+episode+" - "+cleanTitle+".mp4")
return filepath.Join(showPath, n.getSeasonPath(), cleanShow+" - "+episode+" - "+cleanTitle+".mp4")
}

// Accepted check if ShowTitle or episode Title matches the filter
Expand All @@ -74,20 +74,21 @@ func (n EpisodeDetails) Accepted(m *matcher.MatchRequest) bool {
}

// GetMediaPathMatcher gives a name matcher for mis numbered episodes
func (n EpisodeDetails) GetMediaPathMatcher(destination string) string {
func (n EpisodeDetails) GetMediaPathMatcher(showPath string) string {
cleanTitle := FileNameCleaner(n.Title)
cleanShow := FileNameCleaner(n.Showtitle)
return filepath.Join(destination, "*", cleanShow+" - * - "+cleanTitle+".mp4")
return filepath.Join(showPath, "*", cleanShow+" - * - "+cleanTitle+".mp4")

}

// GetNFOPath give the path where the episode's NFO should be
func (n EpisodeDetails) GetNFOPath(destination string) string {
nf := n.GetMediaPath(destination)
func (n EpisodeDetails) GetNFOPath(showPath string) string {
nf := n.GetMediaPath(showPath)
return strings.TrimSuffix(nf, filepath.Ext(nf)) + ".nfo"
}

// WriteNFO file at expected place
// TODO remove destination and get it from show path
func (n *EpisodeDetails) WriteNFO(destination string) error {
err := os.MkdirAll(filepath.Dir(destination), 0777)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions metadata/nfo/nfo.go
Expand Up @@ -54,6 +54,7 @@ type MediaInfo struct {
IsSpecial bool `xml:"-"` // True when special episode
SeasonInfo *Season `xml:"-"` // Possible Season nfo
TVShow *TVShow `xml:"-"` // Possible TVShow nfo
IsDetailed bool `xml:"-"` // True when details have been retrieved
}

// Aired type helper
Expand Down

0 comments on commit da9cb1c

Please sign in to comment.