podsync icon indicating copy to clipboard operation
podsync copied to clipboard

Add option to sort episodes by playlist addition date

Open bcongdon opened this issue 5 years ago • 5 comments

Currently episodes are sorted by their publish date (i.e. the video upload date).

It would be nice to be able to sort by playlist addition date (which is exposed on PlaylistItem for youtube playlist items).

The use case is: If you add a really old video to a playlist, it gets added really far back in your feed, and many podcast clients won't download "old" episodes by default.

bcongdon avatar Nov 28 '19 18:11 bcongdon

@bcongdon can you clarify which field are you referring to? There is snippet.publishedAt, but I don't see anything related to addition date: https://developers.google.com/youtube/v3/docs/playlistItems

mxpv avatar Nov 28 '19 22:11 mxpv

snippet.publishedAt is the addition date for PlaylistItem (it's described as "The date and time that the item was added to the playlist").

That's in contrast to snippet.publishedAt on the Video resource, which is the actual "publish" date

bcongdon avatar Nov 29 '19 03:11 bcongdon

This seems to be a problem which intersects with the fact that playlist items are fetched in playlist order, not in publish order. For playlists longer than the per-page limit 50 items, you need to set a very long page size (>= the number of playlist items) for PodSync to consider finding the latest items. It also appears to require downloading all the items in order for the cleanup to then kick in afterward if you don’t want to keep them all.

I don’t see a way to avoid this easily with YouTube’s API, as they don’t publish any way to adjust the sorting behaviour in the request, and it also means PodSync is incurring lots of API calls in requesting metadata for all those items even if some of them are to be discarded immediately.

I wonder if an approach would be to add a setting for or make the default behaviour for Playlists to fetch all pages and limit on page_size instead, then we could in fact handle sorting by PlaylistItem’s publishedAt. We could also use the db’s cache of publishedAt and contentDetails.itemCount to reduce ongoing API calls (to just the queryFeed call, instead of always running the subsequent queryItems).

ticky avatar Aug 19 '20 20:08 ticky

How about prefixing the "title" with the index for playlists only? Something like "snippet.position snippet.title" results in

  • 0000 first video
  • 0001 second video

The podcast app would just needs to sort episodes by name. Podcast Addict on android can do this, but that might not be universally supported everywhere.

sdolenc avatar Jun 21 '21 22:06 sdolenc

I tested a version of this locally and it works well for playlists

image

However, it should not be merged as-is. It prefixes numbers to episodes from channels which is not desirable. If this is the sort of direction we want to go then we'd want to conditionalize this to playlists only :)

sdolenc avatar Jun 22 '21 00:06 sdolenc