Stuff stuff stuff #44

Merged
PouuleT merged 24 commits from update-node into master 2021-08-30 12:59:08 +00:00
8 changed files with 58 additions and 33 deletions
Showing only changes of commit d585a59c83 - Show all commits

View File

@ -84,7 +84,6 @@ func FillEpisodeFromDB(eDB *episodeDB, pEpisode *polochon.ShowEpisode) {
pEpisode.Title = eDB.Title
pEpisode.Rating = eDB.Rating
pEpisode.Plot = eDB.Plot
pEpisode.Thumb = eDB.Thumb
pEpisode.Runtime = eDB.Runtime
pEpisode.Aired = eDB.Aired
pEpisode.Thumb = imageURL(fmt.Sprintf(

View File

@ -90,6 +90,7 @@ func FillMovieFromDB(mDB *movieDB, pMovie *polochon.Movie) {
pMovie.SortTitle = mDB.SortTitle
pMovie.Tagline = mDB.Tagline
pMovie.Thumb = imageURL("movies/" + mDB.ImdbID + ".jpg")
pMovie.Fanart = imageURL("movies/" + mDB.ImdbID + "-fanart.jpg")
}
// updateFromMovie will update the movieDB from a Movie

View File

@ -9,8 +9,9 @@ import (
// TorrentVideo reprensents a torrent embeding the video inforamtions
type TorrentVideo struct {
*polochon.Torrent
Img string `json:"img"`
Video polochon.Video `json:"video,omitempty"`
Thumb string `json:"thumb"`
Fanart string `json:"fanart"`
Video polochon.Video `json:"video,omitempty"`
}
// NewTorrentVideo returns a new TorrentVideo
@ -47,11 +48,13 @@ func (t *TorrentVideo) Update(detailer polochon.Detailer, db *sqlx.DB, log *logr
if err := GetShow(db, v.Show); err != nil {
return
}
t.Img = v.Show.Poster
t.Fanart = v.Show.Fanart
t.Thumb = v.Show.Poster
v.Show = nil
}
case *polochon.Movie:
t.Img = v.Thumb
t.Thumb = v.Thumb
t.Fanart = v.Fanart
}
}

View File

@ -150,7 +150,13 @@ func (m *Movie) Refresh(env *web.Env, detailers []polochon.Detailer) error {
}
// Download poster
err = web.Download(m.Thumb, m.imgFile(), true)
err = web.Download(m.Thumb, m.imgFile("thumb"), 300)
if err != nil {
log.Errorf("got error trying to download the poster %q", err)
}
// Download fanart
err = web.Download(m.Fanart, m.imgFile("fanart"), 960)
if err != nil {
log.Errorf("got error trying to download the poster %q", err)
}
@ -237,13 +243,19 @@ func (m *Movie) RefreshTorrents(env *web.Env, torrenters []polochon.Torrenter) e
}
// imgURL returns the default image url
func (m *Movie) imgURL() string {
return fmt.Sprintf("movies/%s.jpg", m.ImdbID)
func (m *Movie) imgURL(imgType string) string {
var location string
if imgType == "thumb" {
location = m.ImdbID
} else {
location = m.ImdbID + "-" + imgType
}
return fmt.Sprintf("movies/%s.jpg", location)
}
// imgFile returns the image location on disk
func (m *Movie) imgFile() string {
return filepath.Join(models.PublicDir, "img", m.imgURL())
func (m *Movie) imgFile(imgType string) string {
return filepath.Join(models.PublicDir, "img", m.imgURL(imgType))
}
// getPolochonMovies returns an array of the user's polochon movies

View File

@ -170,24 +170,24 @@ func (s *Show) downloadImages(env *web.Env) {
}
// Download the show images
for _, img := range []struct {
url string
urlType string
scale bool
url string
urlType string
maxWidth uint
}{
{
url: s.Show.Banner,
urlType: "banner",
scale: false,
url: s.Show.Banner,
urlType: "banner",
maxWidth: 0,
},
{
url: s.Show.Fanart,
urlType: "fanart",
scale: false,
url: s.Show.Fanart,
urlType: "fanart",
maxWidth: 960,
},
{
url: s.Show.Poster,
urlType: "poster",
scale: true,
url: s.Show.Poster,
urlType: "poster",
maxWidth: 300,
},
} {
if img.url == "" {
@ -197,7 +197,7 @@ func (s *Show) downloadImages(env *web.Env) {
if _, err := os.Stat(s.imgFile(img.urlType)); err == nil {
continue
}
if err := web.Download(img.url, s.imgFile(img.urlType), img.scale); err != nil {
if err := web.Download(img.url, s.imgFile(img.urlType), img.maxWidth); err != nil {
env.Log.Errorf("failed to dowload %s: %s", img.urlType, err)
}
}
@ -214,7 +214,7 @@ func (s *Show) downloadImages(env *web.Env) {
continue
}
err := web.Download(e.Thumb, fileName, false)
err := web.Download(e.Thumb, fileName, 0)
if err != nil {
env.Log.Errorf("failed to dowload the thumb for season %d episode %d ( %s ) : %s", e.Season, e.Episode, e.Thumb, err)
}

View File

@ -13,7 +13,7 @@ import (
)
// Download used for downloading file
var Download = func(srcURL, dest string, scale bool) error {
var Download = func(srcURL, dest string, maxWidth uint) error {
if err := createDirectory(dest); err != nil {
return err
}
@ -36,8 +36,8 @@ var Download = func(srcURL, dest string, scale bool) error {
return err
}
if scale {
image = resize.Resize(300, 0, image, resize.Lanczos3)
if maxWidth != 0 {
image = resize.Resize(maxWidth, 0, image, resize.Lanczos3)
}
// Create the file

View File

@ -1,17 +1,27 @@
import React from "react";
import PropTypes from "prop-types";
export const Poster = ({ url }) => {
if (!url || url === "") {
export const Poster = ({ thumb, fanart }) => {
if (thumb === "" && fanart === "") {
return null;
}
return (
<div className="col-md-2 d-none d-md-block">
<img className="card-img" src={url} />
<div className="col-md-2">
{thumb !== "" && (
<img className="card-img d-none d-sm-block" src={thumb} />
)}
{fanart !== "" && (
<img className="card-img d-block d-sm-none" src={fanart} />
)}
</div>
);
};
Poster.propTypes = {
url: PropTypes.string,
thumb: PropTypes.string,
fanart: PropTypes.string,
};
Poster.defaultProps = {
thumb: "",
fanart: "",
};

View File

@ -28,7 +28,7 @@ export const TorrentGroup = ({ torrentKey }) => {
return (
<div className="w-100 mb-3 card">
<div className="row no-gutters">
<Poster url={torrents[0].img} />
<Poster thumb={torrents[0].thumb} fanart={torrents[0].fanart} />
<div className="col-sm">
<div className="card-body">
<h4 className="card-title">{title(torrents[0])}</h4>