Ejemplo n.º 1
0
func favicon_try_from_url(uri string) string {
	c := curl.NewCurl("")

	cache, err := c.Get(uri)
	fmt.Println(cache)
	if err != nil {
		return ""
	}
	// text/html, text/xml, image
	m := strings.Split(cache.Mime, "/")
	switch m[0] {
	case "text":
		f, err := os.Open(cache.Local)
		if err == nil {
			defer f.Close()
			n, err := html.Parse(f)
			if err == nil {
				if u, ok := icon_from_link_rel(n); ok {
					return u
				}
			}
		}

	case "image":
		return uri
	}
	return ""
}
Ejemplo n.º 2
0
func (this processor_youku) process(uri *url.URL) (VideoDescription, error) {
	ids := ykrs1.FindStringSubmatch(uri.Path)
	if len(ids) != 2 {
		ids = ykrs2.FindStringSubmatch(uri.Path)
	}
	var vid string
	if len(ids) == 2 {
		vid = ids[1]
	}
	if vid == "" {
		return VideoDescription{}, vd_error{"no video id", uri.String()}
	}
	var v struct {
		Data []struct {
			Logo    string   `json:"logo,omitempty"`
			Tags    []string `json:"tags,omitempty"`
			Title   string   `json:"title,omitempty"`
			Seconds float64  `json:"seconds"`
		} `json:"data,omitempty"`
	}
	u := fmt.Sprintf("http://v.youku.com/player/getPlayList/VideoIDS/%v/timezone/+08/version/5/source/out?password=&ran=%v&n=%v", vid, rand.Int(), rand.Int())
	err := curl.NewCurl("").GetAsJson(u, &v)
	if len(v.Data) == 0 {
		return VideoDescription{}, err
	}
	return VideoDescription{Image: v.Data[0].Logo, Thumbnail: v.Data[0].Logo, Title: v.Data[0].Title}, nil
}
Ejemplo n.º 3
0
func main() {
	flag.Parse()
	if *uri == "" {
		flag.PrintDefaults()
		return
	}
	c := curl.NewCurl("e:/")
	cache, err := c.GetUtf8(*uri)
	if err != nil {
		panic(err)
	}
	f, err := os.Open(cache.LocalUtf8)
	if err != nil {
		panic(err)
	}
	defer f.Close()
	doc, err := html.Parse(f)
	if err != nil {
		panic(err)
	}
	ex := cleaner.NewExtractor("e:/")
	article, _, err := ex.MakeHtmlReadable(doc, *uri)
	if err != nil {
		panic(err)
	}
	print_html_doc(article)
}
Ejemplo n.º 4
0
func BingSuggestion(q string) ([]string, error) {
	p := struct {
		market string `param:"mkt"` //zh-CN
		cp     int    `param:"cp"`  //2
		o      string `param:"o"`   //a+ds+ds+p
		query  string `param:"q"`
	}{market: "zh-CN", cp: 2, query: q}

	qu := oauth2.HttpQueryEncode(p)
	uri := bing_suggest + "?" + qu
	var val bing_suggestion_result
	err := curl.NewCurl("").GetAsJson(uri, &val)
	x := export_bing_suggestions(val)
	return x, err
}
Ejemplo n.º 5
0
func So360Suggestion(q string) ([]string, error) {
	p := struct {
		callback  string `param:"callback"`
		encodein  string `param:"encodein"`
		encodeout string `param:"encodeout"`
		word      string `param:"word"`
	}{word: q, encodein: "utf-8", encodeout: "utf-8"}
	qu := oauth2.HttpQueryEncode(p)
	uri := so360_suggest + "?" + qu
	fmt.Println(uri)
	/*	val := struct {
			Q string   `json:"q"`
			P bool     `json:"p"`
			S []string `json:"s"`
		}{}
	*/
	_, err := curl.NewCurl("", curl.CurlProxyPolicyNoProxy, 0).GetAsString(uri)
	return nil, err
}
Ejemplo n.º 6
0
func BaiduSuggestion(q string) ([]string, error) {
	p := struct {
		query    string `param:"wd"`
		callback string `param:"cb"`
		sid      string `param:"sid"`
		t        string `param:"t"`
		p        *int   `param:"p"`
	}{query: q}
	qu := oauth2.HttpQueryEncode(p)
	uri := baidu_suggest + "?" + qu
	fmt.Println(uri)
	/*	val := struct {
			Q string   `json:"q"`
			P bool     `json:"p"`
			S []string `json:"s"`
		}{}
	*/
	_, err := curl.NewCurl("", curl.CurlProxyPolicyNoProxy, 0).GetAsString(uri)
	x := make([]string, 0)
	return x, err
}
Ejemplo n.º 7
0
func (this processor_56) process(uri *url.URL) (VideoDescription, error) {
	uid := this.uid_from_uri(uri)
	if uid == "" {
		return VideoDescription{}, vd_error{"56 unrecognize uid", uri.String()}
	}
	vxmlurl := this.metaurl_from_uid(uid)
	var vxml struct {
		Info struct {
			Image     string `json:"bimg,omitempty"`
			Vid       string `json:"vid"`
			Uid       string `json:"textid"`
			Thumbnail string `json:"img"`
			Key       string `json:"key"`
			Tag       string `json:"tag"`
			Title     string `json:"Subject"`
			Duration  string `json:"duration"`
			Files     []struct {
				Length   string `json:"filesize"`
				Duration string `json:"totaltime"`
				Url      string `json:"url"`
				Type     string `json:"type"`
			} `json:"rfiles,omitempty"`
		} `json:"info"`
		Reason      string `json:"msg"`
		SegmentSize int    `json:"segsize"`
		Status      string `json:"status"`
		P2p         int    `json:"p2p"`
	}
	err := curl.NewCurl("").GetAsJson(vxmlurl, &vxml)
	v := VideoDescription{
		Image:     vxml.Info.Image,
		Thumbnail: vxml.Info.Thumbnail,
		Title:     vxml.Info.Title,
		Tags:      []string{vxml.Info.Tag},
		Seconds:   atoi(vxml.Info.Duration),
	}
	return v, err
}
Ejemplo n.º 8
0
func feed_fetch(uri string) (v ReadSource, res []ReadEntry, err error) {
	cache, err := curl.NewCurl(backend_config().FeedSourceFolder).GetUtf8(uri)
	if err != nil {
		return
	}
	ext := curl.MimeToExt(cache.Mime)
	if ext != "xml" && ext != "atom+xml" && ext != "rss+xml" {
		return v, nil, new_backenderror(-1, "unsupported mime: "+cache.Mime)
	} else if cache.LocalUtf8 == "" {
		return v, nil, new_backenderror(-1, "unrecognized encoding: "+cache.Local)
	}
	f, err := os.Open(cache.LocalUtf8)
	if err != nil {
		return
	}
	var fv feed.FeedSource
	var fes []feed.FeedEntry
	fv, fes, err = feed.NewFeedMaker(f, uri).MakeFeed()
	f.Close()
	v = new_readsource(fv)
	res = new_readentries(fes)
	return
}