Add subtitles

This commit is contained in:
Lucas BEE 2017-05-15 13:36:06 +02:00
parent 6f5c3a83ea
commit 740da466b6
3 changed files with 47 additions and 12 deletions

View File

@ -31,9 +31,23 @@ func (m *Movie) MarshalJSON() ([]byte, error) {
type Alias Movie type Alias Movie
var downloadURL string 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 the episode is present, fill the downloadURL
if m.pMovie != nil { if m.pMovie != nil {
// Get the DownloadURL
downloadURL, _ = m.client.DownloadURL(m.pMovie) 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 // Marshal the movie with its polochon_url
@ -41,10 +55,12 @@ func (m *Movie) MarshalJSON() ([]byte, error) {
*Alias *Alias
PolochonURL string `json:"polochon_url"` PolochonURL string `json:"polochon_url"`
PosterURL string `json:"poster_url"` PosterURL string `json:"poster_url"`
Subtitles []Subtitle `json:"subtitles"`
}{ }{
Alias: (*Alias)(m), Alias: (*Alias)(m),
PolochonURL: downloadURL, PolochonURL: downloadURL,
PosterURL: m.PosterURL(), PosterURL: m.PosterURL(),
Subtitles: subtitles,
} }
return json.Marshal(movieToMarshal) return json.Marshal(movieToMarshal)

View File

@ -23,8 +23,16 @@ func (e *Episode) MarshalJSON() ([]byte, error) {
type alias Episode type alias Episode
var downloadURL string 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 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( downloadURL, _ = e.client.DownloadURL(
&papi.Episode{ &papi.Episode{
ShowImdbID: e.ShowImdbID, ShowImdbID: e.ShowImdbID,
@ -32,15 +40,26 @@ func (e *Episode) MarshalJSON() ([]byte, error) {
Season: e.Season, 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 // Marshal the episode with its polochon_url
episodeToMarshal := &struct { episodeToMarshal := &struct {
*alias *alias
PolochonURL string `json:"polochon_url"` PolochonURL string `json:"polochon_url"`
Subtitles []Subtitle `json:"subtitles"`
}{ }{
alias: (*alias)(e), alias: (*alias)(e),
PolochonURL: downloadURL, PolochonURL: downloadURL,
Subtitles: subtitles,
} }
return json.Marshal(episodeToMarshal) return json.Marshal(episodeToMarshal)

View File

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