func init() { n := EncodingForIndex(NativeEncoding) for i, e := range EncodingMap { Decoders[i], _ = iconv.NewConverter(e.Name, n) Encoders[i], _ = iconv.NewConverter(n, e.Name) } }
func GetSosoMP3URL(data string) (urls []string, songName []string, singer []string, suc bool) { suc = true re, _ := regexp.Compile("@@(.*)@@.*@@(.*)@@.*@@.*@@.*@@.*@@FI(http.*);;") list := re.FindAllStringSubmatch(data, 3) if len(list) < 1 { suc = false return } fmt.Println("执行。。。。。。。。") //fmt.Printf("%v\n", list) urls = make([]string, len(list)) songName = make([]string, len(list)) singer = make([]string, len(list)) converter, _ := iconv.NewConverter("GBK", "utf-8") for i, value := range list { songName[i], _ = converter.ConvertString(value[1]) singer[i], _ = converter.ConvertString(value[2]) //fmt.Printf("%v\n%v\n%v\n%v\n", value[0], value[1], value[2], value[3]) subre, _ := regexp.Compile("(\\d)+") result := subre.FindAllString(value[3], 2) if result == nil || len(result) != 2 { urls[i] = value[3] } else { steam, _ := strconv.ParseInt(result[0], 10, 32) songid, _ := strconv.ParseInt(result[1], 10, 32) songid = songid - 12000000 + 30000000 urls[i] = "http://stream" + strconv.FormatInt((steam+10), 10) + ".qqmusic.qq.com/" + strconv.FormatInt(songid, 10) + ".mp3" } } return }
// renderIconvConverter wrapper function for iconv converter. func renderIconvConverter(fromEncoding string) func([]byte) []byte { if fromEncoding == "utf8" || fromEncoding == "utf-8" { return func(str []byte) []byte { return str } } return func(content []byte) []byte { converter, _ := iconv.NewConverter(fromEncoding, "utf-8") var out []byte out = make([]byte, len(content)*2) _, outLen, _ := converter.Convert(content, out) return out[:outLen] } }
func convertToGBK(source []byte) []byte { cv, err := iconv.NewConverter("gbk", "utf-8") if err != nil { logex.Error(err) return source } defer cv.Close() println(string(source)) ret, err := cv.ConvertString(string(source)) if err != nil { logex.Error(err) return []byte(ret) } return []byte(ret) }
func convertString(data string, from, to string) string { conv, err := iconv.NewConverter(from, to) if err != nil { logex.Error(err) return data } defer conv.Close() source := []byte(data) total := 0 buf := bytes.NewBuffer(nil) for total < len(source) { output := make([]byte, len(source)) read, written, err := conv.Convert(source[total:], output) buf.Write(output[:written]) total += read if err != nil { buf.WriteByte(source[total]) total += 1 } } return string(buf.Bytes()) }
// ID for this plugin implementation. const ( ID string = "netcoupe" ) const ( // baseURL is the base url for the netcoupe website baseURL string = "http://netcoupe.net" // flightDetailURL is the subpath to fetch details of flight with 'ID' flightDetailURL string = "/Results/FlightDetail.aspx?FlightID=" // maxIDGap is the max num of subsequent missing IDs when crawling flights maxIDGap int = 3 ) // iso2UTF is a ISO-8859-1 to UTF-8 converter used to convert netcoupe's flight details var iso2UTF, _ = iconv.NewConverter("ISO-8859-1", "UTF-8") var reNom = regexp.MustCompile("DisplayContactDetail\\(.\\d*.,\\s.hasPrevious...>([^<]*)</a>") var reCategorie = regexp.MustCompile("(?s)Cat.gorie :</b>\\s*</div>\\s*</td>\\s*<td>\\s*<div align=\"left\">([^<]*)</div>") var reClub = regexp.MustCompile("(?s)DisplayClubDetail\\(.\\d*.,\\s.hasPrevious...>([^<]*)</a>") var reDate = regexp.MustCompile("(?s)Date :</b>\\s*</div>\\s*</td>\\s*<td>\\s*<div align=\"left\">\\s*(\\d+/\\d+/\\d+)\\s*</div>") var reDepart = regexp.MustCompile("(?s)A.rodrome de d.part :</b>\\s*</div>\\s*</td>\\s*<td>\\s*<div align=\"left\">([^<]*)</div>") var reRegion = regexp.MustCompile("(?s)R.gion :</b>\\s*</div>\\s*</td>\\s*<td>\\s*<div align=\"left\">([^<]*)</div>") var rePays = regexp.MustCompile("(?s)Pays :</b>\\s*</div>\\s*</td>\\s*<td>\\s*<div align=\"left\">([^<]*)</div>") var reDistance = regexp.MustCompile("(?s)Distance :</b>\\s*</div>\\s*</td>\\s*<td>\\s*<div align=\"left\">(.*)\\s* kms\\s*</div>") var rePoints = regexp.MustCompile("(?s)Points :</b>\\s*</div>\\s*</td>\\s*<td>\\s*<div align=\"left\">\\s*(\\S*)\\s*</div>") var rePlaneur = regexp.MustCompile("(?s)Planeur :</b>\\s*</div>\\s*</td>\\s*<td>\\s*<div align=\"left\">\\s*<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\\s*<tbody>\\s*<tr>\\s*<td valign=\"middle\">([^&]*) \\s*</td>") var reTypeCircuit = regexp.MustCompile("(?s)Type de circuit :</b>\\s*</div>\\s*</td>\\s*<td>\\s*<div align=\"left\">([^<]*)</div>") var reVitesse = regexp.MustCompile("(?s)Vitesse moyenne du circuit :</b>\\s*</div>\\s*</td>\\s*<td>\\s*<div align=\"left\">\\s*(.*) km/h\\s*</div>") var rePointDepart = regexp.MustCompile("(?s)Point de d.part :</b>\\s*</div>\\s*</td>\\s*<td>\\s*<div align=\"left\">([^<]*)</div>") var rePointVirage1 = regexp.MustCompile("(?s)Point de virage n.1 :</b>\\s*</div>\\s*</td>\\s*<td>\\s*<div align=\"left\">([^<]*)</div>")