/
TvShow.groovy
107 lines (86 loc) · 2.27 KB
/
TvShow.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package streama
import streama.traits.SimpleInstance
import java.security.SecureRandom
import org.hibernate.Criteria
class TvShow implements SimpleInstance {
transient springSecurityService
transient theMovieDbService
Boolean deleted = false
Boolean manualInput = false
Date dateCreated
Date lastUpdated
String name
String overview
String apiId
String backdrop_path
String poster_path
String first_air_date
String original_language
String imdb_id
Double vote_average
Integer vote_count
Double popularity
static hasMany = [episodes: Episode, genre: Genre]
File poster_image
File backdrop_image
static mapping = {
cache true
episodes cache: true
overview type: 'text'
}
static constraints = {
name nullable: false
overview size: 1..5000
}
List<Episode> getFilteredEpisodes() {
List filteredEpisodes = Episode.findAllByShowAndDeletedNotEqual(this, true)
return filteredEpisodes
}
// def getEpisodes(){
// return this.getFilteredEpisodes()
// }
def getExternalLinks() {
theMovieDbService.getExternalLinks(this.apiId)
}
def getHasFiles() {
return (this.episodes?.find { it.files } ? true : false)
}
def getFullTvShowMeta() {
try {
return theMovieDbService.getFullTvShowMeta(this.apiId)
}catch (e) {
log.warn("couldnt get FullTvShowMeta for ${this.apiId}")
log.warn(e.message)
return null
}
}
def inWatchlist() {
User currentUser = springSecurityService.currentUser
Profile profile = currentUser.getProfileFromRequest()
return WatchlistEntry.where {
user == currentUser
profile == profile
tvShow == this
isDeleted == false
}.count() > 0
}
List<Episode> listEpisodesWithFiles() {
return this.episodes?.findAll { it.files && it.season_number != '0' } as List
}
def getFirstEpisode() {
return listEpisodesWithFiles().min { it.seasonEpisodeMerged }
}
def getPosterPath(Integer width = 300){
if(this.poster_image){
return this.poster_image.src
}
if(!this.poster_path){
return
}
String TMDB_BASE_PATH = "https://image.tmdb.org/t/p/w${width}/"
if(this.poster_path?.startsWith('http')){
return this.poster_path
}
return TMDB_BASE_PATH + this.poster_path
}
}