Skip to content

Commit

Permalink
fix: SoundCloud support
Browse files Browse the repository at this point in the history
feature: add playing soundcloud user and track
  • Loading branch information
svrooij authored Jun 19, 2021
2 parents 725d663 + d983762 commit 378802b
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,26 @@ Helpers.GenerateLocalMetadata = function (uri, artUri = '') {
* @return {Object} options {uri: Spotify uri, metadata: metadata}
*/
Helpers.GenerateMetadata = function (uri, title = '', region = '3079') {
let meta = '<DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="##SPOTIFYURI##" ##PARENTID##restricted="true"><dc:title>##RESOURCETITLE##</dc:title><upnp:class>##SPOTIFYTYPE##</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">##REGION##</desc></item></DIDL-Lite>'

// Soundcloud track
const match = uri.match(/x-sonos-http:track:(\d+).mp3\?sid=160&flags=8224&sn=4/)
if (match) {
return {
uri,
metadata: meta.replace('##SPOTIFYURI##', '10032020track%3a' + match[1])
.replace('##RESOURCETITLE##', title || 'Soundcloud Track')
.replace('##SPOTIFYTYPE##', 'object.item.audioItem.musicTrack')
.replace('##PARENTID##', '')
.replace('##REGION##', 'SA_RINCON40967_X_#Svc40967-0-Token')
}
}

const parts = uri.split(':')
if (!((parts.length === 2 && (parts[0] === 'radio' || parts[0] === 'x-sonosapi-stream' || parts[0] === 'x-rincon-cpcontainer')) || (parts.length >= 3 && parts[0] === 'spotify'))) {
debug('Returning string because it isn\'t recognized')
return Helpers.GenerateLocalMetadata(uri)
}
let meta = '<DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="##SPOTIFYURI##" ##PARENTID##restricted="true"><dc:title>##RESOURCETITLE##</dc:title><upnp:class>##SPOTIFYTYPE##</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">##REGION##</desc></item></DIDL-Lite>'

if (parts[0] === 'radio' || parts[0] === 'x-sonosapi-stream') {
const radioTitle = title || 'TuneIn Radio'
Expand Down Expand Up @@ -233,6 +247,16 @@ Helpers.GenerateMetadata = function (uri, title = '', region = '3079') {
.replace('##PARENTID##', '')
.replace(`SA_RINCON${region}_X_#Svc${region}-0-Token`, 'SA_RINCON40967_X_#Svc40967-0-Token')
}
} else if (uri.startsWith('x-rincon-cpcontainer:100f206cuser-tracks')) { // Sound Cloud user
const [id] = uri.replace('x-rincon-cpcontainer:', '').split('?')
return {
uri: uri,
metadata: meta.replace('##SPOTIFYURI##', id)
.replace('##RESOURCETITLE##', title || 'Sound Cloud User')
.replace('##SPOTIFYTYPE##', 'object.container.playlistContainer.sameArtist')
.replace('##PARENTID##', '')
.replace(`SA_RINCON${region}_X_#Svc${region}-0-Token`, 'SA_RINCON40967_X_#Svc40967-0-Token')
}
} else if (uri.startsWith('x-rincon-cpcontainer:1006206cplaylist')) { // Sound Cloud playlists
const [id] = uri.replace('x-rincon-cpcontainer:', '').split('?')
return {
Expand Down

0 comments on commit 378802b

Please sign in to comment.