Esempio n. 1
0
File: song.go Progetto: olragon/dna
// getSongFromXML returns values from url: http://nhacso.net/flash/song/xnl/1/id/
func getSongFromXML(song *Song) <-chan bool {
	channel := make(chan bool, 1)
	go func() {
		link := "http://nhacso.net/flash/song/xnl/1/id/" + GetKey(song.Id)
		result, err := http.Get(link)
		if err == nil {
			song.Title = getValueXML(&result.Data, "name", 1).Trim()
			song.Artists = getValueXML(&result.Data, "artist", 0).ToStringArray().SplitWithRegexp("\\|\\|").SplitWithRegexp(" / ").SplitWithRegexp(" - ")
			song.Artistid = getValueXML(&result.Data, "artistlink", 0).ReplaceWithRegexp("\\.html", "").ReplaceWithRegexp(`^.+-`, "").ToInt()
			authors := getValueXML(&result.Data, "author", 0)
			if !authors.IsBlank() {
				song.Authors = authors.ToStringArray().SplitWithRegexp("\\|\\|").SplitWithRegexp(" / ").SplitWithRegexp(" - ")
				song.Authorid = getValueXML(&result.Data, "authorlink", 0).ReplaceWithRegexp(`\.html`, "").ReplaceWithRegexp(`^.+-`, "").ToInt()

			}
			duration := result.Data.FindAllString("<totalTime.+totalTime>", 1)
			if duration.Length() > 0 {
				song.Duration = duration[0].RemoveHtmlTags("").Trim().ToInt()
			}

			song.Link = getValueXML(&result.Data, "mp3link", 0)

			if song.Title != "" && song.Link != "/" {
				ts := song.Link.FindAllString(`\/[0-9]+_`, 1)[0].ReplaceWithRegexp(`\/`, "").ReplaceWithRegexp(`_`, "")
				unix := ts.ToInt().ToFloat() * dna.Float(math.Pow10(13-len(ts)))
				song.DateCreated = dna.Int(int64(unix) / 1000).ToTime()
				song.DateUpdated = time.Now()
			}
		}
		channel <- true

	}()
	return channel
}
Esempio n. 2
0
File: video.go Progetto: olragon/dna
func getVideoFromMainPage(video *Video) <-chan bool {
	channel := make(chan bool, 1)
	go func() {
		link := "http://nhacso.net/xem-video/google-bot." + GetKey(video.Id) + "=.html"
		// Log(link)
		result, err := http.Get(link)
		if err == nil && !result.Data.Match("Rất tiếc, chúng tôi không tìm thấy thông tin bạn yêu cầu!") {
			data := &result.Data
			temp := data.FindAllString(`(?mis)<p class="title_video.+Đăng bởi`, 1)
			if temp.Length() > 0 {
				title := temp[0].FindAllString(`<h1 class="title">.+</h1>`, 1)
				if title.Length() > 0 {
					video.Title = title[0].RemoveHtmlTags("").Trim()
				}

				if temp[0].Match(`official`) {
					video.Official = 1
				}

				artists := temp[0].FindAllString(`<h2>.+</h2>`, -1)
				if artists.Length() > 0 {
					video.Artists = dna.StringArray(artists.Map(func(val dna.String, idx dna.Int) dna.String {
						return val.RemoveHtmlTags("").Trim()
					}).([]dna.String)).SplitWithRegexp(` / `).Unique()
				}

			}
			topics := data.FindAllString(`<li><a href="http://nhacso.net/the-loai-video/.+</a></li>`, 1)
			if topics.Length() > 0 {
				video.Topics = topics[0].RemoveHtmlTags("").ToStringArray().SplitWithRegexp(` - `).SplitWithRegexp(`/`)
			}

			plays := data.FindAllString(`<span>.+</span><ins>&nbsp;lượt xem</ins>`, 1)
			if plays.Length() > 0 {
				video.Plays = plays[0].GetTags("span")[0].RemoveHtmlTags("").Trim().Replace(".", "").ToInt()
			}

			thumbLink := data.FindAllString(`poster="(.+)" src="(.+)" data`, 1)
			if thumbLink.Length() > 0 {
				video.Thumbnail = thumbLink[0].FindAllStringSubmatch(`poster="(.+?)" `, 1)[0][1]
				video.Link = thumbLink[0].FindAllStringSubmatch(`src="(.+?)" `, 1)[0][1]
				if video.Link != "" {
					ts := video.Link.FindAllStringSubmatch(`([0-9]+)_`, 1)
					if len(ts) > 0 {
						secs := float64(ts[0][1].ToInt()) * math.Pow10(13-len(ts[0][1]))
						// Log(secs)
						video.DateCreated = dna.Float(secs / 1000).ToInt().ToTime()
					}

				}
			}
			producerid := data.FindAllStringSubmatch(`getProducerByListIds\('(\d+)', '#producer_'\);`, 1)
			if len(producerid) > 0 {
				video.Producerid = producerid[0][1].ToInt()
			}
		}
		channel <- true
	}()
	return channel

}