Exemple #1
0
// ToShortForm returns a short form string representing a site name.
// For example: NhacSo is for "ns"
func ToShortForm(siteid dna.Int) dna.String {
	switch siteid {
	case NhacSo:
		return "ns"
	case Zing:
		return "zi"
	case NhacCuaTui:
		return "nct"
	case ChaCha:
		return "cc"
	case NhacVui:
		return "nv"
	case ChiaSeNhac:
		return "csn"
	case HDViet:
		return "hdv"
	case Keeng:
		return "ke"
	case SongFreaks:
		return "sf"
	case AllMusic:
		return "am"
	case LyricWiki:
		return "lw"
	case MetroLyrics:
		return "ml"
	case LyricFind:
		return "lf"
	case VietGiaiTri:
		return "vg"
	case MusicVNN:
		return "mv"
	default:
		panic("Cannot convert siteid to short form - GOT:" + siteid.ToString().String())
	}
}
Exemple #2
0
func (qv *QueryValues) SetIdKey(id dna.Int) {
	qv.mutex.Lock()
	qv.Values.Set("sfid", id.ToString().String())
	qv.mutex.Unlock()
}
Exemple #3
0
// Encrypt encodes an integer ID into a key
func Encrypt(id dna.Int) dna.String {
	return dna.StringArray(id.ToHex().Split("").Map(
		func(v dna.String, i dna.Int) dna.String {
			return a[b.IndexOf(v)]
		}).([]dna.String)).Join("")
}
Exemple #4
0
func getCategory(songs *[]*Song, genre Genre, page dna.Int) <-chan bool {
	channel := make(chan bool, 1)
	go func() {
		link := "http://nhacso.net/bai-hat-theo-the-loai-" + genre.Id.ToString() + "/joke-link-2-" + page.ToString() + ".html"
		// dna.Log(link)
		result, err := http.Get(link)
		if err == nil {
			data := &result.Data

			// transform string {"2":[0,3,5,7,9,11,13,15,29],"10":[1,2,4,6,8,]}
			// to  map[dna.Int]dna.Int{20:2, 28:2, 4:10, 12:10} Ex: map[29] = 2
			temp := data.FindAllStringSubmatch(`getCategory.+'(\{.+\})'`, -1)
			mapping := map[dna.Int]dna.Int{}
			if len(temp) > 0 && temp[0].Length() > 0 {
				vals := temp[0][1].FindAllString(`"[0-9]+":\[[0-9,]+?\]`, -1)
				if vals.Length() > 0 {
					for _, val := range vals {
						target := val.FindAllStringSubmatch(`"(.+)"`, -1)[0][1].ToInt()
						arr := val.FindAllStringSubmatch(`\[(.+)\]`, -1)[0][1].Split(",").ToIntArray()
						for _, itm := range arr {
							mapping[itm] = target
						}
					}
				}
			}
			// Finding cat id for each song. cats var is 2-dimentional array.
			// Each index of it represents the correspondent song, its value is the categories the song belongs to
			catStrings := data.FindAllString(`Thể loại :.+`, -1)
			cats := []dna.IntArray{}
			for _, val := range catStrings {
				tagids := dna.IntArray{}
				tmp := val.FindAllStringSubmatch(`cate_tag_song_([0-9]+)`, -1)
				if len(tmp) > 0 {
					for _, el := range tmp {
						tagids.Push(el[1].ToInt())
					}
				}
				cats = append(cats, tagids)
			}
			// Log(cats)

			// get songids
			temps := data.FindAllStringSubmatch(`play" id="blocksongtag_([0-9]+)`, -1)
			songids := dna.IntArray{}
			if len(temps) > 0 {
				for _, val := range temps {
					songids.Push(val[1].ToInt())
				}
			}

			tmpsongs := &[]*Song{}
			for idx, songid := range songids {
				song := NewSong()
				song.Id = songid
				category := dna.StringArray{}
				for _, val := range cats[idx] {
					if mapping[val] > 0 && mapping[val] < CatTags.Length() {
						if CatTags[mapping[val]] != "" {
							category.Push(CatTags[mapping[val]])
						}
					} else {
						mess := dna.Sprintf("WRONG INDEX AT CATTAGS: %v %v %v - %v", mapping[val], genre, page, link)
						panic(mess.String())
					}

				}
				category.Push(genre.Name)
				song.Category = transformCats(category.Unique()).Unique()
				*tmpsongs = append(*tmpsongs, song)
			}
			*songs = *tmpsongs

		}
		channel <- true

	}()
	return channel
}
Exemple #5
0
// This function will encode the Id of nhacso into cipher text.
func Encrypt(id dna.Int) dna.String {
	return dna.StringArray(id.ToString().Split("").Map(
		func(v dna.String, i dna.Int) dna.String {
			return ns[6-i][v.ToInt()]
		}).([]dna.String)).Join("")
}
Exemple #6
0
func (urlb *URLBuilder) GetPlaylistsByTopic(topicId dna.Int) dna.String {
	s1 := "get-playlist-by-topic" + topicId.ToString() + TOKEN_KEY + urlb.tsStr
	return dna.Sprintf("%v?secretkey=%v&action=get-playlist-by-topic&deviceinfo=%v&topicid=%v&time=%v&token=%v", BASE_URL, SECRET_KEY, DEVICE_INFOR, topicId, urlb.tsStr, getMD5(s1))
}
Exemple #7
0
func (urlb *URLBuilder) GetPlaylistInfo(albumid dna.Int) dna.String {
	//NOT COMPLETE
	s1 := "get-playlist-info" + albumid.ToString() + TOKEN_KEY + urlb.tsStr
	return dna.Sprintf("%v?secretkey=%v&action=get-playlist-info&deviceinfo=%v&playlistid=%v&time=%v&token=%v", BASE_URL, SECRET_KEY, DEVICE_INFOR, albumid, urlb.tsStr, getMD5(s1))
}
Exemple #8
0
func (urlb *URLBuilder) GetSongLyric(songid dna.Int) dna.String {
	s1 := "get-lyric" + songid.ToString() + TOKEN_KEY + urlb.tsStr
	return dna.Sprintf("%v?secretkey=%v&action=get-lyric&deviceinfo=%v&songid=%v&time=%v&token=%v", BASE_URL, SECRET_KEY, DEVICE_INFOR, songid, urlb.tsStr, getMD5(s1))
}
Exemple #9
0
func (urlb *URLBuilder) GetVideoInfo(videoid dna.Int) dna.String {

	//NOT COMPLETE
	s1 := "get-video-detail" + videoid.ToString() + TOKEN_KEY + urlb.tsStr
	return dna.Sprintf("%v?secretkey=%v&action=get-video-detail&deviceinfo=%v&videoid=%v&time=%v&token=%v", BASE_URL, SECRET_KEY, DEVICE_INFOR, videoid, urlb.tsStr, getMD5(s1))
}
Exemple #10
0
func (urlb *URLBuilder) GetSongsOfPlaylist(albumid dna.Int) dna.String {
	s1 := "get-song-by-playlistid" + albumid.ToString() + TOKEN_KEY + urlb.tsStr
	return dna.Sprintf("%v?secretkey=%v&action=get-song-by-playlistid&deviceinfo=%v&playlistid=%v&time=%v&token=%v", BASE_URL, SECRET_KEY, DEVICE_INFOR, albumid, urlb.tsStr, getMD5(s1))
}
Exemple #11
0
func (urlb *URLBuilder) GetSongsByGenre(genreId, pageIndex, pageSize dna.Int) dna.String {
	s1 := "get-song-by-genre" + genreId.ToString() + pageIndex.ToString() + pageSize.ToString() + TOKEN_KEY + urlb.tsStr
	return dna.Sprintf("%v?secretkey=%v&action=get-song-by-genre&deviceinfo=%v&genreid=%v&pageindex=%v&pagesize=%v&time=%v&token=%v", BASE_URL, SECRET_KEY, DEVICE_INFOR, genreId, pageIndex, pageSize, urlb.tsStr, getMD5(s1))
}
Exemple #12
0
func (urlb *URLBuilder) GetArtistInfo(artistid dna.Int) dna.String {
	s1 := "get-artist-detail" + artistid.ToString() + TOKEN_KEY + urlb.tsStr
	return dna.Sprintf("%v?secretkey=%v&action=get-artist-detail&deviceinfo=%v&artistid=%v&time=%v&token=%v", BASE_URL, SECRET_KEY, DEVICE_INFOR, artistid, urlb.tsStr, getMD5(s1))
}
Exemple #13
0
func (urlb *URLBuilder) GetPlaylistsRelated(playlistid dna.Int) dna.String {
	s1 := "get-playlist-related" + playlistid.ToString() + TOKEN_KEY + urlb.tsStr
	return dna.Sprintf("%v?secretkey=%v&action=get-playlist-related&deviceinfo=%v&playlistid=%v&time=%v&token=%v", BASE_URL, SECRET_KEY, DEVICE_INFOR, playlistid, urlb.tsStr, getMD5(s1))
}
Exemple #14
0
func getAPIFullSongWithMetadata(id dna.Int) (*APIFullSong, error) {
	var apisong = new(APIFullSong)
	var link string

	link = "http://api.lyricfind.com/metadata.do?apikey=" + METADATA_KEY + "&reqtype=metadata&trackid=amg:" + id.ToString().String() + "&displaykey=" + API_KEY + "&output=json"
	result, err := http.Get(dna.String(link))
	if err == nil {
		data := &result.Data
		json.Unmarshal([]byte(*data), apisong)
		switch apisong.Response.Code {
		case 100, 101, 111, 102:
			return apisong, nil
		default:
			return nil, errors.New(dna.Sprintf("LyricFind - Song ID: %v - %v %v", id, apisong.Response.Code, apisong.Response.Description).String())
		}
		return apisong, nil
	} else {
		return nil, err
	}
}
Exemple #15
0
func GetAPISong(id dna.Int) (*APISong, error) {
	var apisong = new(APISong)
	link := "https://api.lyricfind.com/lyric.do?apikey=" + API_KEY + "&reqtype=default&trackid=amg:" + id.ToString().String() + "&output=json"
	// result, err := GetProxy(dna.String(link), 0)
	result, err := http.Get(dna.String(link))
	if err == nil {
		data := &result.Data
		json.Unmarshal([]byte(*data), apisong)
		switch apisong.Response.Code {
		case 100, 101, 111, 102:
			return apisong, nil
		default:
			return nil, errors.New(dna.Sprintf("LyricFind - Song ID: %v - %v %v", id, apisong.Response.Code, apisong.Response.Description).String())
		}
		return apisong, nil
	} else {
		return nil, err
	}
}
Exemple #16
0
func getAlbumCategory(albums *[]*Album, genre Genre, page dna.Int) <-chan bool {
	channel := make(chan bool, 1)
	go func() {
		link := "http://nhacso.net/album-theo-the-loai-" + genre.Id.ToString() + "/joke-link-2-" + page.ToString() + ".html"
		// dna.Log(link)
		result, err := http.Get(link)
		if err == nil {
			data := &result.Data
			temp := data.FindAllStringSubmatch(`getTotalSongInAlbum\('(.+)', 'album_new_totalsong_'`, -1)
			tmpalbums := &[]*Album{}
			if len(temp) > 0 {
				albumList := temp[0][1].Split(",").ToIntArray()
				for _, albumid := range albumList {
					album := NewAlbum()
					album.Id = albumid
					cats := dna.StringArray{genre.Name}
					album.Category = transformCats(cats)
					*tmpalbums = append(*tmpalbums, album)
				}
			}
			*albums = *tmpalbums

		}
		channel <- true

	}()
	return channel
}