Example #1
0
func (c *Config) FindMovie(title string, year int) ([]*Movie, error) {
	q := c.LinkUrl.Query()
	q.Set("q", title)

	query := *c.LinkUrl
	query.RawQuery = q.Encode()
	rawquery := query.String()
	log.Println(rawquery)

	var matches []scoredMovie
	var batch_answers RottenTomatoMovies

	mm := movie_match{title, year}

	for len(matches) < 1 && rawquery != "" {
		fmt.Println(rawquery)
		err := json.FromUrl(rawquery, &batch_answers)
		if err != nil {
			return selectBest(matches), err
		}
		if batch_answers.Error != "" {
			return selectBest(matches), errors.New(batch_answers.Error)
		}
		for _, m := range batch_answers.Movies {
			var s scoredMovie
			s.score, s.dist = mm.scoreMatch(m)
			//log.Println(s.score, s.dist, m.Title, m.Year)
			s.movie = m
			matches = append(matches, s)
		}
		rawquery = batch_answers.Links.Next
	}
	return selectBest(matches), nil
}
Example #2
0
func GetConfig() *Config {
	if globalConfig != nil {
		return globalConfig
	}

	globalConfigLock.Lock()
	defer globalConfigLock.Unlock()

	// Fills out Links.Movies and Links.Lists
	var config Config
	err := json.FromUrl(init_query+api_key, &config)
	if err != nil {
		log.Println(err)
		return nil
	}

	if config.Links.Movies != "" {
		// Fills out LinkTemplate
		err = json.FromUrl(config.Links.Movies+api_key, &config)
		if err != nil {
			log.Println(err)
		} else {
			u, err := url.Parse(config.LinkTemplate)
			if err != nil {
				log.Println(err)
			} else {
				q := u.Query()
				q.Set("page_limit", "10")
				q.Set("page", "1")
				q.Set("apikey", rtkey)
				u.RawQuery = q.Encode()

				config.LinkUrl = u

				globalConfig = &config
			}
		}
	}

	return globalConfig
}
Example #3
0
func (r *Movie) GetFullCast(c *Config) error {
	if r.Links.Cast == "" {
		return nil
	}

	url, err := c.AddKey(r.Links.Cast)
	if err != nil {
		return err
	}
	log.Println(url)
	json.FromUrl(url, r)
	return nil
}