本文整理汇总了Golang中dna/http.Get函数的典型用法代码示例。如果您正苦于以下问题:Golang Get函数的具体用法?Golang Get怎么用?Golang Get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getPlaylistM3u8
func getPlaylistM3u8(episode *Episode) <-chan bool {
channel := make(chan bool, 1)
go func() {
result, err := http.Get(episode.Link)
if err == nil {
episode.PlaylistM3u8 = result.Data
m3u8Filenames := episode.PlaylistM3u8.FindAllString(`.+m3u8`, -1)
// Get file with highest resolution
if m3u8Filenames.Length() > 0 {
lastM3u8Filename := m3u8Filenames[m3u8Filenames.Length()-1]
baseM3u8Url := episode.Link.ReplaceWithRegexp(`[^/]+m3u8$`, "")
lastM3u8FilePath := baseM3u8Url + lastM3u8Filename
resultm3u8, errm3u8 := http.Get(lastM3u8FilePath)
if errm3u8 == nil {
episode.EpisodeM3u8 = resultm3u8.Data.ReplaceWithRegexp(`(.+\.ts)`, baseM3u8Url+"${1}")
// ioutil.WriteFile("./dump/test.m3u8", episode.EpisodeM3u8.ToBytes(), 0644)
}
}
}
channel <- true
}()
return channel
}
示例2: getSrtContent
func getSrtContent(episode *Episode, isEn dna.Bool) <-chan bool {
channel := make(chan bool, 1)
go func() {
var result *http.Result
var err error
if isEn == true {
result, err = http.Get(episode.SubtitleExt[1])
} else {
result, err = http.Get(episode.SubtitleExt[0])
}
if err == nil {
if isEn == true {
// It is hard to detect an encoding of a string.
// Therefore we convert them to BASE64
episode.EnSrt = dna.String(base64.StdEncoding.EncodeToString(result.Data.ToBytes()))
// episode.EnSrt = ISO8859_1ToUTF8String(result.Data.ToBytes())
// ioutil.WriteFile("./dump/test_en_srt.srt", result.Data.ToBytes(), 0644)
} else {
// Vietnamese Subtitle encoded in UTF-16 Little Ending
// It has to be converted to UTF-8
if result.Data.Match(`^[0-9a-fA-F]+$`) == false {
// episode.ViSrt = UTF16ToUTF8String(result.Data.ToBytes(), binary.LittleEndian)
episode.ViSrt = dna.String(base64.StdEncoding.EncodeToString(result.Data.ToBytes()))
}
// dna.Log(result.Data.Substring(0, 100))
}
}
channel <- true
}()
return channel
}
示例3: getSongFromXML
// 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
}
示例4: getAPIAlbumSimilars
// getAPIAlbumSimilars fetches album's similars
// with the following url format:
// http://www.allmusic.com/album/google-bot-mw0002585207/similar/mobile
func getAPIAlbumSimilars(album *APIAlbum) <-chan bool {
channel := make(chan bool, 1)
go func() {
link := "http://www.allmusic.com/album/google-bot-mw" + album.Id.ToFormattedString(10, true) + "/similar/mobile"
result, err := http.Get(link)
if err == nil {
data := &result.Data
idsArr := data.FindAllString(`<a href=".+`, -1)
ids := dna.IntArray(idsArr.Map(func(val dna.String, idx dna.Int) dna.Int {
idArr := val.FindAllStringSubmatch(`mw([0-9]+)`, -1)
if len(idArr) > 0 {
return idArr[0][1].ToInt()
} else {
return 0
}
}).([]dna.Int)).Filter(func(val dna.Int, idx dna.Int) dna.Bool {
if val > 0 {
return true
} else {
return false
}
})
if ids.Length() > 0 {
album.Similars = ids
}
}
channel <- true
}()
return channel
}
示例5: getAlbumCategory
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
}
示例6: getAPIAlbumAwards
// getAPIAlbumAwards fetches album's awards
// with the following url format:
// http://www.allmusic.com/album/google-bot-mw0002585207/similar/mobile
func getAPIAlbumAwards(album *APIAlbum) <-chan bool {
channel := make(chan bool, 1)
go func() {
link := "http://www.allmusic.com/album/google-bot-mw" + album.Id.ToFormattedString(10, true) + "/awards/mobile"
result, err := http.Get(link)
if err == nil {
data := &result.Data
var awardSections = []APIAwardSection{}
sectionsArr := data.FindAllString(`(?mis)<section class=.+?</section>`, -1)
sectionsArr.ForEach(func(section dna.String, idx dna.Int) {
awardSections = append(awardSections, getSection(section))
})
if len(awardSections) > 0 {
bAwards, derr := json.Marshal(awardSections)
if derr == nil {
album.Awards = dna.String(string(bAwards))
}
}
}
channel <- true
}()
return channel
}
示例7: getSongPlays
// getSongPlays returns song plays
func getSongPlays(song *Song, body dna.String) {
// POST METHOD
// link := "http://www.nhaccuatui.com/interaction/api/hit-counter?jsoncallback=nct"
// http.DefaulHeader.Set("Content-Type", "application/x-www-form-urlencoded ")
// result, err := http.Post(dna.String(link), body)
// // Log(link)
// if err == nil {
// data := &result.Data
// tpl := dna.String(`{"counter":([0-9]+)}`)
// playsArr := data.FindAllStringSubmatch(tpl, -1)
// if len(playsArr) > 0 {
// song.Plays = playsArr[0][1].ToInt()
// }
// }
// GET METHOD
link := "http://www.nhaccuatui.com/interaction/api/counter?jsoncallback=nct&listSongIds=" + song.Id.ToString()
result, err := http.Get(link)
if err == nil {
data := &result.Data
tpl := dna.Sprintf(`{"%v":([0-9]+)}`, song.Id)
// dna.Log(data)
playsArr := data.FindAllStringSubmatch(tpl, -1)
if len(playsArr) > 0 {
song.Plays = playsArr[0][1].ToInt()
}
}
}
示例8: getExercises
func getExercises(cat Category) <-chan Exercises {
channel := make(chan Exercises)
exercises := Exercises{}
go func() {
link := "http://www.indiabix.com" + cat.Url
// dna.Log(link)
result, err := http.Get(link)
if err == nil {
data := &result.Data
exercisesArr := data.FindAllStringSubmatch(`(?mis)ib-lefttbar-container.+Exercise(.+?)id="ib-main-bar"`, 1)
// dna.Log(exercisesArr)
if len(exercisesArr) > 0 {
sectionArr := exercisesArr[0][1].FindAllString(`<a href=.+?</a>`, -1)
for _, section := range sectionArr {
exc := NewExercise()
exc.Cat = cat
exc.Cat.Url = section.GetTagAttributes("href")
exc.No = exc.Cat.Url.ReplaceWithRegexp(`/$`, "").ReplaceWithRegexp(`^.+/`, "").ToInt()
exercises = append(exercises, *exc)
// dna.Log(exc.Cat.Url.ReplaceWithRegexp(`/$`, "").Replace(`^.+/`, ""))
}
}
}
channel <- exercises
}()
return channel
}
示例9: getGracenoteSongLyric
func getGracenoteSongLyric(artist, title dna.String, song *Song) {
link := "http://lyrics.wikia.com/Gracenote:" + artist.Replace(" ", "_") + ":" + title.Replace(" ", "_")
result, err := http.Get(link)
if err == nil {
data := &result.Data
writersArr := data.FindAllString(`Songwriters.+`, 1)
if writersArr.Length() > 0 {
song.GracenoteSongwriters = writersArr[0].GetTags("em")[0].RemoveHtmlTags("").DecodeHTML()
}
publisheraArr := data.FindAllString(`Publishers.+`, 1)
if publisheraArr.Length() > 0 {
song.GracenotePublishers = publisheraArr[0].GetTags("em")[0].RemoveHtmlTags("").DecodeHTML()
}
lyricArr := data.FindAllStringSubmatch(`(?mis)<div class='lyricbox'>(.+?)<\!--`, 1)
if len(lyricArr) > 0 {
song.GracenoteLyric = lyricArr[0][1].Trim().DecodeHTML().ReplaceWithRegexp(`(?mis)^<div.+?</span></div>`, "").Trim().Replace("<br />", "\n")
}
if song.GracenoteLyric != "" {
song.DownloadGracenoteDone = 1
} else {
song.DownloadGracenoteDone = 0
}
}
}
示例10: getSongXML
// getSongXML returns song from main page
func getSongXML(song *Song) <-chan bool {
channel := make(chan bool, 1)
go func() {
link := "http://www.chacha.vn/player/songXml/" + song.Id.ToString()
result, err := http.Get(link)
// dna.Log(link)
if err == nil && !result.Data.Match(`Không tìm thấy bài hát`) {
data := &result.Data
if data.Match(`<enclosure.+label="320K"`) {
song.Bitrate = 320
link := data.FindAllString(`<enclosure.+label="320K".+/>`, -1)
if link.Length() > 0 {
song.Link = link[0].GetTagAttributes("url")
}
} else {
if data.Match(`<enclosure.+label="128K"`) {
song.Bitrate = 128
link := data.FindAllString(`<enclosure.+label="128K".+?`, -1)
if link.Length() > 0 {
song.Link = link[0].GetTagAttributes("url")
}
}
}
}
channel <- true
}()
return channel
}
示例11: getVideoFromXML
// getVideoFromXML returns video from main page
func getVideoFromXML(video *Video) <-chan bool {
channel := make(chan bool, 1)
go func() {
link := "http://hcm.nhac.vui.vn/asx2.php?type=1&id=" + video.Id.ToString()
result, err := http.Get(link)
// dna.Log(link)
if err == nil {
data := &result.Data
linkArr := data.FindAllStringSubmatch(`<jwplayer:file><\!\[CDATA\[(.+)\]\]></jwplayer:file>`, 1)
if len(linkArr) > 0 {
video.Link = linkArr[0][1].Trim()
switch {
case video.Link.Match("mp3") == true:
video.Type = "song"
case video.Link.Match("(?mis)mp4") == true:
video.Type = "video"
case video.Link.Match("flv") == true:
video.Type = "video"
}
}
}
channel <- true
}()
return channel
}
示例12: GetAPIMovie
func GetAPIMovie(movieid, ep dna.Int) (*APIMovie, error) {
urlb := NewURLBuilder()
var link dna.String = ""
if ep == 0 {
link = urlb.GetMovie(movieid)
} else {
link = urlb.GetEpisole(movieid, ep)
}
// dna.Log(link)
result, err := http.Get(link)
if err == nil {
if result.Data.Match(`"r":"acesstokenkey invalid or expired"`) == true {
return nil, errors.New("ACCESS_TOKEN_KEY invalid or expired")
}
var apiMoveiJSON = &APIMovieJSON{}
errd := json.Unmarshal(result.Data.ToBytes(), apiMoveiJSON)
if errd == nil {
apiMoveiJSON.Movie.MovieId = movieid
apiMoveiJSON.Movie.EpId = ep
return &apiMoveiJSON.Movie, nil
} else {
return nil, errd
}
} else {
return nil, err
}
}
示例13: getSongFormats
func getSongFormats(subject *Subject) <-chan bool {
channel := make(chan bool, 1)
go func() {
link := "http://www.indiabix.com/" + subject.Name.ToDashCase().ToLowerCase()
// dna.Log(link)
result, err := http.Get(link)
if err == nil {
data := &result.Data
tables := data.FindAllString(`(?mis)<table width="100%" id="ib-tbl-topics">.+?</table>`, -1)
for _, table := range tables {
cells := table.FindAllString(`<td>.+?</td>`, -1)
if cells.Length() > 0 {
for _, cell := range cells {
cat := &Category{subject.Name, cell.RemoveHtmlTags(""), cell.GetTagAttributes("href")}
subject.Cats = append(subject.Cats, cat)
// dna.Log(cat)
}
}
}
}
channel <- true
}()
return channel
}
示例14: getSongFromMainPage
// 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
}
示例15: getSongLrc
func getSongLrc(song *Song) {
result, err := http.Get(song.LrcUrl)
if err == nil {
lrc, derr := DecryptLRC(result.Data)
if derr == nil {
song.Lrc = lrc
} else {
dna.Log("ERR WHILE DECRYPT SONG ", song.Id)
dna.Log("-----\n")
}
}
}