Esempio n. 1
0
func GetShow(showId int, language string) *Show {
	var show *Show
	cacheStore := cache.NewFileStore(path.Join(config.Get().ProfilePath, "cache"))
	key := fmt.Sprintf("com.tmdb.show.%d.%s", showId, language)
	if err := cacheStore.Get(key, &show); err != nil {
		rateLimiter.Call(func() {
			p := napping.Params{"api_key": apiKey, "append_to_response": "credits,images,alternative_titles,translations,external_ids", "language": language}.AsUrlValues()
			napping.Get(
				tmdbEndpoint+"tv/"+strconv.Itoa(showId),
				&p,
				&show,
				nil,
			)
		})
		if show != nil {
			cacheStore.Set(key, show, cacheTime)
		}
	}
	if show == nil {
		return nil
	}
	switch t := show.RawPopularity.(type) {
	case string:
		if popularity, err := strconv.ParseFloat(t, 64); err == nil {
			show.Popularity = popularity
		}
	case float64:
		show.Popularity = t
	}
	return show
}
Esempio n. 2
0
func getMovieById(movieId string, language string) *Movie {
	var movie *Movie
	cacheStore := cache.NewFileStore(path.Join(config.Get().ProfilePath, "cache"))
	key := fmt.Sprintf("com.tmdb.movie.%s.%s", movieId, language)
	if err := cacheStore.Get(key, &movie); err != nil {
		rateLimiter.Call(func() {
			p := napping.Params{"api_key": apiKey, "append_to_response": "credits,images,alternative_titles,translations,external_ids,trailers", "language": language}.AsUrlValues()
			napping.Get(
				tmdbEndpoint+"movie/"+movieId,
				&p,
				&movie,
				nil,
			)
			if movie != nil {
				cacheStore.Set(key, movie, cacheTime)
			}
		})
	}
	if movie == nil {
		return nil
	}
	switch t := movie.RawPopularity.(type) {
	case string:
		popularity, _ := strconv.ParseFloat(t, 64)
		movie.Popularity = popularity
	case float64:
		movie.Popularity = t
	}
	return movie
}
Esempio n. 3
0
func getClientId() string {
	clientId := ""
	key := "io.steeve.pulsar.ga"
	cacheStore := cache.NewFileStore(path.Join(config.Get().ProfilePath))
	if err := cacheStore.Get(key, &clientId); err != nil {
		clientUUID, _ := uuid.NewV4()
		clientId := clientUUID.String()
		cacheStore.Set(key, clientId, clientIdCacheTime)
	}
	return clientId
}
Esempio n. 4
0
func NewShowCached(tvdbId string, language string) (*Show, error) {
	var show *Show
	cacheStore := cache.NewFileStore(path.Join(config.Get().ProfilePath, "cache"))
	key := fmt.Sprintf("com.tvdb.show.%s.%s", tvdbId, language)
	if err := cacheStore.Get(key, &show); err != nil {
		newShow, err := NewShow(tvdbId, language)
		if err != nil {
			return nil, err
		}
		if newShow != nil {
			cacheStore.Set(key, newShow, cacheTime)
		}
		show = newShow
	}
	return show, nil
}
Esempio n. 5
0
func Find(externalId string, externalSource string) *FindResult {
	var result *FindResult

	cacheStore := cache.NewFileStore(path.Join(config.Get().ProfilePath, "cache"))
	key := fmt.Sprintf("com.tmdb.find.%s.%s", externalSource, externalId)
	if err := cacheStore.Get(key, &result); err != nil {
		rateLimiter.Call(func() {
			p := napping.Params{"api_key": apiKey, "external_source": externalSource}.AsUrlValues()
			napping.Get(
				tmdbEndpoint+"find/"+externalId,
				&p,
				&result,
				nil,
			)
			cacheStore.Set(key, result, 365*24*time.Hour)
		})
	}

	return result
}