Skip to content

Commit

Permalink
refactor: reduce default poster image size to w500
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-ding committed Dec 11, 2024
1 parent 6698d36 commit 76a9183
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 9 deletions.
14 changes: 6 additions & 8 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package main
import (
"polaris/db"
"polaris/log"
"polaris/pkg/utils"
"polaris/server"
"time"
)

func main() {
Expand All @@ -18,13 +16,13 @@ func main() {
log.Panicf("init db error: %v", err)
}

go func() {
time.Sleep(2 * time.Second)
if err := utils.OpenURL("http://127.0.0.1:8080"); err != nil {
log.Errorf("open url error: %v", err)
}
// go func() {
// time.Sleep(2 * time.Second)
// if err := utils.OpenURL("http://127.0.0.1:8080"); err != nil {
// log.Errorf("open url error: %v", err)
// }

}()
// }()
s := server.NewServer(dbClient)
if err := s.Serve(); err != nil {
log.Errorf("server start error: %v", err)
Expand Down
1 change: 1 addition & 0 deletions server/core/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func (c *Client) registerCronJob(name string, cron string, f func() error) {
func (c *Client) Init() {
go c.reloadTasks()
c.addSysCron()
go c.checkW500PosterOnStartup()
}

func (c *Client) reloadTasks() {
Expand Down
53 changes: 53 additions & 0 deletions server/core/importlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ func (c *Client) AddTv2Watchlist(in AddWatchlistIn) (interface{}, error) {
if err := c.downloadPoster(detail.PosterPath, r.ID); err != nil {
log.Errorf("download poster error: %v", err)
}
if err := c.downloadW500Poster(detail.PosterPath, r.ID); err != nil {
log.Errorf("download w500 poster error: %v", err)
}

if err := c.downloadBackdrop(detail.BackdropPath, r.ID); err != nil {
log.Errorf("download poster error: %v", err)
}
Expand Down Expand Up @@ -301,6 +305,10 @@ func (c *Client) AddMovie2Watchlist(in AddWatchlistIn) (interface{}, error) {
if err := c.downloadPoster(detail.PosterPath, r.ID); err != nil {
log.Errorf("download poster error: %v", err)
}
if err := c.downloadW500Poster(detail.PosterPath, r.ID); err != nil {
log.Errorf("download w500 poster error: %v", err)
}

if err := c.downloadBackdrop(detail.BackdropPath, r.ID); err != nil {
log.Errorf("download backdrop error: %v", err)
}
Expand Down Expand Up @@ -372,6 +380,11 @@ func (c *Client) downloadPoster(path string, mediaID int) error {
return c.downloadImage(url, mediaID, "poster.jpg")
}

func (c *Client) downloadW500Poster(path string, mediaID int) error {
url := "https://image.tmdb.org/t/p/w500" + path
return c.downloadImage(url, mediaID, "poster_w500.jpg")
}

func (c *Client) downloadImage(url string, mediaID int, name string) error {

log.Infof("try to download image: %v", url)
Expand All @@ -397,6 +410,46 @@ func (c *Client) downloadImage(url string, mediaID int, name string) error {

}

func (c *Client) checkW500PosterOnStartup() {
log.Infof("check all w500 posters")
all := c.db.GetMediaWatchlist(media.MediaTypeTv)
movies := c.db.GetMediaWatchlist(media.MediaTypeMovie)
all = append(all, movies...)
for _, e := range all {
targetFile := filepath.Join(fmt.Sprintf("%v/%d", db.ImgPath, e.ID), "poster_w500.jpg")
if _, err := os.Stat(targetFile); err != nil {
log.Infof("poster_w500.jpg not exist for %s, will download it", e.NameEn)

if e.MediaType ==media.MediaTypeTv {
detail, err := c.MustTMDB().GetTvDetails(e.TmdbID, db.LanguageCN)
if err != nil {
log.Warnf("get tmdb detail for %s error: %v", e.NameEn, err)
continue
}

if err := c.downloadW500Poster(detail.PosterPath, e.ID); err != nil {
log.Warnf("download w500 poster error: %v", err)
continue
}

} else {
detail, err := c.MustTMDB().GetMovieDetails(e.TmdbID, db.LanguageCN)
if err != nil {
log.Warnf("get tmdb detail for %s error: %v", e.NameEn, err)
continue
}

if err := c.downloadW500Poster(detail.PosterPath, e.ID); err != nil {
log.Warnf("download w500 poster error: %v", err)
continue
}

}

}
}
}

func (c *Client) SuggestedMovieFolderName(tmdbId int) (string, error) {

d1, err := c.MustTMDB().GetMovieDetails(tmdbId, c.language)
Expand Down
2 changes: 1 addition & 1 deletion ui/lib/welcome_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class MediaCard extends StatelessWidget {
child: Ink.image(
fit: BoxFit.cover,
image: NetworkImage(
"${APIs.imagesUrl}/${item.id}/poster.jpg",
"${APIs.imagesUrl}/${item.id}/poster_w500.jpg",
)),
),
SizedBox(
Expand Down

0 comments on commit 76a9183

Please sign in to comment.