<commit_before>package music
import (
    "errors"
    "net/http"
    "encoding/xml"
    "net/url"
    "time"
    "io/ioutil"
    "strings"
    "logger"
)

type RootResponse struct {
    XMLName xml.Name `xml:"metadata"`
    Releases []Release `xml:"release-list>release"`
}

type Release struct {
    //XMLName xml.Name `xml:"release"`
    //Field string `xml:"field"`
    Id string `xml:"id,attr"`
    Group ReleaseGroup `xml:"release-group"`
}

type ReleaseGroup struct {
    Id string `xml:"id,attr"`
}

func (rl RootResponse)GetUrl()(string,error){
    if len(rl.Releases) == 0 {
        return "",errors.New("Impossible to get id")
    }
    // read 10 firsts
    for i:= 0 ; i < 10 && i < len(rl.Releases) ; i++{
        r := rl.Releases[i]
        if r.Group.Id != "" {
            // Check if exist
            urlImage := "http://coverartarchive.org/release-group/" + r.Group.Id + "/front-250"
            resp,_ := http.Get(urlImage)
            if resp.StatusCode == 200 {
                return urlImage,nil
            }
        }
        if r.Id != "" {
            urlImage := "http://coverartarchive.org/release/" + r.Id + "/front-250"
            resp,_ := http.Get(urlImage)
            if resp.StatusCode == 200 {
                return urlImage,nil
            }
        }
    }
    return "",errors.New("No id")
}

func extractInfo(data []byte)(string,error){
    var r RootResponse
    xml.Unmarshal(data,&r)
    return r.GetUrl()
}

// key if composed of artist-album
var coverCache = make(map[string]string)

// use to request music brainz one time max by second
var lastGet = 0

func checkLastGet(){
    defer func(){
        lastGet = time.Now().Nanosecond()
    }()<commit_msg>Close socket after cover request<commit_after>package music
import (
    "errors"
    "net/http"
    "encoding/xml"
    "net/url"
    "time"
    "io/ioutil"
    "strings"
    "logger"
)

type RootResponse struct {
    XMLName xml.Name `xml:"metadata"`
    Releases []Release `xml:"release-list>release"`
}

type Release struct {
    //XMLName xml.Name `xml:"release"`
    //Field string `xml:"field"`
    Id string `xml:"id,attr"`
    Group ReleaseGroup `xml:"release-group"`
}

type ReleaseGroup struct {
    Id string `xml:"id,attr"`
}

func (rl RootResponse)GetUrl()(string,error){
    if len(rl.Releases) == 0 {
        return "",errors.New("Impossible to get id")
    }
    // read 10 firsts
    for i:= 0 ; i < 10 && i < len(rl.Releases) ; i++{
        r := rl.Releases[i]
        if r.Group.Id != "" {
            // Check if exist
            urlImage := "http://coverartarchive.org/release-group/" + r.Group.Id + "/front-250"
            resp,_ := http.Get(urlImage)
            if resp != nil && resp.Body!=nil {
                defer resp.Body.Close()
            }
            if resp.StatusCode == 200 {
                return urlImage,nil
            }
        }
        if r.Id != "" {
            urlImage := "http://coverartarchive.org/release/" + r.Id + "/front-250"
            resp,_ := http.Get(urlImage)
            if resp != nil && resp.Body!=nil {
                defer resp.Body.Close()
            }
            if resp.StatusCode == 200 {
                return urlImage,nil
            }
        }
    }
    return "",errors.New("No id")
}

func extractInfo(data []byte)(string,error){
    var r RootResponse
    xml.Unmarshal(data,&r)
    return r.GetUrl()
}

// key if composed of artist-album
var coverCache = make(map[string]string)

// use to request music brainz one time max by second
var lastGet = 0

func checkLastGet(){
    defer func(){
        lastGet = time.Now().Nanosecond()
    }()
{'fraction_non_alphanumeric': 0.1470669237124759, 'fraction_numerical': 0.010465436518865326, 'mean_word_length': 2.0241465445462117, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 22}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2713130', 'n_tokens_mistral': 1191, 'n_tokens_neox': 1140, 'n_words': 282}