From cc127a3cf92efbad828bcfef89d0a436331c947c Mon Sep 17 00:00:00 2001 From: Lucas BEE Date: Sun, 19 Apr 2020 20:02:29 +0200 Subject: [PATCH 1/2] Update addicted The page ajax_getShows page isn't working anymore, replace it with the index Reformat and static check --- addicted.go | 39 ++++++++++++++++++++------------------- go.mod | 11 +++++++++++ go.sum | 20 ++++++++++++++++++++ 3 files changed, 51 insertions(+), 19 deletions(-) create mode 100644 go.mod create mode 100644 go.sum diff --git a/addicted.go b/addicted.go index 1f13aed..8a9b6ca 100644 --- a/addicted.go +++ b/addicted.go @@ -20,24 +20,24 @@ import ( var ( baseURL = "http://www.addic7ed.com/" - reDownloadCount = regexp.MustCompile("(\\d+) Downloads") + reDownloadCount = regexp.MustCompile(`(\d+) Downloads`) xpathRelease = xmlpath.MustCompile("//div[@id=\"container95m\"]//td[@class=\"NewsTitle\"]") xpathLanguageFromRelease = xmlpath.MustCompile("../..//td[@class=\"language\"]") xpathDownloadFromLanguage = xmlpath.MustCompile("..//a[@class=\"buttonDownload\"]/@href") xpathDownloadCountFromLanguage = xmlpath.MustCompile("../following-sibling::tr[1]/td[1]") xpathCheckSubtilePage = xmlpath.MustCompile("//div[@id=\"container\"]") xpathCheckLogged = xmlpath.MustCompile("//a[@href=\"/logout.php\"]") - releaseRe = regexp.MustCompile("Version ([-\\(\\)\\.\\w]+),") + releaseRe = regexp.MustCompile(`Version ([-\(\)\.\w]+),`) //ErrNoCreditial returned when attempt to login without creditial set - ErrNoCreditial = errors.New("No creditial provided") + ErrNoCreditial = errors.New("no creditial provided") //ErrInvalidCredential returned when login failed - ErrInvalidCredential = errors.New("Invalid creditial") + ErrInvalidCredential = errors.New("invalid creditial") //ErrEpisodeNotFound returned when try to find subtitles for an unknow episode or season or show - ErrEpisodeNotFound = errors.New("Episode not found") + ErrEpisodeNotFound = errors.New("episode not found") //ErrUnexpectedContent returned when addic7ed's website seem to have change - ErrUnexpectedContent = errors.New("Unexpected content") + ErrUnexpectedContent = errors.New("unexpected content") // ErrDownloadLimit retuned when download limit by day exceeded - ErrDownloadLimit = errors.New("Download count exceeded") + ErrDownloadLimit = errors.New("download count exceeded") ) // Subtitle represents a subtitle @@ -131,7 +131,7 @@ func New() (*Client, error) { Name: "showScraper", Method: "GET", List: "select > option", - URL: baseURL + "ajax_getShows.php", + URL: baseURL, Headers: map[string]string{ "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2988.133 Safari/537.36", }, @@ -194,17 +194,18 @@ func (c *Client) connect() error { // GetTvShows returns a map of show's title as keys and ids as values func (c *Client) GetTvShows() (map[string]string, error) { - if len(c.shows) == 0 { - var err error - // Parse the page - res, err := c.showScraper.Execute(nil) - if err != nil { - return nil, err - } - c.shows = map[string]string{} - for _, r := range res { - c.shows[r["name"]] = r["id"] - } + if len(c.shows) > 0 { + return c.shows, nil + } + var err error + // Parse the page + res, err := c.showScraper.Execute(nil) + if err != nil { + return nil, err + } + c.shows = map[string]string{} + for _, r := range res { + c.shows[r["name"]] = r["id"] } return c.shows, nil } diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..62f6828 --- /dev/null +++ b/go.mod @@ -0,0 +1,11 @@ +module github.com/odwrtw/addicted + +go 1.14 + +require ( + github.com/jpillora/scraper v0.0.0-20190930150335-f06f890eb841 + github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect + golang.org/x/net v0.0.0-20200506145744-7e3656a0809f + gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect + gopkg.in/xmlpath.v2 v2.0.0-20150820204837-860cbeca3ebc +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..86d578f --- /dev/null +++ b/go.sum @@ -0,0 +1,20 @@ +github.com/PuerkitoBio/goquery v1.5.0/go.mod h1:qD2PgZ9lccMbQlc7eEOjaeRlFQON7xY8kdmcsrnKqMg= +github.com/andybalholm/cascadia v1.0.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y= +github.com/jpillora/opts v0.0.0-20160806153215-0b3373f6c34d/go.mod h1:8/sC6XyMKHq/ybiU9Oqc1i0tDjFA/6otW7+Ha/qtnfo= +github.com/jpillora/scraper v0.0.0-20190930150335-f06f890eb841/go.mod h1:rwZ1CpR9lO34N/3IDicjhl2N/jfe124j1zdwYJNjsEI= +github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20200506145744-7e3656a0809f h1:QBjCr1Fz5kw158VqdE9JfI9cJnl/ymnJWAdMuinqL7Y= +golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/xmlpath.v2 v2.0.0-20150820204837-860cbeca3ebc/go.mod h1:N8UOSI6/c2yOpa/XDz3KVUiegocTziPiqNkeNTMiG1k= From e7d95700c557e05b0d6924d2e9e990351d2ba888 Mon Sep 17 00:00:00 2001 From: Lucas BEE Date: Sat, 25 Apr 2020 17:53:29 +0200 Subject: [PATCH 2/2] Update README --- README.md | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 94486cb..e91881c 100644 --- a/README.md +++ b/README.md @@ -14,31 +14,37 @@ Usage "fmt" "io/ioutil" - "gitlab.quimbo.fr/nicolas/addicted" + "github.com/odwrtw/addicted" ) func main() { user := "username" passwd := "yourpassword" - addic, err := addicted.New(user, passwd) + // Create a client + addic, err := addicted.NewWithAuth(user, passwd) + // Or + // addic, err := addicted.New() - // t, err := addic.GetTvShows() + // Get the list of shows ( addicted has its own system of IDs ) + // shows, err := addic.GetTvShows() // if err != nil { - // fmt.Println(err) + // fmt.Println(err) // } - // fmt.Println(t) - - sub, err := addic.GetSubtitles("3103", 1, 1) + // Get the susbtitles ( House of cards S01E01 ) + subs, err := addic.GetSubtitles("3103", 1, 1) if err != nil { - fmt.Println(err) + fmt.Println(err) } - for i, s := range sub { - if s.Language == "French" { - fmt.Println(i) - } + + // Filter the results on the lang + subs = subs.FilterByLang("french") + + // Download it + subtitle, err := ioutil.ReadAll(&subs[0]) + if err != nil { + panic(err) } - subtitle, _ := ioutil.ReadAll(&sub[7]) ioutil.WriteFile("test.srt", subtitle, 0644) }