mirror of
https://github.com/riwiwa/muzi.git
synced 2026-02-28 11:56:57 -08:00
lastfm import accepts dynamic track amount and now allows scrobbling while
importing
This commit is contained in:
@@ -84,28 +84,28 @@ func JsonToDB(jsonFile string, platform int) {
|
|||||||
if platform == spotify {
|
if platform == spotify {
|
||||||
type Track struct {
|
type Track struct {
|
||||||
Timestamp string `json:"ts"`
|
Timestamp string `json:"ts"`
|
||||||
//Platform string `json:"platform"`
|
Platform string `json:"-"`
|
||||||
Played int `json:"ms_played"`
|
Played int `json:"ms_played"`
|
||||||
//Country string `json:"conn_country"`
|
Country string `json:"-"`
|
||||||
//IP string `json:"ip_addr"`
|
IP string `json:"-"`
|
||||||
Name string `json:"master_metadata_track_name"`
|
Name string `json:"master_metadata_track_name"`
|
||||||
Artist string `json:"master_metadata_album_artist_name"`
|
Artist string `json:"master_metadata_album_artist_name"`
|
||||||
Album string `json:"master_metadata_album_album_name"`
|
Album string `json:"master_metadata_album_album_name"`
|
||||||
//TrackURI string `json:"spotify_track_uri"`
|
TrackURI string `json:"-"`
|
||||||
//Episode string `json:"episode_name"`
|
Episode string `json:"-"`
|
||||||
//Show string `json:"episode_show_name"`
|
Show string `json:"-"`
|
||||||
//EpisodeURI string `json:"spotify_episode_uri"`
|
EpisodeURI string `json:"-"`
|
||||||
//Audiobook string `json:"audiobook_title"`
|
Audiobook string `json:"-"`
|
||||||
//AudiobookURI string `json:"audiobook_uri"`
|
AudiobookURI string `json:"-"`
|
||||||
//AudiobookChapterURI string `json:"audiobook_chapter_uri"`
|
AudiobookChapterURI string `json:"-"`
|
||||||
//AudiobookChapter string `json:"audiobook_chapter_title"`
|
AudiobookChapter string `json:"-"`
|
||||||
//ReasonStart string `json:"reason_start"`
|
ReasonStart string `json:"-"`
|
||||||
//ReasonEnd string `json:"reason_end"`
|
ReasonEnd string `json:"-"`
|
||||||
//Shuffle bool `json:"shuffle"`
|
Shuffle bool `json:"-"`
|
||||||
//Skipped bool `json:"skipped"`
|
Skipped bool `json:"-"`
|
||||||
//Offline bool `json:"offline"`
|
Offline bool `json:"-"`
|
||||||
//OfflineTimestamp int `json:"offline_timestamp"`
|
OfflineTimestamp int `json:"-"`
|
||||||
//Incognito bool `json:"incognito_mode"`
|
Incognito bool `json:"-"`
|
||||||
}
|
}
|
||||||
var tracks []Track
|
var tracks []Track
|
||||||
err := json.Unmarshal(jsonData, &tracks)
|
err := json.Unmarshal(jsonData, &tracks)
|
||||||
@@ -186,32 +186,35 @@ func ImportLastFM() {
|
|||||||
Recenttracks struct {
|
Recenttracks struct {
|
||||||
Track []struct {
|
Track []struct {
|
||||||
Artist struct {
|
Artist struct {
|
||||||
Mbid string `json:"mbid"`
|
Mbid string `json:"-"`
|
||||||
Text string `json:"#text"`
|
Text string `json:"#text"`
|
||||||
} `json:"artist"`
|
} `json:"artist"`
|
||||||
Streamable string `json:"streamable"`
|
Streamable string `json:"-"`
|
||||||
Image []struct {
|
Image []struct {
|
||||||
Size string `json:"size"`
|
Size string `json:"-"`
|
||||||
Text string `json:"#text"`
|
Text string `json:"-"`
|
||||||
} `json:"image"`
|
} `json:"-"`
|
||||||
Mbid string `json:"mbid"`
|
Mbid string `json:"-"`
|
||||||
Album struct {
|
Album struct {
|
||||||
Mbid string `json:"mbid"`
|
Mbid string `json:"-"`
|
||||||
Text string `json:"#text"`
|
Text string `json:"#text"`
|
||||||
} `json:"album"`
|
} `json:"album"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
URL string `json:"url"`
|
Attr struct {
|
||||||
|
Nowplaying string `json:"nowplaying"`
|
||||||
|
} `json:"@attr,omitempty"`
|
||||||
|
URL string `json:"-"`
|
||||||
Date struct {
|
Date struct {
|
||||||
Uts string `json:"uts"`
|
Uts string `json:"uts"`
|
||||||
Text string `json:"#text"`
|
Text string `json:"-"`
|
||||||
} `json:"date"`
|
} `json:"date"`
|
||||||
} `json:"track"`
|
} `json:"track"`
|
||||||
Attr struct {
|
Attr struct {
|
||||||
PerPage string `json:"perPage"`
|
PerPage string `json:"-"`
|
||||||
TotalPages string `json:"totalPages"`
|
TotalPages string `json:"totalPages"`
|
||||||
Page string `json:"page"`
|
Page string `json:"page"`
|
||||||
Total string `json:"total"`
|
Total string `json:"-"`
|
||||||
User string `json:"user"`
|
User string `json:"-"`
|
||||||
} `json:"@attr"`
|
} `json:"@attr"`
|
||||||
} `json:"recenttracks"`
|
} `json:"recenttracks"`
|
||||||
}
|
}
|
||||||
@@ -231,7 +234,10 @@ func ImportLastFM() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
json.NewDecoder(resp.Body).Decode(&data)
|
json.NewDecoder(resp.Body).Decode(&data)
|
||||||
for j := range 100 {
|
for j := range data.Recenttracks.Track {
|
||||||
|
if data.Recenttracks.Track[j].Attr.Nowplaying == "true" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
unixTime, err := strconv.ParseInt(data.Recenttracks.Track[j].Date.Uts, 10, 64)
|
unixTime, err := strconv.ParseInt(data.Recenttracks.Track[j].Date.Uts, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|||||||
6
main.go
6
main.go
@@ -41,8 +41,6 @@ func main() {
|
|||||||
dirSpotifyZip := "./imports/spotify/zip/"
|
dirSpotifyZip := "./imports/spotify/zip/"
|
||||||
dirSpotifyExt := "./imports/spotify/extracted/"
|
dirSpotifyExt := "./imports/spotify/extracted/"
|
||||||
|
|
||||||
dirLastFM := "./imports/lastfm/"
|
|
||||||
|
|
||||||
err := dirCheck(dirImports)
|
err := dirCheck(dirImports)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@@ -59,10 +57,6 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = dirCheck(dirLastFM)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = dbCheck()
|
err = dbCheck()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user