Exemple #1
0
func FetchPreview(code int, tweet *anaconda.Tweet, config Config) {
	coverUrls := PeekCoverImageUrls(code, config.HaruHostName)
	now := time.Now()

	// 커버는 1개일 확률이 높으니까 고루틴 굳이 쓸 필요 없을거다
	for i, url := range coverUrls {
		fetcher := network.HttpFetcher{}
		resp := fetcher.Fetch(url)

		prefix := twutils.MakePrefix(now)
		filename := ""
		ext := filepath.Ext(url)
		if len(coverUrls) == 1 {
			filename = fmt.Sprintf("%d%s", code, ext)
		} else {
			num := i + 1
			filename = fmt.Sprintf("%d_%d%s", code, num, ext)
		}
		config.Accessor.UploadBytes(resp.Data, prefix+filename)
	}

	if tweet != nil && len(coverUrls) > 0 {
		twutils.UploadMetadata(tweet, config.Accessor, "", now)
	}
}
Exemple #2
0
// 썸네일 얻기. hitomi api 에서 획득 가능하겠지?
func PeekCoverImageUrls(code int, host string) []string {
	url := fmt.Sprintf("http://%s/api/detail/hitomi/%d", host, code)
	fetcher := network.HttpFetcher{}
	apiResp := fetcher.Fetch(url)
	jsontext := string(apiResp.Data)
	urls := ExtractCoverImages(jsontext)
	return urls
}
Exemple #3
0
func fetchMediaCh(tweet *anaconda.Tweet, media anaconda.EntityMedia, resps chan<- *MediaResponse) {
	url := twutils.FindMediaURL(media)
	filename := twutils.MakeMediaFileName(tweet, media)
	fetcher := network.HttpFetcher{}
	resp := fetcher.Fetch(url)

	resps <- &MediaResponse{
		resp,
		filename,
	}
}