Can I replace songs inside a playlist with a position index - spotify

I would like to know if there is any way to replace songs inside a playlist with a position index, just like the add tracks endpoint.
When I add "position" to my body parameters I get an error telling me to add "range_start" as if I was calling the reorder endpoint.

Looks like the Replace takes the same parameters for this as Reorder endpoint, although the documentation doesn't state this, the Web Console at Reorder or replace a Playlist's Tracks does - I didn't actually know this until I checked that myself, as had assumed only the entire playlist could be replaced

Related

Adding custom logic to declarativeNetRequest

I have logic that used webRequestBlocking, where I'd redirect the request, if the request param matched some dynamically changeable values stored in background script, i.e. if user is placing orders for items 1,2,3 and my background script says, dont allow messages to item 1, then I'd in that case redirect the webrequest, do a check that the requestBody doesnt have item 1 set.
I am trying to do the same in V3, but I can't find a way, given there isnt a way for me to call any of my own custom methods from background script, I thought I can maybe just update rules to match for the requestBody params, but I can't seem to find a way to do that even?
Is there anything that can be done here? Not sure why would they remove support for something so important?

Youtube search using the google API

I am using the google API and I wanted to do a youtube search.
I request a search with https://www.googleapis.com/youtube/v3/search?part=snippet&q=[word that I searched for]&key=my_keyto get the items array. I noticed though that the items array does not return the results in the same order as when you search youtube yourself.
Ex: if I search for the word 'bad' the first result in the items array is the "Young Lex ft AwKarin - BAD ( Official Music Video Clip )" while if I searched like a youtube user its the "Michael Jackson - Bad (Shortened Version)".
Perhaps they are not ordered and I have to order them using a property or something I have missed.
So my question is how can I make the items array return as the first item the first result that would have appeared in the youtube search.
edit: I have tried adding chart=MostPopular leaving to default videoCategoryId, but it still showed the same first result.
Well, it seems that the YouTube acts like that and it is a natural behavior of it. The only possible way that you can do to match the API and the YouTube site itself is by passing the same filter for it. Example is upload date and viewCount.
Here is the example request for viewCount.
https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.search.list?part=snippet&maxResults=10&order=viewCount&q=spider&_h=1&
and this is for the YouTube site
https://www.youtube.com/results?q=spider&sp=CAM%253D
Hope this slight information helps you.

get document by id in modx

Very simply I want to have multiple content regions on a single page. Note this is my first Modx site.
So far I have the home page and created child documents for the sub regions on the home page. All I want is to call them in the template.
For example there is a document with an id of 2, and I want the long title on the home page (id of 1).
Something like :
[[~2*longtitle]]
Unfortunately the above just returns the url to that sub document and not the longtitle of that document itself.
So far I've found no documentation on doing so. Does anyone know how to accomplish this?
You have 2 options, the hard way ~ the route you have chosen ;) and the easy way... which I will outline as well.
For what you are trying to do you are going to want to use either getResources http://rtfm.modx.com/display/ADDON/getResources which will allow you to loop over a collection of resources & extract the fields you need [in this case 'content'] or getresourceField http://rtfm.modx.com/display/ADDON/getResourceField which will allow you to specify a single resource & the field to extract, just call it multiple times in your template.
You might try:
[[getResources? &parents='[[*id]]' &tpl='myTpl' &includeContent='1']]
Should get all the child resources [up to default ~ 10] of the current resource, then you would create a template for get resources to loop over:
<h1>[[+longtitle]]</h1>
<p>[[+content]]</p>
notice the use of + instead of * for the resource fields
OR
the easy way, create template variables for your extra content areas, you can set them up as rich text areas as well. that way all your content for any given page is within the one resource ~ no need for you to create child resources to hold content for your header/footer/sidebar/etc
Either way will work, the TV method may use less overhead though.
you can use fastfield
[[#12.pagetitle]]
or in a call
[[#[[+id]].pagetitle]]
You can also grab all TVs of that resource, like
[[#12.myTv]]
see also: http://rtfm.modx.com/extras/revo/fastfield

In PySpotify, trying to remove a track from a playlist without knowing the position of the track in the playlist

I am trying to remove a track from a playlist and the information I know about the track is the spotify URI, the name of the track and the artist. However, I don't know the position of the track in the playlist.
The function to remove the track is the following:
spotify.Playlists.remove_tracks(tracks)
Parameters: tracks (list of int) – A list of track positions to be removed from the playlist
I haven't found any callbacks or class method that would provide this information except upon adding the track to the playlist, which may have happened in another session.
Has anyone done this successfully and if so, could you point me to how you were able to do it?
Thanks
I haven't used PySpotify myself, but looking at the docs, it says that a Playlist is an iterable sequence of Tracks. I think you should be able to iterate over the tracks and use str(spotify.Link.from_track(track)) to get the link for each track. Then you can easily enough look for the indices that match your track URI.

libspotify API: track index

Is there any way to get the track index in an album? or given a track URI, is it possible to know its index or offset in the album (assume the track belongs to an album) without walking through the whole album?
Thanks.
Yes he is referring to sp_track_index, wich is only accessible through a album browse.
see libspotify documentation for sp_track_index here
What you need to do is something along the lines of:
call sp_albumbrowse_create for the album of sp_track that you have
wait for the callback fired when created/loaded
get sp_track_index from that track. Preferably you put the specific track in userdata to be passed on to the callback to be used with comparison.
Note: getting sp_track_index outside of an browse, will always return 0.
See Browse example here
You have to do an album browse for the target album. Once you've done that, you can get the track's index.

Resources