Ejemplo n.º 1
0
// To Source converts string format such as "(12,123123)" to Source Type
func ToSource(sourceStr dna.String) Source {
	if sourceStr.Match(`\([0-9]+,[0-9]+\)`) == false {
		panic("Wrong Source format")
	}
	sourArr := sourceStr.ReplaceWithRegexp(`^\(|\)$`, "").Split(",")
	return Source{sourArr[0].ToInt(), sourArr[1].ToInt()}
}
Ejemplo n.º 2
0
Archivo: song.go Proyecto: olragon/dna
// getSongFromMainPage returns song from main page
func getSongFromMainPage(song *Song) <-chan bool {

	channel := make(chan bool, 1)
	go func() {
		link := "http://nhacso.net/nghe-nhac/google-bot." + GetKey(song.Id) + "==.html"
		result, err := http.Get(link)
		// Log(link)
		// Log(result.Data)
		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
			if data.Match("official") {
				song.Official = 1
			}

			bitrate := data.FindAllString(`\d+kb\/s`, 1)[0]
			if !bitrate.IsBlank() {
				song.Bitrate = bitrate.FindAllString(`\d+`, 1)[0].ToInt()
			}

			plays := data.FindAllString("total_listen_song_detail_\\d+.+", 1)[0]
			if !plays.IsBlank() {
				song.Plays = plays.ReplaceWithRegexp("<\\/span>.+$", "").ReplaceWithRegexp("^.+>", "").ReplaceWithRegexp("\\.", "").ToInt()
			}

			topics := data.FindAllString("<li><a\\shref\\=\\\"http\\:\\/\\/nhacso\\.net\\/the-loai.+", 1)[0]
			if !topics.IsBlank() {
				topics = topics.ReplaceWithRegexp("^.+\\\">|<\\/a><\\/li>", "")
				song.Topics = topics.ToStringArray().SplitWithRegexp(" - ").SplitWithRegexp("/")
				temp := data.FindAllString("<a.+class=\"casi\".+>(.+?)<\\/a>", 1)
				var singer dna.String
				if temp.Length() > 0 {
					singer = temp[0]
				} else {
					singer = ""
				}
				if topics.Match("Nhạc Hoa") && singer.Match(` / `) {
					song.SameArtist = 1
				}
			}

			lyric := data.FindAllString(`(?mis)txtlyric.+Bạn chưa nhập nội bài hát`, 1)[0]
			if !lyric.IsBlank() {
				song.Islyric = 1
				song.Lyric = lyric.ReplaceWithRegexp("(?mis)<\\/textarea>.+$", "").ReplaceWithRegexp("^.+>", "")
				if song.Lyric.Match("Hãy đóng góp lời bài hát chính xác cho Nhacso nhé") {
					song.Lyric = ``
					song.Islyric = 0
				}
			}
		}
		channel <- true

	}()
	return channel
}
Ejemplo n.º 3
0
func getType(str dna.String) dna.String {
	switch {
	case str.Match(`(?mis)MP3`) == true:
		return "mp3"
	case str.Match(`(?mis)M4A`) == true:
		return "m4a"
	case str.Match(`(?mis)MP4`) == true:
		return "mp4"
	case str.Match(`(?mis)FLAC`) == true:
		return "flac"
	case str.Match(`(?mis)FLV`) == true:
		return "flv"
	default:
		dna.Log("No type found at: " + str.String())
		return ""
	}
}
Ejemplo n.º 4
0
func getSection(section dna.String) APIAwardSection {
	var awards = []APIAward{}
	var name dna.String = ""
	var sectionType dna.String = ""
	var awardType dna.Int = 0

	nameArr := section.FindAllString(`(?mis)<h2 class="headline">.+?</h2>`, -1)
	if nameArr.Length() > 0 {
		name = nameArr[0].RemoveHtmlTags("").Trim()
		switch {
		case name.Match("Singles") == true:
			sectionType = "SINGLE"
			awardType = 2
		case name.Match("APIAlbums") == true:
			sectionType = "ALBUM"
			awardType = 1

		}
	}

	if name.Match("Grammy Awards") == true {
		return getGrammyAPIAwardSection(section)
	}

	tbody := section.FindAllString(`(?mis)<tbody>.+?</tbody>`, -1)
	if tbody.Length() > 0 {
		rows := tbody[0].FindAllString(`(?mis)<tr>.+?</tr>`, -1)
		awards = rows.Map(func(row dna.String, idx dna.Int) APIAward {
			var (
				id      dna.Int    = 0
				year    dna.Int    = 0
				chart   dna.String = ""
				title   dna.String = ""
				peak    dna.Int    = 0
				winners            = []Person{}
				award   dna.String = ""
			)

			yearArr := row.FindAllString(`(?mis)<td class="year".+?</div>`, 1)
			if yearArr.Length() > 0 {
				year = yearArr[0].RemoveHtmlTags("").Trim().ToInt()
			}

			peakArr := row.FindAllString(`(?mis)<td class="peak".+?</td>`, 1)
			if peakArr.Length() > 0 {
				peak = peakArr[0].RemoveHtmlTags("").Trim().ToInt()
			}

			charArr := row.FindAllString(`(?mis)<div class="chart-name">.+?</div>`, 1)
			if charArr.Length() > 0 {
				chart = charArr[0].RemoveHtmlTags("").DecodeHTML().Trim()
			}

			titleArr := row.FindAllString(`<a href=".+</a>`, 1)
			if titleArr.Length() > 0 {
				title = titleArr[0].RemoveHtmlTags("").DecodeHTML().Trim()
			}

			var match dna.String = ""
			switch sectionType {
			case "SINGLE":
				match = `<a href=.+mt([0-9]+)"`
			case "ALBUM":
				match = `<a href=.+mw([0-9]+)"`
			default:
				match = `<a href=.+mw([0-9]+)"`
			}
			idArr := row.FindAllStringSubmatch(match, 1)
			if len(idArr) > 0 {
				id = idArr[0][1].ToInt()
			}

			return APIAward{
				Id:      id,
				Title:   title,
				Year:    year,
				Chart:   chart,
				Peak:    peak,
				Type:    awardType,
				Winners: winners,
				Award:   award,
			}
		}).([]APIAward)
	}
	return APIAwardSection{Name: name, Type: sectionType, Awards: awards}
}