+1
-1
| { | ||
| "name": "playmusic", | ||
| "version": "2.1.1", | ||
| "version": "2.2.0", | ||
| "description": "Node JS Google Play Music API. Supports All Access", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
+167
-26
@@ -126,10 +126,14 @@ /* Node-JS Google Play Music API | ||
| var devices = response.settings.uploadDevice.filter(function(d) { | ||
| return d.deviceType === 2; | ||
| return d.deviceType === 2 || d.deviceType === 3; | ||
| }); | ||
| if(devices.length > 0) { | ||
| that._deviceId = devices[0].id.slice(2); | ||
| var id = devices[0].id; | ||
| if (devices[0].deviceType === 2) { | ||
| id = id.slice(2); | ||
| } | ||
| that._deviceId = id; | ||
| if(typeof callback === "function") callback(); | ||
| } else { | ||
| if(typeof callback === "function") callback(new Error("Unable to find a usable device on your account, access from a mobile device and try again")); | ||
| if(typeof callback === "function") callback(); | ||
| } | ||
@@ -274,2 +278,7 @@ }); | ||
| PlayMusic.prototype.getStreamUrl = function (id, callback) { | ||
| if(!this._deviceId) { | ||
| callback(new Error("Unable to find a usable device on your account, access from a mobile device and try again")); | ||
| return; | ||
| } | ||
| var that = this; | ||
@@ -307,2 +316,17 @@ var salt = pmUtil.salt(13); | ||
| /** | ||
| * Opens and returns a stream object | ||
| * | ||
| * @param id string - track id, hyphenated is preferred, but "nid" will work for all access tracks (not uploaded ones) | ||
| * @param callback function(stream) - success callback | ||
| */ | ||
| PlayMusic.prototype.getStream = function(id, callback) { | ||
| this.getStreamUrl(id, function(err, url) { | ||
| if(err) return callback(err); | ||
| https.get(url, function(stream) { | ||
| callback(null, stream); | ||
| }) | ||
| }) | ||
| } | ||
| /** | ||
| * Searches for All Access tracks. | ||
@@ -374,22 +398,19 @@ * | ||
| /** | ||
| * Adds a track to end of a playlist. | ||
| * Updates a playlist's metadata | ||
| * | ||
| * @param songId int - the song id | ||
| * @param playlistId int - the playlist id | ||
| * @param playlistId string - the playlist id | ||
| * @param updates object - data to update the playlist with | ||
| * @param callback function(err, mutationStatus) - success callback | ||
| */ | ||
| PlayMusic.prototype.addTrackToPlayList = function (songId, playlistId, callback) { | ||
| PlayMusic.prototype.updatePlayListMeta = function (playlistId, updates, callback) { | ||
| var that = this; | ||
| var mutations = [ | ||
| { | ||
| "create": { | ||
| "clientId": uuid.v1(), | ||
| "creationTimestamp": "-1", | ||
| "deleted": "false", | ||
| "lastModifiedTimestamp": "0", | ||
| "playlistId": playlistId, | ||
| "source": (songId.indexOf("T") === 0 ? "2" : "1"), | ||
| "trackId": songId | ||
| } | ||
| { | ||
| "update": { | ||
| "id": playlistId, | ||
| "name": updates.name || null, | ||
| "description": updates.description || null, | ||
| "shareState": updates.shareState || null | ||
| } | ||
| } | ||
| ]; | ||
@@ -399,6 +420,42 @@ this.request({ | ||
| contentType: "application/json", | ||
| url: this._baseURL + 'playlistbatch?' + querystring.stringify({alt: "json"}), | ||
| data: JSON.stringify({"mutations": mutations}) | ||
| }, function(err, body) { | ||
| callback(err ? new Error("error updating playlist metadata " + err) : null, body); | ||
| }); | ||
| }; | ||
| /** | ||
| * Adds a track to end of a playlist. | ||
| * | ||
| * @param songId string - the song id. Or an array of song ids | ||
| * @param playlistId int - the playlist id | ||
| * @param callback function(err, mutationStatus) - success callback | ||
| */ | ||
| PlayMusic.prototype.addTrackToPlayList = function (songIds, playlistId, callback) { | ||
| var that = this; | ||
| var songIdsArray = Array.isArray(songIds) ? songIds : [songIds]; | ||
| var mutations = []; | ||
| songIdsArray.forEach(function(songId) { | ||
| mutations.push( | ||
| { | ||
| "create": { | ||
| "clientId": uuid.v1(), | ||
| "creationTimestamp": "-1", | ||
| "deleted": "false", | ||
| "lastModifiedTimestamp": "0", | ||
| "playlistId": playlistId, | ||
| "source": (songId.indexOf("T") === 0 ? "2" : "1"), | ||
| "trackId": songId | ||
| } | ||
| } | ||
| ); | ||
| }); | ||
| this.request({ | ||
| method: "POST", | ||
| contentType: "application/json", | ||
| url: this._baseURL + 'plentriesbatch?' + querystring.stringify({alt: "json"}), | ||
| data: JSON.stringify({"mutations": mutations}) | ||
| }, function(err, body) { | ||
| callback(err ? new Error("error adding a track to playlist: " + err) : null, body); | ||
| callback(err ? new Error("error adding tracks to playlist: " + err) : null, body); | ||
| }); | ||
@@ -434,11 +491,37 @@ }; | ||
| /* Change metadata of a track a library | ||
| * Currently only support changing rating | ||
| * You need to change a song object with a different rating value: | ||
| * 5 = thumb up, 1 = thumb down, 0 = no thumb | ||
| * @param song object - the track dictionnary. You can get from getAllAccessTrack or from getLibrary | ||
| * @param callback function(err, success) - success callback | ||
| */ | ||
| PlayMusic.prototype.changeTrackMetadata = function (song, callback) { | ||
| var that = this; | ||
| var mutations = [ { "update": song } ]; | ||
| this.request({ | ||
| method: "POST", | ||
| contentType: "application/json", | ||
| url: this._baseURL + 'trackbatch?' + querystring.stringify({alt: "json"}), | ||
| data: JSON.stringify({"mutations": mutations}) | ||
| }, function(err, body) { | ||
| callback(err ? new Error("error changing rating track: " + err) : null, body); | ||
| }); | ||
| } | ||
| /** | ||
| * Removes given entry id from playlist entries | ||
| * Removes given entry ids from playlist entries | ||
| * | ||
| * @param entryId int - the entry id. You can get this from getPlayListEntries | ||
| * @param entryId string - the entry id. Or an array of entry ids. You can get this from getPlayListEntries | ||
| * @param callback function(err, mutationStatus) - success callback | ||
| */ | ||
| PlayMusic.prototype.removePlayListEntry = function (entryId, callback) { | ||
| PlayMusic.prototype.removePlayListEntry = function (entryIds, callback) { | ||
| var that = this; | ||
| var mutations = [ { "delete": entryId } ]; | ||
| var entryIdsArray = Array.isArray(entryIds) ? entryIds : [entryIds]; | ||
| var mutations = []; | ||
| entryIdsArray.forEach(function(entryId) { | ||
| mutations.push({ "delete": entryId }); | ||
| }); | ||
@@ -451,3 +534,3 @@ this.request({ | ||
| }, function(err, body) { | ||
| callback(err ? new Error("error removing playlist entry: " + err) : null, body); | ||
| callback(err ? new Error("error removing playlist entries: " + err) : null, body); | ||
| }); | ||
@@ -459,10 +542,29 @@ }; | ||
| * | ||
| * @param opts Object - parameters | ||
| * @param callback function(err, playlistEntries) - success callback | ||
| */ | ||
| PlayMusic.prototype.getPlayListEntries = function (callback) { | ||
| PlayMusic.prototype.getPlayListEntries = function (opts, callback) { | ||
| var that = this; | ||
| // If first parameter is a callback, shift it over to the second param | ||
| if (typeof opts === "function") { | ||
| callback = opts; | ||
| opts = {}; | ||
| } | ||
| // Set options defaults | ||
| opts.limit = opts.limit || 1000; | ||
| // Request body data | ||
| var data = {"max-results": opts.limit}; | ||
| // Add 'start-token' if a continuation token was provided | ||
| if (!!opts.nextPageToken) { | ||
| data["start-token"] = opts.nextPageToken; | ||
| } | ||
| this.request({ | ||
| method: "POST", | ||
| url: this._baseURL + 'plentryfeed' | ||
| }, function(err, body) { | ||
| url: this._baseURL + 'plentryfeed', | ||
| contentType: "application/json", | ||
| data: JSON.stringify(data) | ||
| }, function (err, body) { | ||
| callback(err ? new Error("error getting playlist results: " + err) : null, body); | ||
@@ -472,3 +574,42 @@ }); | ||
| /** | ||
| * Returns tracks on shared playlist. | ||
| * | ||
| * @param opts Object - parameters | ||
| * @param callback function(err, playlistEntries) - success callback | ||
| */ | ||
| PlayMusic.prototype.getSharedPlayListEntries = function (opts, callback) { | ||
| var that = this; | ||
| // If first parameter is a callback, shift it over to the second param | ||
| if (typeof opts === "function") { | ||
| callback = opts; | ||
| opts = {}; | ||
| } | ||
| // Set options defaults | ||
| opts.limit = opts.limit || 1000; | ||
| // Request body data | ||
| var data = {"max-results": opts.limit}; | ||
| // Add 'start-token' if a continuation token was provided | ||
| if (!!opts.nextPageToken) { | ||
| data["start-token"] = opts.nextPageToken; | ||
| } | ||
| data['shareToken'] = opts.shareToken; | ||
| this.request({ | ||
| method: "POST", | ||
| url: this._baseURL + 'plentries/shared', | ||
| contentType: "application/json", | ||
| data: JSON.stringify({ | ||
| 'entries': [data] | ||
| }) | ||
| }, function (err, body) { | ||
| callback(err ? new Error("error getting playlist results: " + err) : null, body); | ||
| }); | ||
| }; | ||
| /** | ||
| * Returns info about an All Access album. Does not work for uploaded songs. | ||
@@ -475,0 +616,0 @@ * |
+12
-12
@@ -24,3 +24,3 @@ Node-JS Google Play Music API | ||
| Initialization | ||
| ``` | ||
| ```js | ||
| var PlayMusic = require('playmusic'); | ||
@@ -36,3 +36,3 @@ var pm = new PlayMusic(); | ||
| ``` | ||
| ```js | ||
| var PlayMusic = require('playmusic'); | ||
@@ -48,3 +48,3 @@ var pm = new PlayMusic(); | ||
| ``` | ||
| ```js | ||
| var PlayMusic = require('playmusic'); | ||
@@ -59,3 +59,3 @@ var pm = new PlayMusic(); | ||
| Retrieve list of all tracks in your library (uploaded tracks _and_ tracks added to library from All Access) | ||
| ``` | ||
| ```js | ||
| pm.getAllTracks(function(err, library) { | ||
@@ -71,3 +71,3 @@ var song = library.data.items.pop(); | ||
| Search for a song | ||
| ``` | ||
| ```js | ||
| pm.search("bastille lost fire", 5, function(err, data) { // max 5 results | ||
@@ -87,3 +87,3 @@ var song = data.entries.sort(function(a, b) { // sort by match score | ||
| Retrieve Playlists | ||
| ``` | ||
| ```js | ||
| // gets all playlists | ||
@@ -101,3 +101,3 @@ pm.getPlayLists(function(err, data) { | ||
| Get favorite songs | ||
| ``` | ||
| ```js | ||
| pm.getFavorites(function(err, data) { | ||
@@ -109,3 +109,3 @@ console.log(data.track); | ||
| Retrieve the Stream URL for a song by track.storeId (All Access songs only!!!) | ||
| ``` | ||
| ```js | ||
| pm.getStreamUrl("Thvfmp2be3c7kbp6ny4arxckz54", console.log); | ||
@@ -115,3 +115,3 @@ ``` | ||
| Retrieve the Stream URL for a song by track.id (uploaded songs only!!!) | ||
| ``` | ||
| ```js | ||
| pm.getStreamUrl("84df1e4e-6b76-3147-9a78-a44becc28dc5", console.log); | ||
@@ -121,3 +121,3 @@ ``` | ||
| Retrieve information about an album or artist (All Access Only!!!) | ||
| ``` | ||
| ```js | ||
| // getArtist - artistId, albumList, topTrackCount, relatedArtistCount[, callback] | ||
@@ -132,3 +132,3 @@ pm.getArtist('Ak6zkmv2zbbsaxl63cgsnx5ttcm', true, 2, 2); | ||
| ``` | ||
| ```js | ||
| pm.getSettings(); | ||
@@ -140,3 +140,3 @@ ``` | ||
| ``` | ||
| ```js | ||
| npm install playmusic | ||
@@ -143,0 +143,0 @@ node |
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
36291
13.24%791
18.95%7
-12.5%6
100%