Skip to content

Commit

Permalink
Fix: Handle parsing of invalid album/playlist URL link
Browse files Browse the repository at this point in the history
  • Loading branch information
vishaltelangre committed Jun 21, 2017
1 parent 788194d commit 481b095
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 26 deletions.
37 changes: 23 additions & 14 deletions lib/providers/gaana.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,29 @@ module.exports = class Gaana extends Provider {
.set({listTitle: 'h1'})
.set({ list: [osmosis.find('[data-type="playSong"].parentnode')] })
.data((data) => {
const trackList = data.list.map(JSON.parse).map(track => {
// Example artists: "Anuradha Paudwal###212098###anuradha-paudwal-2,Kumar Sanu###1###kumar-sanu"
const artists = `${track.artist}`.split(",")
.map(artist => artist.split('###')[0]);
return {
title: track.title,
album: track.albumtitle,
image: track.albumartwork,
artist: artists.join(", "),
time: track.duration,
year: track.release_date && (new Date(track.release_date)).getFullYear()
};
});
resolve({listTitle: data.listTitle, trackList});
try {
const trackList = data.list.map(JSON.parse).map(track => {
// Example artists: "Anuradha Paudwal###212098###anuradha-paudwal-2,Kumar Sanu###1###kumar-sanu"
const artists = `${track.artist}`.split(",")
.map(artist => artist.split('###')[0]);
return {
title: track.title,
album: track.albumtitle,
image: track.albumartwork,
artist: artists.join(", "),
time: track.duration,
year: track.release_date && (new Date(track.release_date)).getFullYear()
};
});

if (!trackList.length) {
reject("Couldn't find any tracks on the provided link");
}

resolve({ listTitle: data.listTitle, trackList });
} catch (error) {
reject(`Error while parsing the list of tracks on the provided link`);
}
})
.log(message => { process.env.DEBUG && cli.debug(message); })
.error(err => {
Expand Down
32 changes: 20 additions & 12 deletions lib/providers/saavn.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,27 @@ module.exports = class Saavn extends Provider {
.find('.page-wrap.album-view, .page-wrap.playlist')
.set({ listTitle: 'h1', list: [osmosis.find('.track-list li .song-json')] })
.data((data) => {
const trackList = data.list.map(JSON.parse).map(track => {
return {
title: track.title,
album: track.album,
image: track.image_url,
composer: track.music,
artist: track.singers,
time: track.duration,
year: track.year
};
});
try {
const trackList = data.list.map(JSON.parse).map(track => {
return {
title: track.title,
album: track.album,
image: track.image_url,
composer: track.music,
artist: track.singers,
time: track.duration,
year: track.year
};
});

resolve({listTitle: data.listTitle, trackList});
if (!trackList.length) {
reject("Couldn't find any tracks on the provided link");
}

resolve({listTitle: data.listTitle, trackList});
} catch (error) {
reject(`Error while parsing the list of tracks on the provided link`);
}
})
.log(message => { process.env.DEBUG && cli.debug(message); })
.error(err => {
Expand Down

0 comments on commit 481b095

Please sign in to comment.