Skip to content

Commit

Permalink
fix: untraced error
Browse files Browse the repository at this point in the history
  • Loading branch information
LynMoe committed Apr 18, 2021
1 parent 14bd643 commit 9246b1c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 41 deletions.
51 changes: 22 additions & 29 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ if (!fs.existsSync(path.resolve(__root, '.azusa/'))) {
trackIds.unshift(parseInt(id, 10))
}
return api.editPlaylist('add', playlistId, id)
}))
})).catch(console.trace)
await Promise.all([...(new Set(idDiff.removed))].map(id => {
general.removeValueFromArray(trackIds, id)
return api.editPlaylist('del', playlistId, id)
}))
})).catch(console.trace)
}
}

Expand All @@ -134,6 +134,7 @@ if (!fs.existsSync(path.resolve(__root, '.azusa/'))) {
}

// Generate for album(专辑)
logger.info('Requesting user\'s albums')
const list = new Set()
if (config('downloadSubAlbum', false)) {
const albumList = await api.getUserAlbum()
Expand All @@ -150,15 +151,8 @@ if (!fs.existsSync(path.resolve(__root, '.azusa/'))) {
const albumInfo = await api.getAlbumInfo(albumId)
const trackIds = []

let publishTime = false

for (const track of albumInfo.songs) {
if (publishTime === false) {
const trackInfo = await api.getTrackInfo(track.id)
publishTime = trackInfo.publishTime
}

trackList[track.id] = metadata.generateTrackMetadata(track, publishTime)
trackList[track.id] = {}
trackIds.push(parseInt(track.id, 10))
}

Expand All @@ -170,6 +164,7 @@ if (!fs.existsSync(path.resolve(__root, '.azusa/'))) {

{
// Generate for artist top songs(歌手热门)
logger.info('Requesting user\'s atrists\' songs')
const list = new Set()
const nameMap = {}
if (config('downloadSubAlbum', false)) {
Expand All @@ -190,15 +185,8 @@ if (!fs.existsSync(path.resolve(__root, '.azusa/'))) {
const artistTop = await api.getArtistTop(artistId)
const trackIds = []

let publishTime = false

for (const track of artistTop.songs.splice(0, config('downloadSubArtistTopNum', 30))) {
if (publishTime === false) {
const trackInfo = await api.getTrackInfo(track.id)
publishTime = trackInfo.publishTime
}

trackList[track.id] = metadata.generateTrackMetadata(track, publishTime)
trackList[track.id] = {}
trackIds.push(parseInt(track.id, 10))
}

Expand All @@ -210,6 +198,7 @@ if (!fs.existsSync(path.resolve(__root, '.azusa/'))) {
}

// Generate for history recommendation
logger.info('Requesting user\'s daily recommendation')
if (config('downloadRecommendation', false)) {
const data = await api.getUserRecommendation()

Expand Down Expand Up @@ -312,10 +301,10 @@ if (!fs.existsSync(path.resolve(__root, '.azusa/'))) {
})
} else resolve()
})
})
}).catch(console.trace)

{
logger.debug('Requesting URL of track', trackInfo.title)
logger.debug('Requesting URL of track', trackInfo.title, trackId)
const trackUrl = await api.getTrackUrl(trackId)

if (!trackUrl) {
Expand Down Expand Up @@ -359,9 +348,9 @@ if (!fs.existsSync(path.resolve(__root, '.azusa/'))) {
})
} else resolve()
})
})
}).catch(console.trace)
{
logger.debug('Requesting lyric of track', trackInfo.name)
logger.debug('Requesting lyric of track', trackInfo.name, trackId)
const lyricData = await api.getLyric(trackId)

if (!lyricData.lrc || !lyricData.lrc.lyric) {
Expand All @@ -373,7 +362,7 @@ if (!fs.existsSync(path.resolve(__root, '.azusa/'))) {
if (error) throw error
resolve()
})
})
}).catch(console.trace)
}
}
logger.info(`[Track: ${colors.italic(trackInfo.title)}] ${colors.blue('Processed!')}`)
Expand Down Expand Up @@ -401,7 +390,7 @@ if (!fs.existsSync(path.resolve(__root, '.azusa/'))) {
})
})
})
})
}).catch(console.trace)
})
})
})
Expand Down Expand Up @@ -464,9 +453,11 @@ if (!fs.existsSync(path.resolve(__root, '.azusa/'))) {
if (error) throw error
resolve()
})
} else {
resolve()
}
})
}, randomInt(100, 1000))
}, randomInt(100, 1000)).catch(console.trace)
})
}
})
Expand All @@ -480,7 +471,9 @@ if (!fs.existsSync(path.resolve(__root, '.azusa/'))) {
await trackCopyQueue.onIdle()

clearInterval(intervalId)
await Promise.all(playlistWriteList.map((fn) => fn ? fn() : Promise.resolve()))

rimraf(tmpBasePath, () => {})
})()
await Promise.all(playlistWriteList.map((fn) => fn ? fn() : Promise.resolve())).then(() => {
setTimeout(() => {
rimraf(tmpBasePath, () => {})
}, 1200)
})
})().catch(console.trace)
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kawaiilab/azusa",
"version": "1.1.2",
"version": "1.1.3",
"description": "For and by music lover",
"main": "app.js",
"bin": {
Expand Down
20 changes: 10 additions & 10 deletions source/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ module.exports = {
uid: this._uid,
cookie: this._cookie
})
result = result.body
logger.debug(result)
result = result.body

return result.playlist
},
Expand All @@ -61,8 +61,8 @@ module.exports = {
limit: 100,
cookie: this._cookie
})
result = result.body
logger.debug(result)
result = result.body

return result.data
},
Expand All @@ -72,8 +72,8 @@ module.exports = {
limit: 100,
cookie: this._cookie
})
result = result.body
logger.debug(result)
result = result.body

return result.data
},
Expand All @@ -83,8 +83,8 @@ module.exports = {
cookie: this._cookie
})

detail = detail.body.data
logger.debug(detail)
detail = detail.body.data

const trackList = []
const content = Array.from(detail.dailySongs)
Expand All @@ -97,8 +97,8 @@ module.exports = {
let result = await NeteaseCloudMusicApi.history_recommend_songs({
cookie: this._cookie
})
result = result.body.data
logger.debug(result)
result = result.body.data

if (result.dates) {
const trackList = {}
Expand Down Expand Up @@ -136,8 +136,8 @@ module.exports = {
id: playlistId,
cookie: this._cookie
})
result = result.body
logger.debug(result)
result = result.body

return result.playlist
},
Expand All @@ -147,8 +147,8 @@ module.exports = {
id: albumId,
cookie: this._cookie
})
result = result.body
logger.debug(result)
result = result.body

return result
},
Expand All @@ -158,8 +158,8 @@ module.exports = {
id: artistId,
cookie: this._cookie
})
result = result.body
logger.debug(result)
result = result.body

return result
},
Expand All @@ -169,8 +169,8 @@ module.exports = {
ids: `${trackId}`,
cookie: this._cookie
})
result = result.body
logger.debug(result)
result = result.body

return result.songs[0]
},
Expand Down Expand Up @@ -204,7 +204,7 @@ module.exports = {
},

async editPlaylist (op, playlistId, trackId) {
let result = await NeteaseCloudMusicApi.playlist_tracks({
const result = await NeteaseCloudMusicApi.playlist_tracks({
cookie: this._cookie,
op: op === 'add' ? 'add' : 'del',
pid: playlistId,
Expand Down

0 comments on commit 9246b1c

Please sign in to comment.