0

Is there a real unique ID for a Video on a YouTube playlist? YouTube offers a playlistItem.id and tells us that this ID is...

The ID that YouTube uses to uniquely identify the playlist item

What I've found out is that this ID is the ID of the Position of a PlaylistItem within a Playlist. If you delete your one and only video on a playlist and you put another video on your playlist, then this new video will have the same PlaylistItem.id.

Any recommendations how to fake a real unique ID?

ninsky
  • 1,658
  • 19
  • 27
  • Sorry for a sideline question: what would be the use of such a *globally unique playlist item ID*? Video IDs and playlist IDs are globally unique *inside and outside* their respective resource categories. – stvar Dec 13 '20 at 14:22
  • The use case is to track changes of a playlist. It would help if the unique playlistItemId would have been unique at least within the scope of its playlist. – ninsky Dec 13 '20 at 20:46
  • I see. In general it quite tricky to be able to compute the set-theoretic diff of any resource category -- like uploaded videos (which is a playlist by itself), playlists, and so on. That is to be able to tell precisely and computationally efficiently *which elements were removed and which were added*. It's however easier using the APIs to tell when new items *were added*. See for example [this answer](https://stackoverflow.com/a/63565865/8327971) of mine. – stvar Dec 13 '20 at 21:01
  • The set-theoretic diff of a playlist can only be computed if having the complete list stored locally and *upon fetching the entire playlist* from the API. That's not efficient since a playlist can be huge in size. – stvar Dec 13 '20 at 21:07
  • I had to tackle something along the lines of keeping *track of changes in a playlist*, since I myself do monitor constantly certain channels of interest to me. For channels that have thousands or hundreds of thousands of uploads it's not feasible to fetch the entire list locally for to compute the set-theoretic diff properly. – stvar Dec 13 '20 at 21:31
  • My app fetches only the first `N` pages (most of the time `N` is 1 or 2), and computes a partial diff only. That's meaningful because the items of the uploads playlist of any given channel *are (have to be) ordered by `contentDetails.videoPublishedAt`, with the newest being the first* ([see point 2 of this answer of mine](https://stackoverflow.com/a/65004531/8327971)). – stvar Dec 13 '20 at 21:32

1 Answers1

0

I think that the tuple

<playlistId, playlistItemId, videoId>

could be taken as a globally unique playlist item ID. Of course, for t1 := <p1, i1, v1> and t2 := <p2, i2, v2>, by definition t1 == t2 if and only if:

  • p1 == p2, and
  • i1 == i2, and
  • v1 == v2.

Since each component of such a tuple is a string that contains no comma, the tuple itself can simply be represented by the concatenation of these three strings separated by comma.

Encoding the ID tuples as mentioned implies that the componentwise ID tuples equality (as defined above) becomes trivially the string equality.

Decoding such an ID to its components is also trivial. Any modern language has readily available standard functions to do precisely such operation. For example, in Python that function is str.split; in PHP that is explode.

stvar
  • 5,871
  • 2
  • 10
  • 23
  • Yes, a touple seems to be the last resort to solve this problem. I think your touple wouldn't work to keep track of the same video which you add and remove multiple times. But the publishedAt date could be useful as described here https://stackoverflow.com/a/50321595/830006 – ninsky Dec 13 '20 at 20:53
  • Indeed you're right; then the tuple would be ``. The rest of my assertions remain valid, since `publishedAt` can be represented such that to not contain comma (e.g. as seconds since the Epoch, or as ISO-8601, `%Y-%m-%dT%H:%M:%S.%NZ`, etc.) – stvar Dec 13 '20 at 21:14