The SGmetadata REST API allows users to make requests for in-stream metadata from any platform that can make HTTPS GET requests. This page is documentation for the SGmetadata JavaScript client that abstracts the SGmetadata REST API.
Additional SGMetadata API documentation can be downloaded here.
<script src="sgmetadata-client.js" type="text/javascript"></script>
<script type="text/javascript">
//This is the UUID for the example scraper.
var scraperUUID = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
//This is your SGmetadata account API key.
var accountApiKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
//Build an API client instance with your specific api key.
//This client abstracts the HTTP endpoints for the SGmetadata api.
var sgmd = SGMetadata({apiKey: accountApiKey});
//Fetch an array of all metadata objects for the metadata scraper.
sgmd.getMetadata(scraperUUID, function(metadataArray) {
//Handle the array of metadata objects from the api response.
yourMetadataDisplayFunction(metadataArray);
});
</script>
<script type="text/javascript">
//This is the UUID for the example Smart Monitor
var monitorUUID = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
//Fetch the most recent smart metadata object for the smart monitor.
sgmd.getSmartMetadata(monitorUUID, function(smartMetadata) {
//Handle the smart metadata object from the api response.
yourMetadataDisplayFunction(smartMetadata);
});
//(Optional) Fetch the 10 most recent smart metadata objects for the smart monitor.
sgmd.getRecentSmartMetadata(monitorUUID, 10, function(smartMetadataArray) {
//Handle the smart metadata array from the api response.
yourMetadataDisplayFunction(smartMetadataArray);
});
//(Optional) Fetch the first page of the smart metadata objects for the smart monitor.
sgmd.getSmartMetadataPage(monitorUUID, 1, 10, function(smartMetadataPage) {
//Handle the array of smart metadata objects from the api response.
yourMetadataDisplayFunction(smartMetadataPage);
});
</script>
This section contains descriptions of all SGMetadata REST API client functions along with live examples of results from each API function. You can view the development console for detailed listings of the API response objects by pressing the f12 key.
The getCurrent function requests the most recent metadata object from the scraper.
The response object has the following properties:
The most recent metadata string from the stream.
Live Example:
The most recent url query string from the stream. This field will be undefined if the stream does not send any StreamUrl metadata.
Live Example:
The date of when the metadata changed. This property is localized to SGmetadata server time (Central Standard Time).
Live Example:
The epoch timestamp (in milliseconds) of when the metadata changed. This property can be used to build a localized display date.
Live Example:
Localized date using example timestamp:
The getMetadata function requests the entire history of metadata objects for the scraper matching the given UUID. The responseArray passed to the callback is an array of metadata objects with the same properties as the single response object returned by SGMetadata.getCurrent().
By default, the responseArray is in chronological order with the most recent (now playing) metadata at index 0, and the previously played song metadata at indices 1 to n where n is the total number of metadata items tracked by the scraper matching the given UUID.
The table below is constructed from data returned by a getMetadata call.
| Index | StreamTitle | StreamUrl | date | timestamp |
|---|
The getCurrentRaw function requests the most recent raw metadata string from the scraper matching the given UUID. The response from this function is an unmodified string of all metadata that was most recently extracted from the stream by the scraper.
Live Example:
The getMetadataRaw function requests the entire history of raw metadata strings for the scraper matching the given UUID. The responseArray passed to the callback is an array of raw metadata strings.
By default, the responseArray is in chronological order with the most recent (now playing) metadata string at index 0, and the previously played song metadata strings at indices 1 to n where n is the total number of metadata items tracked by the scraper matching the given UUID.
The table below is constructed from data returned by a getMetadataRaw call.
| Index | Metadata |
|---|
The getSmartMetadata function requests the most recent smart metadata object from the Smart Monitor matching the given UUID. The response from this function is a smart metadata object with the properties: streamTitle, streamUrl, and data.
The pre-formatted stream title string created from the smart metadata data object.
Live Example:
The pre-formatted stream url string created from the smart metadata data object.
Live Example:
The raw Smart Metadata data object used to generate the above streamTitle and streamUrl strings.
Live Example:
The getSmartMetadataPage function requests a single page of smart metadata objects from the entire history of metadata objects for the Smart Monitor matching the given UUID. The smartMetadataPage passed to the callback contains an array of smart metadata objects with the same properties as the single response object returned by SGMetadata.getSmartMetadata().
By default, the smartMetadataPage data is in chronological order with the least recent (oldest) smart metadata one page 1, and the most recent (newest) smart metadata on the last page indicated by meta.lastPage.
The table below is constructed from data returned by a getSmartMetadataPage call.
| Index | streamTitle | streamUrl | date |
|---|
The getRecentSmartMetadata function requests X number of the most recent smart metadata objects from the Smart Monitor matching the given UUID. The data passed to the callback is array of smart metadata objects with the same properties as the single response object returned by SGMetadata.getSmartMetadata().
By default, the smartMetadataArray is in chronological order with the most recent (now playing) metadata object at index 0.
The table below is constructed from data returned by a getRecentSmartMetadata call.
| Index | streamTitle | streamUrl | date |
|---|