Detecting iTunes playlist folders on a device - objective-c

Through iTunes, you can create playlist folders that are nested arbitrarily deep. When you copy those playlist folders to your iOS device, iTunes is able to detect that they're folders, and allows you to drill down to the point where you ultimately get songs. Any idea how they do that?? I've been trying to figure this out for days.
When I query for a specific persistentID of a known folder, the only things I can see about it that are different from a playlist that contains songs are:
playlist.mediaTypes = 4359 (this is
Music|Podcast|Audiobook|Movie|VideoiTunes) whereas a normal playlist
will not mix audio types and video types
value for property
MPMediaPlaylistPropertyPlaylistAttributes contains 2
(MPMediaPlaylistAttributeSmart), whereas a normal playlist contains 0
the item count will be equal to the total number of items on the
device
But, that's it! I don't see any way to get at the sub-folders. Or, when interrogating a playlist or subfolder that's contained within a folder, I don't see any way to tie it to the parent.
Apple does it in iTunes, so there must be a way. Are they using some private API?

There are the following undocumented properties that can get you what you are looking for using MPMediaPlaylist's valueForProperty method: #"isFolder", and #"parentPersistentID".
Note, these are not documented and do not appear in any header files, so use of them might be considered use of a 'private API' according to Apple's application submission rules.
I've opened a bug report to Apple asking that those be made available in header files, and also asking to clarify whether they are considered to be part of a private API.

Related

Sonos Api: Is there a way to understand which Sonos favorite is playing?

I want to understand which favorite playlist is currently playing on my Sonos speaker.
I've tried the following options:
There's no favorite ID in playbackMetadata and in playbackStatus. So, matching with favorite ID doesn't work
There's containerId in playbackMetadata, which sort of gives information about provider-specific playlist identifiers. Yet, there's no same identifiers in getFavorites response. So, matching containerId won't work either.
Tried loadingFavorite (both with and without playOnComplete set), then getting playbackMetadata in order to build a mapping of favorite ID to containerId. No luck either. Even with 2s delay between two calls to give some space for favorite to be loaded, playlistMetadata returns old containerId (or it might be new, only it doesn't get changed for a new favorite).
Is there a straightforward option? Or not that straightforward, but working?
It is not possible, at least at the UPnP level. When a Favorite is submitted for playback, nothing is included that would allow tracking it back to its origin.

How to find only original tracks on soundcloud

I am using soundcloud API for a project but the problem is I get remix of the original songs or cover version, its okay if I get remix and cover version but is there any mechanism that the original one comes as first song in the search result ? I tried searching on Google and read the API documentation but found nothing in this context.
The track object in soundcloud's API actually has the track_type property which has possible values of 'original' and 'remix' among other things. Sadly like most valueable metadata the track object has, content providers neglect to fill the field. So unless content providers start putting more effort into filling in the metadata fields the only option you have is giving songs priority based on words in the title or tags.

Search Apple App store by genre with iOS/Obj-c

How would you use Obj-c to search the Apple App store to do the following...
Return the details of the top 100 in the games overall category or a
specific games category
Return the details of a specific games in the games category
Anyone?
Well, as far as I know you have two methods to search the App Store:
Search API;
RSS feed generator.
There are many differences between those but the most relevant for your example is that with the Search API you cannot sort the results as they come sorted by relevance and it requires always a search term. The RSS feed generator already has Top Free, Top Paid and Top Grossing categories for you.
Given this I'm going to start answering your question for the RSS feed generator.
You use the RSS feed generator to generate feeds like this for the top 100 free games in the US store: https://itunes.apple.com/us/rss/topfreeapplications/limit=100/genre=6014/xml;
Take a loot at this link to get games sub genres;
You use NSXMLParser library to parse the RSS which already includes the app details.
You may use the initWithContentsOfUrl: method of NSXMLParser;
A quick how-to for this part can be found here.
You can also use StoreKit to get the details of the apps by their ID or show a modal view controller with a specific app but that will require an extra network request.
For the sake of completeness I'll also cover how you can use the Search API.
Use the Search API to create a URL that describes your search:
A URL like this allow you to search for apps with that matches "angry birds" - https://itunes.apple.com/search?term=angry+birds&media=software.
Process the results using NSJSONSerialization library. That already includes the app details.
Take a loot at this tutorial on how to use the NSJSONSerialization library.
In the end, as #Numan said, this two methods accomplish different things. You said you wanted to have the top 100 games from a specific category and also said you needed to search for a specific game.
You can use my descriptions to create one class that interacts with the App Store in these two ways and return an object defined by you that describes an app (or an array of objects).
You can access this info by RSS, look here http://www.apple.com/rss/
Also you can generate RSS feed http://itunes.apple.com/rss/generator/

Find related audios via Keywords

I'm starting to implement an iphone application, that contains audio lessons.
my application is connect to calendar and map, so it takes from the user (places, appointment or meetings) that he wrote in Calendar or checked-in in map.
Then, I will display related lessons to him.
My question is: Is there any algorithm that can be user to find related lesson.
note that each lesson contains keywords and I want to match them with user input.
Thank you and I appreciate any kind of information that will help me :)
i'd just create a separate database which contained an array of keywords and somehow specified its associated audio file resource. IOW, NSArray and NSString should make this pretty quick to implement yourself.

How unique is MPMediaItemPropertyPersistentID?

How unique is MPMediaItemPropertyPersistentID? Will it even work when synching the list of IDs to another device connected to the same iTunes Account?
I want to implement a iCloud synchronized playlist solution which stores the IDs as a list and I need to know if this will be possible.
As per the documentation (emphasis mine)...
The value of the MPMediaItemPropertyPersistentID identifier persists
across application launches and across syncs that do not change the
sync status of the media item. The value is not guaranteed to
persist across a sync/unsync/sync cycle.
As such, given that it won't even persist on this basis I'd be surprised if it persisted across devices in a sufficiently robust manner, if at all.
In my understanding this is not possible. I think this ID is persistent only for each device. It is no unique identifier for a specific song in the iTunes Store. It is only a ID for your own synced songs.
As you read the documentation, you'll see how fragile this ID could be.
"The value is not guaranteed to persist across a sync/unsync/sync cycle."
So if you sync your song database with iTunes and maybe delete a song from your iOS device and the sync again and put it back to your device, you may not get the same ID again for this song. And for sure not across other devices.
So I think, what you're trying to do will not work, until you get a worldwide identical Identifier for each song of the iTunes catalogue or your own iTunes catalogue on the Mac (where the Mac has to handle the IDs).
The other answers are a little big vague, so here is an answer from my own experiences and tests:
1) You can't use MPMediaItemPropertyPersistentID to get an ID that is equal between devices.
2) The MPMediaItemPropertyPersistentID will change when the device is synced with another iTunes library or all music is removed from the device and then synced again.
The ID get's created and stored by iTunes when the song is synced on the device. If it's unsynced, the ID get's deleted.
In case somebody else lands here, like me, using a Google search:
I confirmed what middaparka said above after an iOS upgrade of my device, when my music app tried to use persistentIDs from before the upgrade. The IDs had changed, and I ended up (unwittingly) listening to many songs from my library that I don't normally listen to...
So I took middaparka's advice and constructed a persistentKey by exclusive-oring the hashes from title, artistName, albumTitle and duration. Building the persistentKey during Core Database initialization will be save time later, by avoiding multiple string comparisons when fetching items in "normal operating code."
The persistentKey strategy worked properly for songs. However, when I made a hash for albums from title, artist and releaseYear, I ended up with one collision.
I had two self-titled albums by different artists released in 1976. When the hashes for the album title and the artist were exclusive-ored, they cancelled each other out. I ended up using the hash for the duration instead of the artist, and that worked.
I may end up refining the algorithm for generating the persistentKeys later...