From 271bc7028e53c3272e8c520bc74d974046522923 Mon Sep 17 00:00:00 2001 From: windblows95 Date: Sat, 3 Aug 2024 13:13:13 -0400 Subject: [PATCH] season: html unescape description and episode names --- season.go | 6 +++--- season_test.go | 12 ++++++------ title.go | 3 ++- title_test.go | 4 ++-- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/season.go b/season.go index e835235..de63c99 100644 --- a/season.go +++ b/season.go @@ -3,8 +3,8 @@ package imdb import ( "errors" "fmt" + "html" "io" - "io/ioutil" "net/http" "regexp" "strconv" @@ -43,7 +43,7 @@ func NewSeason(c *http.Client, id string, season int) (*Season, error) { } return nil, fmt.Errorf("imdb: status not ok: %v", resp.Status) } - page, err := ioutil.ReadAll(resp.Body) + page, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -69,7 +69,7 @@ func (s *Season) Parse(c *http.Client, page []byte) error { for _, ep := range episodesMatch { n, _ := strconv.Atoi(string(ep[3])) - episode := Episode{SeasonNumber: s.SeasonNumber, EpisodeNumber: n, ImageURL: string(ep[1]), ID: string(ep[2]), Name: string(ep[4])} + episode := Episode{SeasonNumber: s.SeasonNumber, EpisodeNumber: n, ImageURL: string(ep[1]), ID: string(ep[2]), Name: html.UnescapeString(string(ep[4]))} s.Episodes = append(s.Episodes, episode) } diff --git a/season_test.go b/season_test.go index 62cf8ab..2862bba 100644 --- a/season_test.go +++ b/season_test.go @@ -18,7 +18,7 @@ func TestSeason(t *testing.T) { EpisodeNumber: 1, ImageURL: "https://m.media-amazon.com/images/M/MV5BMWIwZWExNGUtNTJjNC00N2Q2LWFjYjItMzhhNzc2NmNlMzBhXkEyXkFqcGc@._V1_QL75_UY281_CR8,0,500,281_.jpg", ID: "tt1000552", - Name: "I Fuckin' Miss Cory and Trevor", + Name: "I Fuckin' Miss Cory and Trevor", }, { SeasonNumber: 7, @@ -53,7 +53,7 @@ func TestSeason(t *testing.T) { EpisodeNumber: 6, ImageURL: "https://m.media-amazon.com/images/M/MV5BZDI4Nzc3MTMtNjM0OC00ZDJiLTgzMzctNTZjZGExOTM4MGY3XkEyXkFqcGc@._V1_QL75_UY281_CR11,0,500,281_.jpg", ID: "tt1026371", - Name: "We Can't Call People Without Wings Angels So We Call Them Friends", + Name: "We Can't Call People Without Wings Angels So We Call Them Friends", }, { SeasonNumber: 7, @@ -111,7 +111,7 @@ func TestSeason(t *testing.T) { EpisodeNumber: 3, ImageURL: "https://m.media-amazon.com/images/M/MV5BMmE4MDVhODctZGZmZi00MTdiLTkyZjUtYzBmNWZlYWU5ZDVlXkEyXkFqcGc@._V1_QL75_UX500_CR0,40,500,281_.jpg", ID: "tt0732924", - Name: "The Fuckin' Way She Goes", + Name: "The Fuckin' Way She Goes", }, { SeasonNumber: 5, @@ -125,14 +125,14 @@ func TestSeason(t *testing.T) { EpisodeNumber: 5, ImageURL: "https://m.media-amazon.com/images/M/MV5BMjU3Y2IzMDMtYjFkZC00NTdhLWI1YTQtMTRhNGM2MDY2MWJhXkEyXkFqcGdeQXVyMTQ2ODE0NDA@._V1_QL75_UX500_CR0,52,500,281_.jpg", ID: "tt0732913", - Name: "Mr. Lahey Is a Fuckin' Drunk, and He Always Will Be", + Name: "Mr. Lahey Is a Fuckin' Drunk, and He Always Will Be", }, { SeasonNumber: 5, EpisodeNumber: 6, ImageURL: "https://m.media-amazon.com/images/M/MV5BNTE1MmU3MjItZWE4ZC00NjkwLTllZDAtMjM4YTlmZDM2MDRlXkEyXkFqcGdeQXVyMTQ2ODE0NDA@._V1_QL75_UX500_CR0,46,500,281_.jpg", ID: "tt0732904", - Name: "Don't Cross the Shitline", + Name: "Don't Cross the Shitline", }, { SeasonNumber: 5, @@ -146,7 +146,7 @@ func TestSeason(t *testing.T) { EpisodeNumber: 8, ImageURL: "https://m.media-amazon.com/images/M/MV5BYTg1ZGI2YmItNDJiZC00NjJiLWE2ZTEtNTc2MGJlNzM3YjRkL2ltYWdlL2ltYWdlXkEyXkFqcGdeQXVyMTQ2ODE0NDA@._V1_QL75_UX500_CR0,46,500,281_.jpg", ID: "tt0732905", - Name: "Dressed All Over & Zesty Mordant", + Name: "Dressed All Over & Zesty Mordant", }, { SeasonNumber: 5, diff --git a/title.go b/title.go index ded463d..d538cc6 100644 --- a/title.go +++ b/title.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "html" "io" "net/http" "regexp" @@ -369,7 +370,7 @@ func (t *Title) Parse(page []byte) error { } } - t.Description = v.Description + t.Description = html.UnescapeString(v.Description) s = titlePosterRE.FindSubmatch(page) if s != nil { diff --git a/title_test.go b/title_test.go index 73ba865..80d908d 100644 --- a/title_test.go +++ b/title_test.go @@ -269,7 +269,7 @@ func TestTitle(t *testing.T) { Genres: []string{"Crime", "Drama", "Romance"}, Languages: []string{"Korean"}, Nationalities: []string{"South Korea", "Japan"}, - Description: "A transient young man breaks into empty homes to partake of the vacationing residents' lives for a few days.", + Description: "A transient young man breaks into empty homes to partake of the vacationing residents' lives for a few days.", Poster: Media{ID: "rm880057600", TitleID: "tt0423866", URL: "https://www.imdb.com/title/tt0423866/mediaviewer/rm880057600", ContentURL: "https://m.media-amazon.com/images/M/MV5BMTM1ODIwNzM5OV5BMl5BanBnXkFtZTcwNjk5MDkyMQ@@._V1_.jpg"}, }, }, @@ -309,7 +309,7 @@ func TestTitle(t *testing.T) { Genres: []string{"Comedy", "Crime"}, Languages: []string{"English"}, Nationalities: []string{"Canada"}, - Description: "When Randy and Lahey rip the boys off on buying Rush tickets, Ricky "borrows" guitarist Alex Lifeson for access to the concert.", + Description: "When Randy and Lahey rip the boys off on buying Rush tickets, Ricky \"borrows\" guitarist Alex Lifeson for access to the concert.", Poster: Media{ID: "rm1259893761", TitleID: "tt0732901", URL: "https://www.imdb.com/title/tt0732901/mediaviewer/rm1259893761", ContentURL: "https://m.media-amazon.com/images/M/MV5BNjY4YjJhZDQtM2U3ZS00ZThkLWIyZmMtZTY3MmU3N2QwOTVmXkEyXkFqcGc@._V1_.jpg"}, Season: 3, Episode: 5,