Skip to content

Commit

Permalink
season: html unescape description and episode names
Browse files Browse the repository at this point in the history
  • Loading branch information
windblows95 authored and StalkR committed Aug 3, 2024
1 parent ba11501 commit 271bc70
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
6 changes: 3 additions & 3 deletions season.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package imdb
import (
"errors"
"fmt"
"html"
"io"
"io/ioutil"
"net/http"
"regexp"
"strconv"
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
}

Expand Down
12 changes: 6 additions & 6 deletions season_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion title.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"html"
"io"
"net/http"
"regexp"
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions title_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
},
},
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 271bc70

Please sign in to comment.