Skip to content

Commit

Permalink
fix: name cannot parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-ding committed Jul 24, 2024
1 parent f4b8d03 commit 16ca00d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
18 changes: 9 additions & 9 deletions pkg/metadata/tv.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
)

type Metadata struct {
NameEn string
NameCn string
Season int
Episode int
Resolution string
NameEn string
NameCn string
Season int
Episode int
Resolution string
IsSeasonPack bool
}

Expand Down Expand Up @@ -158,9 +158,9 @@ func parseChineseName(name string) *Metadata {
re3 := regexp.MustCompile(`[^\d\w]\d{1,2}[^\d\w]`)
epNums := re3.FindAllString(name, -1)
if len(epNums) > 0 {

re3 := regexp.MustCompile(`\d{1,2}`)
epNum := re3.FindAllString(epNums[0],-1)[0]
epNum := re3.FindAllString(epNums[0], -1)[0]
n, err := strconv.Atoi(epNum)
if err != nil {
panic(fmt.Sprintf("convert %s error: %v", epNum, err))
Expand Down Expand Up @@ -203,10 +203,10 @@ func parseChineseName(name string) *Metadata {
}
}

if meta.IsSeasonPack && meta.Episode != 0{
if meta.IsSeasonPack && meta.Episode != 0 {
meta.Season = meta.Episode
meta.Episode = -1
}
}

//tv name
title := name
Expand Down
4 changes: 2 additions & 2 deletions pkg/torznab/torznab.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (r *Response) ToResults() []Result {
for _, item := range r.Channel.Item {
r := Result{
Name: item.Title,
Magnet: item.Link,
Link: item.Link,
Size: mustAtoI(item.Size),
Seeders: mustAtoI(item.GetAttr("seeders")),
Peers: mustAtoI(item.GetAttr("peers")),
Expand Down Expand Up @@ -129,7 +129,7 @@ func Search(torznabUrl, api, keyWord string) ([]Result, error) {

type Result struct {
Name string
Magnet string
Link string
Size int
Seeders int
Peers int
Expand Down
4 changes: 2 additions & 2 deletions pkg/transmission/transmission.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ type Client struct {
cfg Config
}

func (c *Client) Download(magnet, dir string) (*Torrent, error) {
func (c *Client) Download(link, dir string) (*Torrent, error) {
t, err := c.c.TorrentAdd(context.TODO(), transmissionrpc.TorrentAddPayload{
Filename: &magnet,
Filename: &link,
DownloadDir: &dir,
})
log.Infof("get torrent info: %+v", t)
Expand Down
5 changes: 4 additions & 1 deletion server/core/torrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ func SearchEpisode(db1 *db.Client, seriesId, seasonNum, episodeNum int, checkRes

var filtered []torznab.Result
for _, r := range res {
log.Infof("torrent resource: %+v", r)
//log.Infof("torrent resource: %+v", r)
meta := metadata.ParseTv(r.Name)
if meta == nil { //cannot parse name
continue
}
if meta.Season != seasonNum {
continue
}
Expand Down
8 changes: 4 additions & 4 deletions server/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (s *Server) searchAndDownloadSeasonPackage(seriesId, seasonNum int) (*strin
return nil, errors.New("no enough space")
}

torrent, err := trc.Download(r1.Magnet, s.db.GetDownloadDir())
torrent, err := trc.Download(r1.Link, s.db.GetDownloadDir())
if err != nil {
return nil, errors.Wrap(err, "downloading")
}
Expand Down Expand Up @@ -144,7 +144,7 @@ func (s *Server) searchAndDownload(seriesId, seasonNum, episodeNum int) (*string
}
r1 := res[0]
log.Infof("found resource to download: %+v", r1)
torrent, err := trc.Download(r1.Magnet, s.db.GetDownloadDir())
torrent, err := trc.Download(r1.Link, s.db.GetDownloadDir())
if err != nil {
return nil, errors.Wrap(err, "downloading")
}
Expand Down Expand Up @@ -195,7 +195,7 @@ func (s *Server) SearchAvailableEpisodeResource(c *gin.Context) (interface{}, er
Size: r.Size,
Seeders: r.Seeders,
Peers: r.Peers,
Link: r.Magnet,
Link: r.Link,
})
}
if len(searchResults) == 0 {
Expand Down Expand Up @@ -268,7 +268,7 @@ func (s *Server) SearchAvailableMovies(c *gin.Context) (interface{}, error) {
Size: r.Size,
Seeders: r.Seeders,
Peers: r.Peers,
Link: r.Magnet,
Link: r.Link,
})
}
if len(searchResults) == 0 {
Expand Down
2 changes: 1 addition & 1 deletion server/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func (s *Server) downloadMovieSingleEpisode(ep *ent.Episode) error {
}
r1 := res[0]
log.Infof("begin download torrent resource: %v", r1.Name)
torrent, err := trc.Download(r1.Magnet, s.db.GetDownloadDir())
torrent, err := trc.Download(r1.Link, s.db.GetDownloadDir())
if err != nil {
return errors.Wrap(err, "downloading")
}
Expand Down

0 comments on commit 16ca00d

Please sign in to comment.