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;`
)
// EpisodeTorrentDB represents the EpisodeTorrent in the DB
type EpisodeTorrentDB struct {
// episodeTorrentDB represents the EpisodeTorrent in the DB
type episodeTorrentDB struct {
ID string `db:"id"`
ImdbID string `db:"imdb_id"`
URL string `db:"url"`
@ -42,9 +42,9 @@ type EpisodeTorrentDB struct {
Updated time.Time `db:"updated_at"`
}
// NewTorrentFromEpisodeTorrentDB returns a polochon.Torrent from an
// newTorrentFromEpisodeTorrentDB returns a polochon.Torrent from an
// EpisodeTorrentDB
func NewTorrentFromEpisodeTorrentDB(eDB *EpisodeTorrentDB) *polochon.Torrent {
func newTorrentFromEpisodeTorrentDB(eDB *episodeTorrentDB) *polochon.Torrent {
return &polochon.Torrent{
ImdbID: eDB.ImdbID,
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
func NewEpisodeTorrentDB(t *polochon.Torrent) *EpisodeTorrentDB {
e := &EpisodeTorrentDB{
func newEpisodeTorrentDB(t *polochon.Torrent) *episodeTorrentDB {
e := &episodeTorrentDB{
ImdbID: t.ImdbID,
Quality: string(t.Quality),
Season: t.Season,
@ -87,7 +87,7 @@ func NewEpisodeTorrentDB(t *polochon.Torrent) *EpisodeTorrentDB {
// GetEpisodeTorrents returns show episodes torrents from database
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)
if err != nil {
return nil, err
@ -99,7 +99,7 @@ func GetEpisodeTorrents(db *sqlx.DB, imdbID string, season, episode int) ([]*pol
var torrents []*polochon.Torrent
for _, torrentDB := range torrentsDB {
torrent := NewTorrentFromEpisodeTorrentDB(torrentDB)
torrent := newTorrentFromEpisodeTorrentDB(torrentDB)
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
func UpsertEpisodeTorrent(db *sqlx.DB, torrent *polochon.Torrent) error {
// Create the EpisodeTorrent ready to be put in db
eDB := NewEpisodeTorrentDB(torrent)
eDB := newEpisodeTorrentDB(torrent)
r, err := db.NamedQuery(upsertEpisodeTorrentQuery, eDB)
if err != nil {
return err

View File

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