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.Title = eDB.Title
pEpisode.Rating = eDB.Rating pEpisode.Rating = eDB.Rating
pEpisode.Plot = eDB.Plot pEpisode.Plot = eDB.Plot
pEpisode.Thumb = eDB.Thumb
pEpisode.Runtime = eDB.Runtime pEpisode.Runtime = eDB.Runtime
pEpisode.Aired = eDB.Aired pEpisode.Aired = eDB.Aired
pEpisode.Thumb = imageURL(fmt.Sprintf( pEpisode.Thumb = imageURL(fmt.Sprintf(

View File

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

View File

@ -9,7 +9,8 @@ import (
// TorrentVideo reprensents a torrent embeding the video inforamtions // TorrentVideo reprensents a torrent embeding the video inforamtions
type TorrentVideo struct { type TorrentVideo struct {
*polochon.Torrent *polochon.Torrent
Img string `json:"img"` Thumb string `json:"thumb"`
Fanart string `json:"fanart"`
Video polochon.Video `json:"video,omitempty"` Video polochon.Video `json:"video,omitempty"`
} }
@ -47,11 +48,13 @@ func (t *TorrentVideo) Update(detailer polochon.Detailer, db *sqlx.DB, log *logr
if err := GetShow(db, v.Show); err != nil { if err := GetShow(db, v.Show); err != nil {
return return
} }
t.Img = v.Show.Poster t.Fanart = v.Show.Fanart
t.Thumb = v.Show.Poster
v.Show = nil v.Show = nil
} }
case *polochon.Movie: 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 // 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 { if err != nil {
log.Errorf("got error trying to download the poster %q", err) 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 // imgURL returns the default image url
func (m *Movie) imgURL() string { func (m *Movie) imgURL(imgType string) string {
return fmt.Sprintf("movies/%s.jpg", m.ImdbID) 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 // imgFile returns the image location on disk
func (m *Movie) imgFile() string { func (m *Movie) imgFile(imgType string) string {
return filepath.Join(models.PublicDir, "img", m.imgURL()) return filepath.Join(models.PublicDir, "img", m.imgURL(imgType))
} }
// getPolochonMovies returns an array of the user's polochon movies // getPolochonMovies returns an array of the user's polochon movies

View File

@ -172,22 +172,22 @@ func (s *Show) downloadImages(env *web.Env) {
for _, img := range []struct { for _, img := range []struct {
url string url string
urlType string urlType string
scale bool maxWidth uint
}{ }{
{ {
url: s.Show.Banner, url: s.Show.Banner,
urlType: "banner", urlType: "banner",
scale: false, maxWidth: 0,
}, },
{ {
url: s.Show.Fanart, url: s.Show.Fanart,
urlType: "fanart", urlType: "fanart",
scale: false, maxWidth: 960,
}, },
{ {
url: s.Show.Poster, url: s.Show.Poster,
urlType: "poster", urlType: "poster",
scale: true, maxWidth: 300,
}, },
} { } {
if img.url == "" { if img.url == "" {
@ -197,7 +197,7 @@ func (s *Show) downloadImages(env *web.Env) {
if _, err := os.Stat(s.imgFile(img.urlType)); err == nil { if _, err := os.Stat(s.imgFile(img.urlType)); err == nil {
continue 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) env.Log.Errorf("failed to dowload %s: %s", img.urlType, err)
} }
} }
@ -214,7 +214,7 @@ func (s *Show) downloadImages(env *web.Env) {
continue continue
} }
err := web.Download(e.Thumb, fileName, false) err := web.Download(e.Thumb, fileName, 0)
if err != nil { 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) 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 // 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 { if err := createDirectory(dest); err != nil {
return err return err
} }
@ -36,8 +36,8 @@ var Download = func(srcURL, dest string, scale bool) error {
return err return err
} }
if scale { if maxWidth != 0 {
image = resize.Resize(300, 0, image, resize.Lanczos3) image = resize.Resize(maxWidth, 0, image, resize.Lanczos3)
} }
// Create the file // Create the file

View File

@ -1,17 +1,27 @@
import React from "react"; import React from "react";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
export const Poster = ({ url }) => { export const Poster = ({ thumb, fanart }) => {
if (!url || url === "") { if (thumb === "" && fanart === "") {
return null; return null;
} }
return ( return (
<div className="col-md-2 d-none d-md-block"> <div className="col-md-2">
<img className="card-img" src={url} /> {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> </div>
); );
}; };
Poster.propTypes = { 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 ( return (
<div className="w-100 mb-3 card"> <div className="w-100 mb-3 card">
<div className="row no-gutters"> <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="col-sm">
<div className="card-body"> <div className="card-body">
<h4 className="card-title">{title(torrents[0])}</h4> <h4 className="card-title">{title(torrents[0])}</h4>