Deezer Radio: Track id not in radio - javascript

How to achieve that all tracks in Deezer Radio API remain unchanged and therefore playable?
Explanation:
I have a Deezer App (HTML+JavaScript, no external libraries) on a Set-Top-Box.
App grabs list of radio trakcs from above mentioned API. It then plays the tracks, fetching the streaming URL for each track from streaming API.
Sometimes the list of radio tracks remains unchanged for many API calls and sometimes the list changes with every call. Why is this so? When a radio track is no longer in radio's list, streaming API returns an error:
{
error: {
type: "DataException",
message: "Track id not in radio",
code: 800
}
}
For example, I get a list of 40 tracks for a particular radio, streaming API normally returns full streaming URLs but every 5th or so track fails to play (a.k.a. Deezer API throws above error) it is not because of erroneus API call but because that particular track is not in the original list of 40 tracks anymore... or this is my own assumption at least.
Therefore I am searching for a way to have a fixed list of 40 tracks that would not change until I play all 40 of them and then get the new list. Is that possible or am I missing something?
Thank you!

There is two ways to achieve this with the JavaScript SDK.
1) You can directly play the radio with DZ.player.playRadio(radio_id)
2) If your really want a fixed list, you can fetch the track list on http://api.deezer.com/radio/radio_id/tracks then play all the tracks with DZ.player.playTracks(tracks)
Example:
DZ.api('/radio/30771/tracks', function(result) {
var tracks = result.data.map(function(elem) {
return elem.id;
});
DZ.player.playTracks(tracks);
});
EDIT: After discussion in the comment, the solution is just do play directly the track without mentioning the radio_id in the streaming url.

Related

How can I play a track from a specific minute and second using Web Playback SDK?

Anybody knows how can I play a track from a specific minute and second using Web Playback SDK?
Example: spotify:track:20zCnBjK6aIgvvy66qZ7RV from 00:44.
Is there anyway to add this info to the Spotify URI?
This is the code,
play({
spotify_uri: 'spotify:track:20zCnBjK6aIgvvy66qZ7RV',
playerInstance: player,
});
Thanks!!!
You only need to add #0:44 at the end of your uri. Info obtained from https://community.spotify.com/t5/Desktop-Windows/Playlist-with-quot-start-at-specific-time-quot-function/td-p/1547529
play({
spotify_uri: 'spotify:track:20zCnBjK6aIgvvy66qZ7RV#0:44',
playerInstance: player,
});
If this doesn't work try:
play({
spotify_uri: 'spotify:track:20zCnBjK6aIgvvy66qZ7RV',
playerInstance: player,
position_ms: 44000
});
Based on https://developer.spotify.com/documentation/web-api/reference/player/start-a-users-playback/

How to get video url with youtube api(v3)

I'm working in node on a server and I'm trying to use the YouTube Api to get a video url. The particular url isn't important, this is more of just an exercise. As far as I can tell with the docs, the best way to find a particular video is if it is associated with a channel or user. IE,
query the api with a username(GoogleDevelopers for example)
get it's channel id
query again to get that channels playlists
search a particular playlist to get a playlist item
given a playlistid, search with that to get items(each should represent a video)
item ids have a videoId field, search with that
get video info, but no url?
However, when I get to that point I feel like there should be a url to that video. The though process would be to send this url back to a front end to allow it to use some library to render the video.
QUESTION: Is there a better way to do this? If not, where am I missing the video URL,
In your return you should get a videoId:
"id":
{
"kind": "youtube#video",
"videoId": "BsLvIF5c7NU"
}
edit: the return is actually just id actually:
"id": "BsLvIF5c7NU"
All you need to do is just append that to the standard url no?:
var url = `https://www.youtube.com/watch?v=${result.id.videoId}`;
Does that make sense?
edit: You could also use part=contentDetails in which case the id is under:
result.items.id
Depending on what you use in the part param will change up the layout of what's returned.
Hope that helps you, dude.

403 Forbidden error when trying to add song to another collaborative playlist with Spotify Web Api

Here is the code I am using to add songs with a button I made. The button works fine, as I am able to add songs to my own playlists. However when trying to add songs to someone else's collaborative playlist, I get a 403 forbidden error.
I have followed the playlists to which I am trying to add songs .I have been able to add songs to that playlist with the desktop app however it is not working on my web page. I don't know if its an error in the code or if the API doesn't allow for collaborative playlists to have songs added to them. My scopes for this project are playlist-read-private,playlist-modify-private,playlist-read-collaborative user-library-modify,user-read-private user-read-email. So I don't think they are an issue either.
document.getElementById('button1').addEventListener('click', function() {
var myid=localStorage.getItem('SpotId')
var playid=localStorage.getItem('URI')
var trackuris = document.getElementById("selections").value;
console.log(trackuris)
var uris=[trackuris]; //create an array with the trackuri stored within
//adding track to playlist using myid, playid, and uris to fill function
spotifyApi.addTracksToPlaylist(myid,playid,uris).then(function(data) {
console.log('Added', data); //logging data returend from spotify to console
document.getElementById('list').src = document.getElementById('list').src;
var select = document.getElementById("selections");
$('#selections').empty(); //deletes previos entries upon adding song to playlist
});
});
This is a limitation of the API. Only playlist owners are able to modify collaborative playlists through the API.

Soundcloud API: Can I specify my request?

I want to get a list of all tracks - resp. the IDs of those tracks - from a certain user. So I'm sending following request to the API (JavaSript SDK):
callPath = "/users/3817541/tracks";
SC.get(callPath,function(obj)
{
console.log(obj);
});
What I get back is an Array of Objects, each of them stuffed with all the track's detail out of which i can extract the IDs - but the transmission of all the unnecessary data slows down my application (I'm actually running this request for multiple users).
Is there any way to tell the API to return just a specific property (ID) of every object instead of the whole cake?

Chrome extension - Background page and unread items

I'm making my first chrome extension and i'm stuck just before the end.
I'm getting a response from a server in json, outputing the html, cache it in localstorage check if there's cache if not getting again from server and then displaying.
Now. In the background.js I need to check every 30 mins if there're updates in the json file on the server... if any display a Badge, once clicked remove badge till next time. but I don't know what to do. Because if I make a setInterval it hits the server and always display a badge even if there's nothing new. Can you guy help me build the js, please?
<script>
setInterval(function(){
chrome.browserAction.setBadgeText({text:chrome.browserAction.setBadgeText({text: "!!!"});});
}, 1800000);
</script>
I've also tried this way, but nothing happens.
function getUnreadItems(callback) {
$.ajax(..., function(data) {
process(data);
callback(data);
});
}
function updateBadge() {
getUnreadItems(function(data) {
chrome.browserAction.setBadgeText({text:data.unreadItems});
});
}
var pollInterval = 1*60*60; // 60 min
var timerId;
function startRequest() {
updateBadge();
timerId = window.setTimeout(startRequest, pollInterval);
}
function stopRequest() {
window.clearTimeout(timerId);
}
background.js
onload='startRequest()'
It looks like you never reset the unread items to "read" on the server, so every time you will ping the server, it will reply with the same number and will thus display that number again.
So you can do a couple of things:
when you click your button and reset the badge to 0, you can send a request to the server to mark all the items as read. Which request will of course depend on your server and what it accepts. That way, the unread count on the server will always be up to date and your extension can be very "stupid": whatever is returned by the server is the current number of unread items.
if you can't do that, you'll have to save some information locally to your extension and figure out the unread count yourself. What I mean by that is that instead of just requesting the unread count you'll need to get information about the specific items like a unique ID. Then every time you poll the server for the list of items, you add the IDs to a list saved in localStorage for example (or chrome.storage.sync) with a viewed tag set to false if that ID is not known yet. The background script will then go through that list and count the number of items that have a viewed tag set to false and use that as an unread count. Whenever you open the popup, you go through your whole list and set the viewed tag to true for all your items.
I've done something similar for an extension to get your Hulu playlist. I did the first option when I delete a video from your playlist, so that it's removed locally and on the server as well. And I did the second option because I wanted to show a count for new videos, but Hulu doesn't keep track of that. (it knows played and unplayed, but not "you've been notified that this new video is available" which I wanted.
See in particular, this section:
// Testing that it's the first time I'm seeing this show
if (show_ids.indexOf(new_show.id) == -1) {
new_shows_number++;
new_show.seen = "no";
} else {
new_show.seen = "yes";
}
Here show_ids is the list of IDs I've already saved and marked as viewed locally. If new_show.id is not in this list, that means it's an unviewed item.

Categories