gmusic-meta-ui.js
v1.120.2018
Published
Browser-side JS library for controlling Google Music through UI manipulation
Downloads
2
Readme
gmusic-meta-ui.js
Browser-side JS library for controlling Google Music through UI manipulation.
gmusic-meta-ui.js
is not created by, affiliated with, or supported by Google Inc.
Getting Started
It's important to note the gmusic-meta-ui.js
depends on gmusic-meta.js
in order to operate correctly
npm
Install the module with: npm install gmusic-meta.js gmusic-meta-ui.js
Once installed, add it to your HTML and access it via window.GMusic
.
<script>
require('gmusic-meta.js')
require('gmusic-meta-ui.js')
window.gmusic = new window.GMusic(); // Our Google Music API
</script>
Vanilla
If you are not using a package manager, download the latest script at:
https://raw.githubusercontent.com/muellerweiss/gmusic-meta-ui.js/master/dist/gmusic-ui.min.js
Then, add it to your HTML and access it via window.GMusic
.
<script src="gmusic.min.js"></script>
<script src="gmusic-ui.min.js"></script>
<script>
window.gmusic = new window.GMusic(window); // Our Google Music API
</script>
Documentation
gmusic-meta-ui.js
extends the GMusic
constructor, window.GMusic
Data Structures
Album
{
"id": String, // Unique ID for this album
"name": String, // The name of the album
"artist": String, // The name of the artist for the album
"albumArt": String, // URL to the albumArt for this album
}
Artist
{
"id": String, // Unique ID for this artist
"name": String, // The name of the artist
"image": String, // URL to an image of this artist
}
Playlist
{
"id": String, // Unique ID for this playlist
"name": String, // User defined name for this playlist
"tracks": Track[], // An array of Track objects that make up the playlist
}
SearchResults
{
"searchText": String, // The text the user searched for to get these results
"bestMatch": {
"type": String, // The type of result that is best. One of "album", "artist" or "track"
"value": Album | Artist | Track
}
"albums": Album[], // An array of albums that are part of these search results
"artists": Artist[], // An array of artists that are part of these search results
"tracks": Track[], // An array of tracks taht are part of these search results
}
new GMusic(window)
Constructor for a new Google Music API.
- window -
Object
- The global window object
You can read up on the namespaces and methods that gmusic-meta
natively offers over in the gmusic-meta.js README
Below are the namespaces and methods that gmusic-meta-ui
adds to GMusic
Playlists
playlists.getAll()
Retrieves a list of all the playlists in the users GPM library
Returns:
- retVal
Playlist[]
- An array ofPlaylist
objects
playlists.play(playlist)
Navigates to the given playlist and plays it immediately
Returns:
- retVal
Promise
- A promise that resolves when the playlist starts playing. This promise can be rejected so you need to handle any errors with.catch
playlists.playWithTrack(playlist, track)
Navigates to the given playlist and plays it immediately starting at the given track
- playlist
Playlist
- APlaylist
object returned fromgetAll()
- track
Track
- ATrack
object from thetracks
property of the supplied playlist
Returns:
- retVal
Promise
- A promise that resolves when the track starts playing. This promise can be rejected so you need to handle any errors with.catch
Queue
queue.clear()
Clears the current queue
queue.getTracks()
Retrieves a list of all the tracks in the users current queue
Returns:
- retVal
Track[]
- An array ofTrack
objects
queue.playTrack(track)
Attempts to play a given track in the queue. If this track is not in the queue an error will be thrown
- track
Track
ATrack
object returned fromgetTracks()
Returns:
- retVal
Promise
- A promise that resolves when the track starts playing. This promise can be rejected so you need to handle any errors with.catch
Search
search.getCurrentResults()
Retrieves a SearchResults
object representing the current search results. Will
throw an error if the user is not currently searching
Returns:
- retVal
SearchResults
- An object of the structure of aSearchResults
object
search.getSearchText()
Retrieves the current string that the user is searching for or the most recent string the user searched for. Basically whatever is in the search input field at the moment.
Returns:
- retVal
String
- The value of the search input field
search.isSearching()
Determines if the user is currently searching or not
Returns:
- retVal
Boolean
- True if the user is searching, False otherwise
search.performSearch(text)
Immediately triggers a new search for the given text
- text
String
A word of sequence of words to search for
Returns:
- retVal
Promise
- A promise that will resolve with the results of the search you just performed. The promise will be rejected with a timeout error if the search takes too long.
search.playResult(result)
Immediately attempts to play the given result. If we fail to play the given result an error will be thrown.
Hooks
Hooks are bound the same way as the gmusic-meta.js hooks.
###.on('change:playlists') Triggers when the content of any playlist or the list of playlists changes in any way.
gmusic-meta.on('change:playlists', function (playlists) {
})
- playlists
Playlist[]
- A list ofPlaylist
objects
###.on('change:queue') Triggers when the contents of the queue is changes in any way
gmusic-meta.on('change:queue', function (queue) {
})
###.on('change:search-results') Triggers when a new search is performed and the results change
gmusic-meta.on('change:search-results', function (newResults) {
})
- queue
Track[]
- A list ofTrack
objects
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint via npm run lint
and test via npm test
.
Testing
Currently there is no testing framework. We should probably implement the gmusic-meta.js testing library in this repo aswell