From 740da466b64d003ab99dfc8c9e99e78acbdf03f5 Mon Sep 17 00:00:00 2001 From: Lucas BEE Date: Mon, 15 May 2017 13:36:06 +0200 Subject: [PATCH] Add subtitles --- src/internal/movies/movies.go | 20 ++++++++++++++++-- src/internal/shows/episodes.go | 37 +++++++++++++++++++++++++--------- src/public/js/requests.js | 2 +- 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/src/internal/movies/movies.go b/src/internal/movies/movies.go index 523ccfb..e4147c4 100644 --- a/src/internal/movies/movies.go +++ b/src/internal/movies/movies.go @@ -31,20 +31,36 @@ 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 movieToMarshal := &struct { *Alias - PolochonURL string `json:"polochon_url"` - PosterURL string `json:"poster_url"` + 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) diff --git a/src/internal/shows/episodes.go b/src/internal/shows/episodes.go index 0e6d5bd..b3535e7 100644 --- a/src/internal/shows/episodes.go +++ b/src/internal/shows/episodes.go @@ -23,24 +23,43 @@ 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) { - downloadURL, _ = e.client.DownloadURL( - &papi.Episode{ - ShowImdbID: e.ShowImdbID, - Episode: e.Episode, - Season: e.Season, - }, - ) + 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, + Episode: e.Episode, + 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"` + PolochonURL string `json:"polochon_url"` + Subtitles []Subtitle `json:"subtitles"` }{ alias: (*alias)(e), PolochonURL: downloadURL, + Subtitles: subtitles, } return json.Marshal(episodeToMarshal) diff --git a/src/public/js/requests.js b/src/public/js/requests.js index 25424c8..e865a82 100644 --- a/src/public/js/requests.js +++ b/src/public/js/requests.js @@ -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', })