Skip to content

Commit

Permalink
Improve caching and updating of playlist details #1024
Browse files Browse the repository at this point in the history
- Update playlist details every day
- Cache details of own playlists for later use
  • Loading branch information
MoojMidge committed Dec 13, 2024
1 parent 38a2d88 commit ac3bffc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion resources/lib/youtube_plugin/youtube/client/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ def get_channel_sections(self, channel_id, **kwargs):
**kwargs)

def get_playlists_of_channel(self, channel_id, page_token='', **kwargs):
params = {'part': 'snippet',
params = {'part': 'snippet,status,contentDetails',
'maxResults': str(self.max_results())}
if channel_id == 'mine':
params['mine'] = True
Expand Down
26 changes: 25 additions & 1 deletion resources/lib/youtube_plugin/youtube/helper/resource_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def get_playlists(self, ids, suppress_errors=False, defer_cache=False):
result = {}
else:
data_cache = context.get_data_cache()
result = data_cache.get_items(ids, data_cache.ONE_MONTH)
result = data_cache.get_items(ids, data_cache.ONE_DAY)
to_update = [id_ for id_ in ids
if id_ not in result
or not result[id_]
Expand Down Expand Up @@ -415,6 +415,30 @@ def get_related_playlists(self, channel_id, defer_cache=False):
return None
return item.get('contentDetails', {}).get('relatedPlaylists')

def get_my_playlists(self, channel_id, page_token, defer_cache=False):
context = self._context
client = self._provider.get_client(context)

result = client.get_playlists_of_channel(channel_id, page_token)
if not result:
return None

new_data = {
yt_item['id']: yt_item
for yt_item in result.get('items', [])
if yt_item
}
if new_data:
context.debug_log and context.log_debug(
'ResourceManager.get_my_playlists'
' - Retrieved new data for playlists'
'\n\tPlaylist IDs: {ids}'
.format(ids=list(new_data))
)
self.cache_data(new_data, defer=defer_cache)

return result

def get_videos(self,
ids,
live_details=False,
Expand Down
4 changes: 1 addition & 3 deletions resources/lib/youtube_plugin/youtube/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,7 @@ def on_channel_playlists(provider, context, re_match):
else:
result = False

json_data = provider.get_client(context).get_playlists_of_channel(
channel_id, page_token
)
json_data = resource_manager.get_my_playlists(channel_id, page_token)
if not json_data:
return result

Expand Down

0 comments on commit ac3bffc

Please sign in to comment.