Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update #3

Merged
merged 2 commits into from
May 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
39 changes: 20 additions & 19 deletions addicted.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
},
Expand Down Expand Up @@ -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
}
Expand Down
11 changes: 11 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)
20 changes: 20 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=