Exemplo n.º 1
0
Arquivo: album.go Projeto: olragon/dna
func getLabelFromDesc(desc dna.String) dna.String {
	var ret dna.String
	label := desc.FindAllString(`(?i)label:?.+`, 1)
	if label.Length() > 0 {
		ret = label[0].ReplaceWithRegexp(`(?i)label:?`, "").Trim()
		if ret.FindAllString(`(?mis)(.)?Publisher(\s)+:?.+`, 1).Length() > 0 {
			ret = ret.ReplaceWithRegexp(`(?mis)(.)?Publisher(\s)+:?`, "").Trim()
		}
		return ret
	}
	if desc.FindAllString(`℗.+`, 1).Length() > 0 {
		ret = desc.FindAllString(`℗.+`, 1)[0].ReplaceWithRegexp(`℗`, "").ReplaceWithRegexp(`[0-9]{4}`, "").Trim()
		return ret
	}
	if label.Length() > 0 {
		ret = label[0].ReplaceWithRegexp(`(?mis)/?PUBLISHER(\s+)?:?`, "").Trim()
		return ret
	}

	label = desc.FindAllString(`(?mis).?Publisher(\s)+:?.+`, 1)
	if label.Length() > 0 {
		ret = label[0].ReplaceWithRegexp(`(.+)?Publisher(\s)+:?`, "").Trim()
	}
	return ret
}
Exemplo n.º 2
0
func getVideoUrl(str, resolution dna.String) *VideoUrl {
	su := NewVideoUrl()
	su.Resolution = resolution
	su.Type = getType(str)
	su.Link = str.GetTagAttributes("href").ReplaceWithRegexp(`(http.+/).+(\..+$)`, "${1}file-name${2}")
	size := str.FindAllString(`[0-9\.]+ MB`, -1)
	if size.Length() > 0 {
		su.Size = size[0].ParseBytesFormat() / 1000
	}
	return su

}
Exemplo n.º 3
0
Arquivo: album.go Projeto: olragon/dna
func getGenresFromDesc(desc dna.String) dna.StringArray {
	var ret dna.StringArray
	genres := desc.FindAllString(`(?i)genres?(\s+)?:?.+`, 1)
	// "Released:" found in album id: 836258
	if genres.Length() > 0 {
		ret = dna.StringArray(genres[0].ReplaceWithRegexp(`(?mis)genres?(\s+)?:?`, "").ReplaceWithRegexp(`\.?\s*Released:.+`, "").Trim().Split(",").Map(func(val dna.String, idx dna.Int) dna.String {
			return val.ReplaceWithRegexp(":", "").Trim()
		}).([]dna.String))
		if ret.Length() == 1 {
			arr := dna.StringArray{}
			if ret[0].FindAllString(`(?mis)K-Pop`, 1).Length() > 0 {
				arr.Push("Korean Pop")
				arr.Push(ret[0].ReplaceWithRegexp(`(?mis)\(?K-Pop\)?`, "").Trim())
				ret = arr
			}
		}
	}
	return ret.SplitWithRegexp(` > `).SplitWithRegexp(`/`)
}
Exemplo n.º 4
0
func getTSGM(data *dna.String, kind dna.String) dna.String {
	var itemArr dna.StringArray
	switch kind {
	case "genres":
		itemArr = data.FindAllString(`(?mis)<h4>Genre</h4>(.+?)</div>`, 1)
	case "styles":
		itemArr = data.FindAllString(`(?mis)<h4>Styles</h4>(.+?)</div>`, 1)
	case "moods":
		itemArr = data.FindAllString(`(?mis)<h4>Album Moods</h4>(.+?)</div>`, 1)
	case "themes":
		itemArr = data.FindAllString(`(?mis)<h4>Themes</h4>(.+?)</div>`, 1)
	default:
		panic("Wrong kind!!!")
	}
	if itemArr.Length() > 0 {
		catArr := itemArr[0].FindAllString(`<a href=.+?</a>`, -1)
		categories := catArr.Map(func(val dna.String, idx dna.Int) Category {
			var idArr []dna.StringArray
			var id dna.Int = 0
			name := val.RemoveHtmlTags("")
			if kind == "moods" {
				idArr = val.FindAllStringSubmatch(`xa([0-9]+)`, 1)
			} else {
				idArr = val.FindAllStringSubmatch(`ma([0-9]+)`, 1)
			}
			if len(idArr) > 0 {
				id = idArr[0][1].ToInt()
			}
			return Category{id, name}
		}).([]Category)

		if len(categories) > 0 {
			bCat, merr := json.Marshal(categories)
			if merr != nil {
				return "[]"
			} else {
				return dna.String(string(bCat))
			}
		} else {
			return "[]"
		}
	} else {
		return "[]"
	}

}
Exemplo n.º 5
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}
}
Exemplo n.º 6
0
func getGrammyAPIAwardSection(section dna.String) APIAwardSection {
	var awards = []APIAward{}
	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 = ""
				atype   dna.Int    = 0
			)

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

			atypeArr := row.FindAllString(`(?mis)<div class="type">.+?</div>`, 1)
			if atypeArr.Length() > 0 {
				switch atypeArr[0].RemoveHtmlTags("").Trim() {
				case "T":
					atype = 2
				case "A":
					atype = 1
				default:
					atype = 0
				}
			}

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

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

			winnerArr := row.FindAllString(`<a href=".+?</a>`, -1)
			winners = winnerArr.Map(func(winner dna.String, idx dna.Int) Person {
				var winnerName dna.String = ""
				var winnerId dna.Int = 0
				winnerName = winner.RemoveHtmlTags("").Trim()
				winnerIdArr := winner.FindAllStringSubmatch(`<a href=.+mn([0-9]+)`, 1)
				if len(winnerIdArr) > 0 {
					winnerId = winnerIdArr[0][1].ToInt()
				}
				return Person{Id: winnerId, Name: winnerName}
			}).([]Person)

			return APIAward{
				Id:      id,
				Title:   title,
				Year:    year,
				Chart:   chart,
				Peak:    peak,
				Type:    atype,
				Winners: winners,
				Award:   award,
			}
		}).([]APIAward)
		return APIAwardSection{Name: "Grammy Awards", Type: "ALBUMs & SONGS", Awards: awards}
	} else {
		return APIAwardSection{}
	}

}