Skip to content

Commit

Permalink
Improve handling of playlists feeds in My Subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
MoojMidge committed Jan 23, 2025
1 parent 3b97bc0 commit 80b1afb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
47 changes: 32 additions & 15 deletions resources/lib/youtube_plugin/youtube/client/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -1757,9 +1757,13 @@ def _parse_feeds(feeds,
_message=context.localize('feeds'),
)

dict_get = {}.get
find = ET.Element.find
findtext = ET.Element.findtext

all_items = {}
new_cache = {}
for channel_id, feed in feeds.items():
for item_id, feed in feeds.items():
channel_name = feed.get('channel_name')
cached_items = feed.get('cached_items')
refresh_feed = feed.get('refresh')
Expand All @@ -1770,31 +1774,44 @@ def _parse_feeds(feeds,
content = to_unicode(content.content).replace('\n', '')

root = ET.fromstring(content if utf8 else to_str(content))
channel_title = root.findtext('atom:title', '', _ns)
channel_title = findtext(root, 'atom:title', '', _ns)
channel_id = findtext(root, 'yt:channelId', '', _ns)
playlist_id = findtext(root, 'yt:playlistId', '', _ns)
channel_name = channel_title.lower().replace(',', '')
dict_get = {}.get

feed_items = [{
'kind': 'youtube#video',
'id': item.findtext('yt:videoId', '', _ns),
'kind': ('youtube#video'
if channel_id else
'youtube#playlistitem'),
'id': (findtext(item, 'yt:videoId', '', _ns)
if channel_id else
None),
'snippet': {
'channelId': channel_id,
'videoOwnerChannelId': channel_id,
'playlistId': playlist_id,
'channelTitle': channel_title,
'title': item.findtext('atom:title', '', _ns),
'description': item.findtext(
'resourceId': {
'videoId': findtext(item, 'yt:videoId', '', _ns)
} if playlist_id else None,
'title': findtext(item, 'atom:title', '', _ns),
'description': findtext(
item,
'media:group/media:description',
'',
_ns,
),
'publishedAt': dt.strptime(
item.findtext('atom:published', '', _ns)
findtext(item, 'atom:published', '', _ns)
),
},
'statistics': {
'likeCount': getattr(item.find(
'likeCount': getattr(find(
item,
'media:group/media:community/media:starRating',
_ns,
), 'get', dict_get)('count', 0),
'viewCount': getattr(item.find(
'viewCount': getattr(find(
item,
'media:group/media:community/media:statistics',
_ns,
), 'get', dict_get)('views', 0),
Expand All @@ -1819,7 +1836,7 @@ def _parse_feeds(feeds,
feed_items = cached_items

if refresh_feed:
new_cache[channel_id] = {
new_cache[item_id] = {
'channel_name': channel_name,
'cached_items': feed_items,
}
Expand All @@ -1830,11 +1847,11 @@ def _parse_feeds(feeds,
filtered = channel_name and channel_name in filters['names']
if filters['blacklist']:
if not filtered:
all_items[channel_id] = feed_items
all_items[item_id] = feed_items
elif filtered:
all_items[channel_id] = feed_items
all_items[item_id] = feed_items
else:
all_items[channel_id] = feed_items
all_items[item_id] = feed_items

if progress_dialog:
progress_dialog.update(position=len(all_items))
Expand Down
3 changes: 2 additions & 1 deletion resources/lib/youtube_plugin/youtube/helper/v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ def _process_list_response(provider,
fanart=fanart,
plot=description,
video_id=item_id,
channel_id=snippet.get('videoOwnerChannelId'),
channel_id=(snippet.get('videoOwnerChannelId')
or snippet.get('channelId')),
playlist_id=snippet.get('playlistId'),
playlist_item_id=playlist_item_id)

Expand Down

0 comments on commit 80b1afb

Please sign in to comment.