1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Handles TV shows |
5
|
|
|
* |
6
|
|
|
* @author Sam Stenvall <[email protected]> |
7
|
|
|
* @copyright Copyright © Sam Stenvall 2013- |
8
|
|
|
* @license https://www.gnu.org/licenses/gpl.html The GNU General Public License v3.0 |
9
|
|
|
*/ |
10
|
|
|
class TvShowController extends MediaController |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Adds an AJAX-only filter on the renderEpisodeList action |
15
|
|
|
* @return array the filters for this controller |
16
|
|
|
*/ |
17
|
|
|
public function filters() |
18
|
|
|
{ |
19
|
|
|
return array_merge(parent::filters(), array( |
20
|
|
|
'ajaxOnly + renderEpisodeList', |
21
|
|
|
)); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
protected function getSpectatorProhibitedActions() |
25
|
|
|
{ |
26
|
|
|
return array('getEpisodePlaylist', 'getSeasonPlaylist', 'getTVShowPlaylist'); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Lists all TV shows in the library |
31
|
|
|
*/ |
32
|
|
|
public function actionIndex() |
33
|
|
|
{ |
34
|
|
|
// Get the appropriate request parameters from the filter |
35
|
|
|
$filterForm = new TVShowFilterForm(); |
36
|
|
|
$tvshows = VideoLibrary::getTVShows($filterForm->buildRequestParameters()); |
37
|
|
|
|
38
|
|
|
// Redirect to the details page if this is the only TV show |
39
|
|
|
if (count($tvshows) === 1 && $filterForm->name === $tvshows[0]->label) |
40
|
|
|
$this->redirect(['details', 'id' => $tvshows[0]->getId()]); |
41
|
|
|
|
42
|
|
|
$dataProvider = new LibraryDataProvider($tvshows); |
43
|
|
|
$dataProvider->makeSortable(); |
44
|
|
|
|
45
|
|
|
$this->render('index', [ |
46
|
|
|
'dataProvider' => $dataProvider, |
47
|
|
|
'filterForm' => $filterForm, |
48
|
|
|
]); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Displays information about the specified show |
54
|
|
|
* @param int $id the show ID |
55
|
|
|
* @throws CHttpException if the show could not be found |
56
|
|
|
*/ |
57
|
|
|
public function actionDetails($id) |
58
|
|
|
{ |
59
|
|
|
$showDetails = VideoLibrary::getTVShowDetails($id, array( |
60
|
|
|
'genre', |
61
|
|
|
'year', |
62
|
|
|
'rating', |
63
|
|
|
'plot', |
64
|
|
|
'mpaa', |
65
|
|
|
'imdbnumber', |
66
|
|
|
'art', |
67
|
|
|
'thumbnail', |
68
|
|
|
'cast', |
69
|
|
|
)); |
70
|
|
|
|
71
|
|
|
$actorDataProvider = new CArrayDataProvider( |
72
|
|
|
$showDetails->cast, array( |
73
|
|
|
'keyField'=>'name', |
74
|
|
|
'pagination'=>array('pageSize'=>6) |
75
|
|
|
)); |
76
|
|
|
|
77
|
|
|
$this->render('details', array( |
78
|
|
|
'details'=>$showDetails, |
79
|
|
|
'seasons'=>VideoLibrary::getSeasons($id), |
80
|
|
|
'actorDataProvider'=>$actorDataProvider)); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Wrapper for renderEpisodeList() |
85
|
|
|
* @see renderEpisodeList() |
86
|
|
|
*/ |
87
|
|
|
public function actionSeason($tvshowid, $season) |
88
|
|
|
{ |
89
|
|
|
$season = VideoLibrary::getSeasonDetails($tvshowid, $season); |
90
|
|
|
|
91
|
|
|
// Get the TV show details so we can get the correct show title |
92
|
|
|
$tvshow = VideoLibrary::getTVShowDetails($tvshowid, array('year')); |
93
|
|
|
|
94
|
|
|
$this->pageTitle = Yii::t('TVShows', 'Season {season} - {showTitle}', array( |
95
|
|
|
'{season}'=>$season->season, '{showTitle}'=>$tvshow->getDisplayName())); |
96
|
|
|
|
97
|
|
|
$this->renderEpisodeList($season); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* AJAX wrapper for renderEpisodeList. |
102
|
|
|
* @see renderEpisodeList |
103
|
|
|
*/ |
104
|
|
|
public function actionRenderEpisodeList($tvshowid, $season) |
105
|
|
|
{ |
106
|
|
|
$this->layout = false; |
107
|
|
|
|
108
|
|
|
$season = VideoLibrary::getSeasonDetails($tvshowid, $season); |
109
|
|
|
|
110
|
|
|
$this->renderEpisodeList($season); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Serves a playlist containing all episodes from the specified TV show |
115
|
|
|
* @param int $tvshowId the TV show ID |
116
|
|
|
*/ |
117
|
|
|
public function actionGetTVShowPlaylist($tvshowId) |
118
|
|
|
{ |
119
|
|
|
$tvshow = VideoLibrary::getTVShowDetails($tvshowId, array()); |
120
|
|
|
|
121
|
|
|
$this->log('"%s" streamed TV show "%s"', Yii::app()->user->name, $tvshow->getDisplayName()); |
122
|
|
|
$this->servePlaylist($tvshow); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Serves a playlist containing all episodes from the specified TV show |
127
|
|
|
* season. |
128
|
|
|
* @param int $tvshowId the TV show ID |
129
|
|
|
* @param int $season the season |
130
|
|
|
*/ |
131
|
|
|
public function actionGetSeasonPlaylist($tvshowId, $season) |
132
|
|
|
{ |
133
|
|
|
// Get the season details so we can determine the playlist name |
134
|
|
|
$seasonDetails = VideoLibrary::getSeasonDetails($tvshowId, $season); |
135
|
|
|
|
136
|
|
|
$this->log('"%s" streamed season %d of "%s"', Yii::app()->user->name, $season, $seasonDetails->showtitle); |
137
|
|
|
$this->servePlaylist($seasonDetails); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Serves a playlist containing the specified episode |
142
|
|
|
* @param int $id the episode ID |
143
|
|
|
* @throws CHttpException if the episode's file(s) don't exist |
144
|
|
|
*/ |
145
|
|
|
public function actionGetEpisodePlaylist($id, $playlistFormat) |
146
|
|
|
{ |
147
|
|
|
$episode = VideoLibrary::getEpisodeDetails($id, array( |
148
|
|
|
'episode', |
149
|
|
|
'season', |
150
|
|
|
'showtitle', |
151
|
|
|
'runtime', |
152
|
|
|
'thumbnail', |
153
|
|
|
'file')); |
154
|
|
|
|
155
|
|
|
$this->log('"%s" streamed %s of "%s"', Yii::app()->user->name, $episode->getEpisodeString(), $episode->showtitle); |
156
|
|
|
$this->servePlaylist($episode, $playlistFormat); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Displays a list of the recently added episodes |
161
|
|
|
*/ |
162
|
|
|
public function actionRecentlyAdded() |
163
|
|
|
{ |
164
|
|
|
$episodes = VideoLibrary::getRecentlyAddedEpisodes(); |
165
|
|
|
|
166
|
|
|
$dataProvider = new LibraryDataProvider($episodes); |
167
|
|
|
$dataProvider->makeSortable('dateadded DESC'); |
168
|
|
|
|
169
|
|
|
$this->render('recentlyAdded', [ |
170
|
|
|
'dataProvider' => $dataProvider, |
171
|
|
|
]); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Returns a data provider containing the episodes for the specified show |
176
|
|
|
* and season |
177
|
|
|
* @param int $tvshowId the TV show ID |
178
|
|
|
* @param int $season the season number |
179
|
|
|
* @return \LibraryDataProvider |
180
|
|
|
*/ |
181
|
|
|
public function getEpisodeDataProvider($tvshowId, $season) |
182
|
|
|
{ |
183
|
|
|
$episodes = VideoLibrary::getEpisodes($tvshowId, $season); |
184
|
|
|
|
185
|
|
|
// We never want pagination here |
186
|
|
|
return new LibraryDataProvider($episodes, array( |
187
|
|
|
'pagination'=>false, |
188
|
|
|
)); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Renders the list of episodes for the specified season |
193
|
|
|
* @param Season $season the season |
194
|
|
|
*/ |
195
|
|
|
private function renderEpisodeList($season) |
196
|
|
|
{ |
197
|
|
|
$this->render('_episodes', array( |
198
|
|
|
'season'=>$season)); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
} |
202
|
|
|
|