Compare commits
4 Commits
e3f6ff1fe2
...
114f022b8d
Author | SHA1 | Date | |
---|---|---|---|
114f022b8d | |||
83d1894a25 | |||
c9ecdac4f2 | |||
3bd51765b8 |
@ -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
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user