Skip to content

Commit

Permalink
feat(imdb): format title runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
Jisin0 committed Sep 16, 2024
1 parent 0242b9d commit 1c618ae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions imdb/getmovie.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ func (c *ImdbClient) GetMovie(id string) (*Movie, error) {
movie.ReleaseYear = htmlquery.InnerText(releaseYearNode)
}

if movie.Runtime != "" {
movie.Runtime = parseIMDbDuration(movie.Runtime)
}

// Cache data for next time
if !c.disabledCaching {
err := c.cache.MovieCache.Save(id, movie)
Expand Down
13 changes: 13 additions & 0 deletions imdb/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package imdb

import "strings"

// parseIMDbDuration parses the time returned from imdb into human-readable format. for ex: PT2H1M -> 2h 1min
func parseIMDbDuration(s string) string {
s = strings.ReplaceAll(s, "PT", "")
s = strings.ReplaceAll(s, "H", "h ")
s = strings.ReplaceAll(s, "M", "min ")
s = strings.ReplaceAll(s, "S", "s")

return s
}

0 comments on commit 1c618ae

Please sign in to comment.