-
Notifications
You must be signed in to change notification settings - Fork 9
/
gulli.go
91 lines (78 loc) · 2.48 KB
/
gulli.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package gulli
import (
"io"
"log"
"path/filepath"
"github.com/simulot/aspiratv/net/http"
"github.com/simulot/aspiratv/parsers/htmlparser"
"github.com/simulot/aspiratv/providers"
)
type getter interface {
Get(uri string) (io.Reader, error)
}
type Gulli struct {
getter getter
htmlParserFactory *htmlparser.Factory
seenShows map[string]bool
debug bool
}
// init registers Gulli provider
func init() {
p, err := New()
if err != nil {
panic(err)
}
providers.Register(p)
}
func New(conf ...func(p *Gulli)) (*Gulli, error) {
p := &Gulli{
getter: http.DefaultClient,
htmlParserFactory: htmlparser.NewFactory(),
seenShows: map[string]bool{},
}
return p, nil
}
// SetDebug set debug mode
func (p *Gulli) SetDebug(b bool) {
p.debug = b
}
// Name return the name of the provider
func (p Gulli) Name() string { return "gulli" }
// Shows download the shows catalog from the web site.
func (p *Gulli) Shows(mm []*providers.MatchRequest) ([]*providers.Show, error) {
shows := []*providers.Show{}
log.Print("[gulli] Fetch Gulli's new shows")
shows, err := p.getAll(mm)
if err != nil {
return nil, err
}
return shows, err
}
// GetShowStreamURL return the show's URL, a mp4 file
func (p *Gulli) GetShowStreamURL(s *providers.Show) (string, error) {
return s.StreamURL, nil
}
// GetShowInfo gather show information from dedicated web page.
// It load the html page of the show to extract availability date used as airdate and production year as season
func (p *Gulli) GetShowInfo(s *providers.Show) error {
return nil
}
// GetShowFileName return a file name with a path that is compatible with PLEX server:
// ShowName/Season NN/ShowName - sNNeMM - Episode title
// Show and Episode names are sanitized to avoid problem when saving on the file system
func (p *Gulli) GetShowFileName(s *providers.Show) string {
return filepath.Join(
providers.PathNameCleaner(s.Show),
"Season "+providers.Format2Digits(s.Season),
providers.FileNameCleaner(s.Show)+" - s"+providers.Format2Digits(s.Season)+"e"+providers.Format2Digits(s.Episode)+" - "+providers.FileNameCleaner(s.Title)+".mp4",
)
}
// GetShowFileNameMatcher return a file pattern of this show
// used for detecting already got episode even when episode or season is different
func (Gulli) GetShowFileNameMatcher(s *providers.Show) string {
return filepath.Join(
providers.PathNameCleaner(s.Show),
"*",
providers.FileNameCleaner(s.Show)+" - * - "+providers.FileNameCleaner(s.Title)+".mp4",
)
}