feat(plugin/music): add support for new top mode with top artists or tracks (#569)

This commit is contained in:
Lucas
2021-10-15 16:06:40 +11:00
committed by GitHub
parent a607097bd1
commit 0ea6df9c86
7 changed files with 444 additions and 16 deletions

View File

@@ -62,5 +62,99 @@ export default function({faker, url, options, login = faker.internet.userName()}
},
})
}
else if (/user.gettoptracks/.test(url)) {
console.debug(`metrics/compute/mocks > mocking lastfm api result > ${url}`)
const artist = faker.random.word()
const track = faker.random.words(5)
return ({
status:200,
data:{
toptracks:{
"@attr":{
page:"1",
perPage:"1",
user:"RJ",
total:"100",
pages:"100",
},
track:[
{
artist:{
mbid:"",
name:artist,
},
image:[
{
size:"small",
"#text":faker.image.abstract(),
},
{
size:"medium",
"#text":faker.image.abstract(),
},
{
size:"large",
"#text":faker.image.abstract(),
},
{
size:"extralarge",
"#text":faker.image.abstract(),
},
],
url:faker.internet.url(),
name:track,
mbid:"",
},
],
},
},
})
}
else if (/user.gettopartists/.test(url)) {
console.debug(`metrics/compute/mocks > mocking lastfm api result > ${url}`)
const artist = faker.random.word()
const playcount = faker.random.number()
return ({
status:200,
data:{
topartists:{
"@attr":{
page:"1",
perPage:"1",
user:"RJ",
total:"100",
pages:"100",
},
artist:[
{
image:[
{
size:"small",
"#text":faker.image.abstract(),
},
{
size:"medium",
"#text":faker.image.abstract(),
},
{
size:"large",
"#text":faker.image.abstract(),
},
{
size:"extralarge",
"#text":faker.image.abstract(),
},
],
streamable:"0",
playcount,
url:faker.internet.url(),
name:artist,
mbid:"",
},
],
},
},
})
}
}
}

View File

@@ -61,5 +61,91 @@ export default function({faker, url, options, login = faker.internet.userName()}
},
})
}
else if (/me.top.tracks/.test(url) && (options?.headers?.Authorization === "Bearer MOCKED_TOKEN_ACCESS")) {
console.debug(`metrics/compute/mocks > mocking spotify api result > ${url}`)
const artist = faker.random.words()
const track = faker.random.words(5)
return ({
status:200,
data:{
items:[
{
album:{
album_type:"single",
artists:[
{
name:artist,
type:"artist",
},
],
images:[
{
height:640,
url:faker.image.abstract(),
width:640,
},
{
height:300,
url:faker.image.abstract(),
width:300,
},
{
height:64,
url:faker.image.abstract(),
width:64,
},
],
name:track,
release_date:`${faker.date.past()}`.substring(0, 10),
type:"album",
},
artists:[
{
name:artist,
type:"artist",
},
],
name:track,
preview_url:faker.internet.url(),
type:"track",
},
],
},
})
}
else if (/me.top.artists/.test(url) && (options?.headers?.Authorization === "Bearer MOCKED_TOKEN_ACCESS")) {
console.debug(`metrics/compute/mocks > mocking spotify api result > ${url}`)
const genre = faker.random.words()
const track = faker.random.words(5)
return ({
status:200,
data:{
items:[
{
genres: [genre],
images:[
{
height:640,
url:faker.image.abstract(),
width:640,
},
{
height:300,
url:faker.image.abstract(),
width:300,
},
{
height:64,
url:faker.image.abstract(),
width:64,
},
],
name:track,
type:"artist",
},
],
},
})
}
}
}