Compare commits

..

4 Commits

Author SHA1 Message Date
114f022b8d Fix empty torrents returned as array in show episodes
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
The show episodes can handle undefined values themselves.
2020-04-10 17:09:43 +02:00
83d1894a25 Fix torrent search on every keystroke
Cleanup the search results when leaving the page.
2020-04-10 17:09:43 +02:00
c9ecdac4f2 Add the torrent URL in the torrent button
This allows us to copy the link without clicking on the button.
2020-04-10 17:09:43 +02:00
3bd51765b8 Update papi and polochon to use the new torrent API 2020-04-10 17:09:43 +02:00
2 changed files with 22 additions and 22 deletions

View File

@ -25,8 +25,8 @@ const (
FROM episode_torrents WHERE imdb_id=$1 AND season=$2 AND episode=$3;` FROM episode_torrents WHERE imdb_id=$1 AND season=$2 AND episode=$3;`
) )
// EpisodeTorrentDB represents the EpisodeTorrent in the DB // episodeTorrentDB represents the EpisodeTorrent in the DB
type EpisodeTorrentDB struct { type episodeTorrentDB struct {
ID string `db:"id"` ID string `db:"id"`
ImdbID string `db:"imdb_id"` ImdbID string `db:"imdb_id"`
URL string `db:"url"` URL string `db:"url"`
@ -42,9 +42,9 @@ type EpisodeTorrentDB struct {
Updated time.Time `db:"updated_at"` Updated time.Time `db:"updated_at"`
} }
// NewTorrentFromEpisodeTorrentDB returns a polochon.Torrent from an // newTorrentFromEpisodeTorrentDB returns a polochon.Torrent from an
// EpisodeTorrentDB // EpisodeTorrentDB
func NewTorrentFromEpisodeTorrentDB(eDB *EpisodeTorrentDB) *polochon.Torrent { func newTorrentFromEpisodeTorrentDB(eDB *episodeTorrentDB) *polochon.Torrent {
return &polochon.Torrent{ return &polochon.Torrent{
ImdbID: eDB.ImdbID, ImdbID: eDB.ImdbID,
Type: polochon.TypeEpisode, Type: polochon.TypeEpisode,
@ -62,10 +62,10 @@ func NewTorrentFromEpisodeTorrentDB(eDB *EpisodeTorrentDB) *polochon.Torrent {
} }
} }
// NewEpisodeTorrentDB returns an EpisodeTorrentDB ready to be put in DB from a // newEpisodeTorrentDB returns an episodeTorrentDB ready to be put in DB from a
// polochon.Torrent // polochon.Torrent
func NewEpisodeTorrentDB(t *polochon.Torrent) *EpisodeTorrentDB { func newEpisodeTorrentDB(t *polochon.Torrent) *episodeTorrentDB {
e := &EpisodeTorrentDB{ e := &episodeTorrentDB{
ImdbID: t.ImdbID, ImdbID: t.ImdbID,
Quality: string(t.Quality), Quality: string(t.Quality),
Season: t.Season, Season: t.Season,
@ -87,7 +87,7 @@ func NewEpisodeTorrentDB(t *polochon.Torrent) *EpisodeTorrentDB {
// GetEpisodeTorrents returns show episodes torrents from database // GetEpisodeTorrents returns show episodes torrents from database
func GetEpisodeTorrents(db *sqlx.DB, imdbID string, season, episode int) ([]*polochon.Torrent, error) { func GetEpisodeTorrents(db *sqlx.DB, imdbID string, season, episode int) ([]*polochon.Torrent, error) {
var torrentsDB = []*EpisodeTorrentDB{} var torrentsDB = []*episodeTorrentDB{}
err := db.Select(&torrentsDB, getEpisodeTorrentQuery, imdbID, season, episode) err := db.Select(&torrentsDB, getEpisodeTorrentQuery, imdbID, season, episode)
if err != nil { if err != nil {
return nil, err return nil, err
@ -99,7 +99,7 @@ func GetEpisodeTorrents(db *sqlx.DB, imdbID string, season, episode int) ([]*pol
var torrents []*polochon.Torrent var torrents []*polochon.Torrent
for _, torrentDB := range torrentsDB { for _, torrentDB := range torrentsDB {
torrent := NewTorrentFromEpisodeTorrentDB(torrentDB) torrent := newTorrentFromEpisodeTorrentDB(torrentDB)
torrents = append(torrents, torrent) torrents = append(torrents, torrent)
} }
@ -109,7 +109,7 @@ func GetEpisodeTorrents(db *sqlx.DB, imdbID string, season, episode int) ([]*pol
// UpsertEpisodeTorrent upserts an episode torrent from a polochon torrent // UpsertEpisodeTorrent upserts an episode torrent from a polochon torrent
func UpsertEpisodeTorrent(db *sqlx.DB, torrent *polochon.Torrent) error { func UpsertEpisodeTorrent(db *sqlx.DB, torrent *polochon.Torrent) error {
// Create the EpisodeTorrent ready to be put in db // Create the EpisodeTorrent ready to be put in db
eDB := NewEpisodeTorrentDB(torrent) eDB := newEpisodeTorrentDB(torrent)
r, err := db.NamedQuery(upsertEpisodeTorrentQuery, eDB) r, err := db.NamedQuery(upsertEpisodeTorrentQuery, eDB)
if err != nil { if err != nil {
return err return err

View File

@ -24,8 +24,8 @@ const (
FROM movie_torrents WHERE imdb_id=$1;` FROM movie_torrents WHERE imdb_id=$1;`
) )
// MovieTorrentDB represents the MovieTorrent in the DB // movieTorrentDB represents the MovieTorrent in the DB
type MovieTorrentDB struct { type movieTorrentDB struct {
ID string `db:"id"` ID string `db:"id"`
ImdbID string `db:"imdb_id"` ImdbID string `db:"imdb_id"`
URL string `db:"url"` URL string `db:"url"`
@ -39,9 +39,9 @@ type MovieTorrentDB struct {
Updated time.Time `db:"updated_at"` Updated time.Time `db:"updated_at"`
} }
// NewTorrentFromMovieTorrentDB creates a new polochon.Torrent from a // newTorrentFromMovieTorrentDB creates a new polochon.Torrent from a
// MovieTorrentDB // movieTorrentDB
func NewTorrentFromMovieTorrentDB(mDB *MovieTorrentDB) *polochon.Torrent { func newTorrentFromMovieTorrentDB(mDB *movieTorrentDB) *polochon.Torrent {
return &polochon.Torrent{ return &polochon.Torrent{
ImdbID: mDB.ImdbID, ImdbID: mDB.ImdbID,
Quality: polochon.Quality(mDB.Quality), Quality: polochon.Quality(mDB.Quality),
@ -57,10 +57,10 @@ func NewTorrentFromMovieTorrentDB(mDB *MovieTorrentDB) *polochon.Torrent {
} }
} }
// NewMovieTorrentDB returns a MovieTorrent ready to be put in DB from a // newMovieTorrentDB returns a MovieTorrent ready to be put in DB from a
// Torrent // Torrent
func NewMovieTorrentDB(t *polochon.Torrent) MovieTorrentDB { func newMovieTorrentDB(t *polochon.Torrent) movieTorrentDB {
m := MovieTorrentDB{ m := movieTorrentDB{
ImdbID: t.ImdbID, ImdbID: t.ImdbID,
Quality: string(t.Quality), Quality: string(t.Quality),
} }
@ -80,7 +80,7 @@ func NewMovieTorrentDB(t *polochon.Torrent) MovieTorrentDB {
// GetMovieTorrents returns polochon.Torrents from the database // GetMovieTorrents returns polochon.Torrents from the database
func GetMovieTorrents(db *sqlx.DB, imdbID string) ([]*polochon.Torrent, error) { func GetMovieTorrents(db *sqlx.DB, imdbID string) ([]*polochon.Torrent, error) {
var torrentsDB = []*MovieTorrentDB{} var torrentsDB = []*movieTorrentDB{}
// Get the torrents from the DB // Get the torrents from the DB
err := db.Select(&torrentsDB, getMovieTorrentQueryByImdbID, imdbID) err := db.Select(&torrentsDB, getMovieTorrentQueryByImdbID, imdbID)
if err != nil { if err != nil {
@ -91,10 +91,10 @@ func GetMovieTorrents(db *sqlx.DB, imdbID string) ([]*polochon.Torrent, error) {
return nil, sql.ErrNoRows return nil, sql.ErrNoRows
} }
// Create polochon Torrents from the MovieTorrentDB // Create polochon Torrents from the movieTorrentDB
var torrents []*polochon.Torrent var torrents []*polochon.Torrent
for _, torrentDB := range torrentsDB { for _, torrentDB := range torrentsDB {
torrent := NewTorrentFromMovieTorrentDB(torrentDB) torrent := newTorrentFromMovieTorrentDB(torrentDB)
torrents = append(torrents, torrent) torrents = append(torrents, torrent)
} }
@ -103,7 +103,7 @@ func GetMovieTorrents(db *sqlx.DB, imdbID string) ([]*polochon.Torrent, error) {
// UpsertMovieTorrent adds or updates MovieTorrent in db // UpsertMovieTorrent adds or updates MovieTorrent in db
func UpsertMovieTorrent(db *sqlx.DB, t *polochon.Torrent) error { func UpsertMovieTorrent(db *sqlx.DB, t *polochon.Torrent) error {
mDB := NewMovieTorrentDB(t) mDB := newMovieTorrentDB(t)
r, err := db.NamedQuery(upsertMovieTorrentQuery, mDB) r, err := db.NamedQuery(upsertMovieTorrentQuery, mDB)
if err != nil { if err != nil {
return err return err