mirror of
https://github.com/simon-ding/polaris.git
synced 2026-02-06 23:21:00 +08:00
feat: add import list & calendar
This commit is contained in:
31
pkg/importlist/douban/douban.go
Normal file
31
pkg/importlist/douban/douban.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package douban
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
)
|
||||
|
||||
type DoulistItem struct {
|
||||
Name string
|
||||
ImdbID string
|
||||
}
|
||||
|
||||
func ParseDoulist(doulistUrl string) ([]DoulistItem, error) {
|
||||
res, err := http.Get(doulistUrl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("status code error: %d %s", res.StatusCode, res.Status)
|
||||
|
||||
}
|
||||
doc, err := goquery.NewDocumentFromReader(res.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
doc.Find("")
|
||||
return nil, nil
|
||||
}
|
||||
12
pkg/importlist/importlist.go
Normal file
12
pkg/importlist/importlist.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package importlist
|
||||
|
||||
type Item struct {
|
||||
Title string
|
||||
ImdbID string
|
||||
TvdbID string
|
||||
TmdbID string
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
Items []Item
|
||||
}
|
||||
96
pkg/importlist/plexwatchlist/plex.go
Normal file
96
pkg/importlist/plexwatchlist/plex.go
Normal file
@@ -0,0 +1,96 @@
|
||||
package plexwatchlist
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"io"
|
||||
"net/http"
|
||||
"polaris/pkg/importlist"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
XMLName xml.Name `xml:"rss"`
|
||||
Text string `xml:",chardata"`
|
||||
Atom string `xml:"atom,attr"`
|
||||
Media string `xml:"media,attr"`
|
||||
Version string `xml:"version,attr"`
|
||||
Channel struct {
|
||||
Text string `xml:",chardata"`
|
||||
Title string `xml:"title"`
|
||||
Link struct {
|
||||
Text string `xml:",chardata"`
|
||||
Href string `xml:"href,attr"`
|
||||
Rel string `xml:"rel,attr"`
|
||||
Type string `xml:"type,attr"`
|
||||
} `xml:"link"`
|
||||
Description string `xml:"description"`
|
||||
Category string `xml:"category"`
|
||||
Item []struct {
|
||||
Text string `xml:",chardata"`
|
||||
Title string `xml:"title"`
|
||||
PubDate string `xml:"pubDate"`
|
||||
Link string `xml:"link"`
|
||||
Description string `xml:"description"`
|
||||
Category string `xml:"category"`
|
||||
Credit []struct {
|
||||
Text string `xml:",chardata"`
|
||||
Role string `xml:"role,attr"`
|
||||
} `xml:"credit"`
|
||||
Thumbnail struct {
|
||||
Text string `xml:",chardata"`
|
||||
URL string `xml:"url,attr"`
|
||||
} `xml:"thumbnail"`
|
||||
Keywords string `xml:"keywords"`
|
||||
Rating struct {
|
||||
Text string `xml:",chardata"`
|
||||
Scheme string `xml:"scheme,attr"`
|
||||
} `xml:"rating"`
|
||||
Guid struct {
|
||||
Text string `xml:",chardata"`
|
||||
IsPermaLink string `xml:"isPermaLink,attr"`
|
||||
} `xml:"guid"`
|
||||
} `xml:"item"`
|
||||
} `xml:"channel"`
|
||||
}
|
||||
|
||||
func (r *Response) convert() *importlist.Response {
|
||||
res := &importlist.Response{}
|
||||
for _, im := range r.Channel.Item {
|
||||
item := importlist.Item{
|
||||
Title: im.Title,
|
||||
}
|
||||
id := strings.ToLower(im.Guid.Text)
|
||||
if strings.HasPrefix(id, "tvdb") {
|
||||
tvdbid := strings.TrimPrefix(id, "tvdb://")
|
||||
item.TvdbID = tvdbid
|
||||
} else if strings.HasPrefix(id, "imdb") {
|
||||
imdbid := strings.TrimPrefix(id, "imdb://")
|
||||
item.ImdbID = imdbid
|
||||
} else if strings.HasPrefix(id, "tmdb") {
|
||||
tmdbid := strings.TrimPrefix(id, "tmdb://")
|
||||
item.TmdbID = tmdbid
|
||||
}
|
||||
res.Items = append(res.Items, item)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func ParsePlexWatchlist(url string) (*importlist.Response, error) {
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "http get")
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
data, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "read data")
|
||||
}
|
||||
var rrr Response
|
||||
err = xml.Unmarshal(data, &rrr)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "xml")
|
||||
}
|
||||
return rrr.convert(), nil
|
||||
}
|
||||
@@ -213,6 +213,19 @@ func (c *Client) GetMovieAlternativeTitles(id int, language string) (*tmdb.Movie
|
||||
return c.tmdbClient.GetMovieAlternativeTitles(id, withLangOption(language))
|
||||
}
|
||||
|
||||
func (c *Client) GetByImdbId(imdbId string, lang string)(*tmdb.FindByID, error) {
|
||||
m := withLangOption(lang)
|
||||
m["external_source"] = "imdb_id"
|
||||
return c.tmdbClient.GetFindByID(imdbId, m)
|
||||
}
|
||||
|
||||
func (c *Client) GetByTvdbId(imdbId string, lang string)(*tmdb.FindByID, error) {
|
||||
m := withLangOption(lang)
|
||||
m["external_source"] = "tvdb_id"
|
||||
return c.tmdbClient.GetFindByID(imdbId, m)
|
||||
}
|
||||
|
||||
|
||||
|
||||
func wrapLanguage(lang string) string {
|
||||
if lang == "" {
|
||||
|
||||
Reference in New Issue
Block a user