Merge branch 'subtitle' into 'master'

Add subtitles

See merge request !66
This commit is contained in:
Grégoire Delattre 2017-05-15 11:18:42 +00:00
commit 63e9d5b4e2
3 changed files with 47 additions and 12 deletions

View File

@ -31,9 +31,23 @@ func (m *Movie) MarshalJSON() ([]byte, error) {
type Alias Movie
var downloadURL string
type Subtitle struct {
Language string `json:"language"`
URL string `json:"url"`
}
var subtitles []Subtitle
// If the episode is present, fill the downloadURL
if m.pMovie != nil {
// Get the DownloadURL
downloadURL, _ = m.client.DownloadURL(m.pMovie)
// Append the Subtitles
for _, l := range m.pMovie.Subtitles {
subtitleURL, _ := m.client.SubtitleURL(m.pMovie, l)
subtitles = append(subtitles, Subtitle{
Language: l,
URL: subtitleURL,
})
}
}
// Marshal the movie with its polochon_url
@ -41,10 +55,12 @@ func (m *Movie) MarshalJSON() ([]byte, error) {
*Alias
PolochonURL string `json:"polochon_url"`
PosterURL string `json:"poster_url"`
Subtitles []Subtitle `json:"subtitles"`
}{
Alias: (*Alias)(m),
PolochonURL: downloadURL,
PosterURL: m.PosterURL(),
Subtitles: subtitles,
}
return json.Marshal(movieToMarshal)

View File

@ -23,8 +23,16 @@ func (e *Episode) MarshalJSON() ([]byte, error) {
type alias Episode
var downloadURL string
type Subtitle struct {
Language string `json:"language"`
URL string `json:"url"`
}
var subtitles []Subtitle
// If the episode is present, fill the downloadURL
if e.pShow != nil && e.pShow.HasEpisode(e.Season, e.Episode) {
if e.pShow != nil {
pEpisode := e.pShow.GetEpisode(e.Season, e.Episode)
if pEpisode != nil {
// Get the DownloadURL
downloadURL, _ = e.client.DownloadURL(
&papi.Episode{
ShowImdbID: e.ShowImdbID,
@ -32,15 +40,26 @@ func (e *Episode) MarshalJSON() ([]byte, error) {
Season: e.Season,
},
)
// Append the Subtitles
for _, l := range pEpisode.Subtitles {
subtitleURL, _ := e.client.SubtitleURL(pEpisode, l)
subtitles = append(subtitles, Subtitle{
Language: l,
URL: subtitleURL,
})
}
}
}
// Marshal the episode with its polochon_url
episodeToMarshal := &struct {
*alias
PolochonURL string `json:"polochon_url"`
Subtitles []Subtitle `json:"subtitles"`
}{
alias: (*alias)(e),
PolochonURL: downloadURL,
Subtitles: subtitles,
}
return json.Marshal(episodeToMarshal)

View File

@ -48,7 +48,7 @@ export function request(eventPrefix, promise, callbackEvents = null) {
})
.catch(error => {
// Unauthorized
if (error.response.status == 401) {
if (error.response && error.response.status == 401) {
dispatch({
type: 'USER_LOGOUT',
})