chore: additional aliases + guards
This commit is contained in:
parent
7d952e24c8
commit
d10e92ffe4
2 changed files with 10 additions and 8 deletions
|
@ -6,7 +6,11 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"artist": "Tom Waits",
|
"artist": "Tom Waits",
|
||||||
"aliases": ["Tom Waits & Crystal Gayle"]
|
"aliases": ["Tom Waits & Crystal Gayle", "Crystal Gayle"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"artist": "Fen",
|
||||||
|
"aliases": ["Sleepwalker & Fen"]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,19 +28,19 @@ module.exports = async function () {
|
||||||
const APPLE_TOKEN = APPLE_TOKEN_RESPONSE['music-token']
|
const APPLE_TOKEN = APPLE_TOKEN_RESPONSE['music-token']
|
||||||
const asset = new AssetCache('recent_tracks_data')
|
const asset = new AssetCache('recent_tracks_data')
|
||||||
const PAGE_SIZE = 30
|
const PAGE_SIZE = 30
|
||||||
const PAGES = 7
|
const PAGES = 10
|
||||||
const response = {
|
const response = {
|
||||||
artists: {},
|
artists: {},
|
||||||
albums: {},
|
albums: {},
|
||||||
tracks: {},
|
tracks: {},
|
||||||
}
|
}
|
||||||
|
|
||||||
let CURRENT_PAGE = 0
|
let CURRENT_PAGE = 0
|
||||||
let res = []
|
let res = []
|
||||||
|
let hasNextPage = true
|
||||||
|
|
||||||
if (asset.isCacheValid('1h')) return await asset.getCachedValue()
|
if (asset.isCacheValid('1h')) return await asset.getCachedValue()
|
||||||
|
|
||||||
while (CURRENT_PAGE < PAGES) {
|
while (CURRENT_PAGE < PAGES && hasNextPage) {
|
||||||
const URL = `https://api.music.apple.com/v1/me/recent/played/tracks?limit=${PAGE_SIZE}&offset=${
|
const URL = `https://api.music.apple.com/v1/me/recent/played/tracks?limit=${PAGE_SIZE}&offset=${
|
||||||
PAGE_SIZE * CURRENT_PAGE
|
PAGE_SIZE * CURRENT_PAGE
|
||||||
}`
|
}`
|
||||||
|
@ -53,12 +53,12 @@ module.exports = async function () {
|
||||||
})
|
})
|
||||||
.then((data) => data.json())
|
.then((data) => data.json())
|
||||||
.catch()
|
.catch()
|
||||||
res = [...res, ...tracks.data]
|
if (!tracks.next) hasNextPage = false
|
||||||
|
if (tracks.data.length) res = [...res, ...tracks.data]
|
||||||
CURRENT_PAGE++
|
CURRENT_PAGE++
|
||||||
}
|
}
|
||||||
|
|
||||||
res.forEach((track) => {
|
res.forEach((track) => {
|
||||||
// aggregate artists
|
|
||||||
if (!response.artists[track.attributes['artistName']]) {
|
if (!response.artists[track.attributes['artistName']]) {
|
||||||
response.artists[track.attributes['artistName']] = {
|
response.artists[track.attributes['artistName']] = {
|
||||||
artist: track.attributes['artistName'],
|
artist: track.attributes['artistName'],
|
||||||
|
@ -68,7 +68,6 @@ module.exports = async function () {
|
||||||
response.artists[track.attributes['artistName']].plays++
|
response.artists[track.attributes['artistName']].plays++
|
||||||
}
|
}
|
||||||
|
|
||||||
// aggregate albums
|
|
||||||
if (!response.albums[track.attributes['albumName']]) {
|
if (!response.albums[track.attributes['albumName']]) {
|
||||||
response.albums[track.attributes['albumName']] = {
|
response.albums[track.attributes['albumName']] = {
|
||||||
name: track.attributes['albumName'],
|
name: track.attributes['albumName'],
|
||||||
|
@ -80,7 +79,6 @@ module.exports = async function () {
|
||||||
response.albums[track.attributes['albumName']].plays++
|
response.albums[track.attributes['albumName']].plays++
|
||||||
}
|
}
|
||||||
|
|
||||||
// aggregate tracks
|
|
||||||
if (!response.tracks[track.attributes.name]) {
|
if (!response.tracks[track.attributes.name]) {
|
||||||
response.tracks[track.attributes.name] = {
|
response.tracks[track.attributes.name] = {
|
||||||
name: track.attributes.name,
|
name: track.attributes.name,
|
||||||
|
|
Reference in a new issue