mirror of
https://github.com/simon-ding/polaris.git
synced 2026-03-05 09:00:45 +08:00
feat: imdbid support
This commit is contained in:
7
db/db.go
7
db/db.go
@@ -138,6 +138,7 @@ func (c *Client) AddMediaWatchlist(m *ent.Media, episodes []int) (*ent.Media, er
|
||||
}
|
||||
r, err := c.ent.Media.Create().
|
||||
SetTmdbID(m.TmdbID).
|
||||
SetImdbID(m.ImdbID).
|
||||
SetStorageID(m.StorageID).
|
||||
SetOverview(m.Overview).
|
||||
SetNameCn(m.NameCn).
|
||||
@@ -560,9 +561,9 @@ func (c *Client) SetEpisodeMonitoring(id int, b bool) error {
|
||||
}
|
||||
|
||||
type EditMediaData struct {
|
||||
ID int `json:"id"`
|
||||
Resolution media.Resolution `json:"resolution"`
|
||||
TargetDir string `json:"target_dir"`
|
||||
ID int `json:"id"`
|
||||
Resolution media.Resolution `json:"resolution"`
|
||||
TargetDir string `json:"target_dir"`
|
||||
Limiter schema.MediaLimiter `json:"limiter"`
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ func NewClient(apiKey, proxyUrl string) (*Client, error) {
|
||||
}
|
||||
|
||||
func (c *Client) GetTvDetails(id int, language string) (*tmdb.TVDetails, error) {
|
||||
d, err := c.tmdbClient.GetTVDetails(id, withLangOption(language))
|
||||
d, err := c.tmdbClient.GetTVDetails(id, withExternalIDs(withLangOption(language)))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "get tv detail")
|
||||
}
|
||||
@@ -58,7 +58,7 @@ func (c *Client) GetTvDetails(id int, language string) (*tmdb.TVDetails, error)
|
||||
log.Debug("should fetch english version")
|
||||
var detailEN *tmdb.TVDetails
|
||||
if language == "zh-CN" {
|
||||
detailEN, err = c.tmdbClient.GetTVDetails(id, withLangOption("en-US"))
|
||||
detailEN, err = c.tmdbClient.GetTVDetails(id, withExternalIDs(withLangOption("en-US")))
|
||||
if err != nil {
|
||||
return d, nil
|
||||
}
|
||||
@@ -75,7 +75,7 @@ func (c *Client) GetTvDetails(id int, language string) (*tmdb.TVDetails, error)
|
||||
}
|
||||
|
||||
func (c *Client) GetMovieDetails(id int, language string) (*tmdb.MovieDetails, error) {
|
||||
return c.tmdbClient.GetMovieDetails(id, withLangOption(language))
|
||||
return c.tmdbClient.GetMovieDetails(id, withExternalIDs(withLangOption(language)))
|
||||
}
|
||||
|
||||
func (c *Client) SearchTvShow(query string, lang string) (*tmdb.SearchTVShows, error) {
|
||||
@@ -211,6 +211,11 @@ func wrapLanguage(lang string) string {
|
||||
return lang
|
||||
}
|
||||
|
||||
func withExternalIDs(m map[string]string) map[string]string {
|
||||
m["append_to_response"] = "external_ids"
|
||||
return m
|
||||
}
|
||||
|
||||
func withLangOption(language string) map[string]string {
|
||||
language = wrapLanguage(language)
|
||||
return map[string]string{
|
||||
|
||||
@@ -36,9 +36,13 @@ func (c *Client) writePlexmatch(seriesId int, episodeId int, targetDir, name str
|
||||
_, err = st.ReadFile(filepath.Join(series.TargetDir, ".plexmatch"))
|
||||
if err != nil {
|
||||
//create new
|
||||
buff := bytes.Buffer{}
|
||||
if series.ImdbID != "" {
|
||||
buff.WriteString(fmt.Sprintf("imdbid: %d\n", series.ImdbID))
|
||||
}
|
||||
buff.WriteString(fmt.Sprintf("tmdbid: %d\n", series.TmdbID))
|
||||
log.Warnf(".plexmatch file not found, create new one: %s", series.NameEn)
|
||||
if err := st.WriteFile(filepath.Join(series.TargetDir, ".plexmatch"),
|
||||
[]byte(fmt.Sprintf("tmdbid: %d\n", series.TmdbID))); err != nil {
|
||||
if err := st.WriteFile(filepath.Join(series.TargetDir, ".plexmatch"), buff.Bytes()); err != nil {
|
||||
return errors.Wrap(err, "series plexmatch")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,6 +139,7 @@ func (s *Server) AddTv2Watchlist(c *gin.Context) (interface{}, error) {
|
||||
}
|
||||
m := &ent.Media{
|
||||
TmdbID: int(detail.ID),
|
||||
ImdbID: detail.IMDbID,
|
||||
MediaType: media.MediaTypeTv,
|
||||
NameCn: nameCn,
|
||||
NameEn: nameEn,
|
||||
@@ -210,6 +211,7 @@ func (s *Server) AddMovie2Watchlist(c *gin.Context) (interface{}, error) {
|
||||
|
||||
r, err := s.db.AddMediaWatchlist(&ent.Media{
|
||||
TmdbID: int(detail.ID),
|
||||
ImdbID: detail.IMDbID,
|
||||
MediaType: media.MediaTypeMovie,
|
||||
NameCn: nameCn,
|
||||
NameEn: nameEn,
|
||||
|
||||
Reference in New Issue
Block a user