Skip to content

Commit

Permalink
Add basic checks for valid My Subscription request data
Browse files Browse the repository at this point in the history
- TODO: Rewrite YouTube.get_my_subscriptions with better error and thread handling
  • Loading branch information
MoojMidge committed Jan 15, 2024
1 parent a973128 commit 1f4c5ac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
4 changes: 2 additions & 2 deletions resources/lib/youtube_plugin/youtube/client/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,7 @@ def _perform(_page_token, _offset, _result):

# if new uploads is cached
cache_items_key = 'my-subscriptions-items'
cached = cache.get_item(cache_items_key, cache.ONE_HOUR)
cached = cache.get_item(cache_items_key, cache.ONE_HOUR) or []
if cached:
_result['items'] = cached

Expand Down Expand Up @@ -1398,7 +1398,7 @@ def fetch_xml(_url, _responses):
# sorting by publish date
def _sort_by_date_time(item):
return datetime_parser.since_epoch(
datetime_parser.strptime(item['published'][0:19])
datetime_parser.strptime(item['published'])
)

_result['items'].sort(reverse=True, key=_sort_by_date_time)
Expand Down
23 changes: 8 additions & 15 deletions resources/lib/youtube_plugin/youtube/helper/yt_specials.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def _extract_urls(video_id):
) as progress_dialog:
resource_manager = provider.get_resource_manager(context)

video_data = resource_manager.get_videos((video_id, ))
video_data = resource_manager.get_videos((video_id,))
yt_item = video_data[video_id]
if not yt_item or 'snippet' not in yt_item:
context.get_ui().on_ok(
Expand Down Expand Up @@ -286,32 +286,25 @@ def _process_saved_playlists_tv(provider, context):
offset=context.get_param('offset', 0)
)

if not json_data:
return False
return tv.saved_playlists_to_items(provider, context, json_data)


def _process_new_uploaded_videos_tv(provider, context):
context.set_content(content.VIDEO_CONTENT)

json_data = provider.get_client(context).get_my_subscriptions(
page_token=context.get_param('next_page_token', ''),
offset=context.get_param('offset', 0)
)

return tv.my_subscriptions_to_items(provider, context, json_data)


def _process_new_uploaded_videos_tv_filtered(provider, context):
def _process_new_uploaded_videos_tv(provider, context, filtered=False):
context.set_content(content.VIDEO_CONTENT)

json_data = provider.get_client(context).get_my_subscriptions(
page_token=context.get_param('next_page_token', ''),
offset=context.get_param('offset', 0)
)

if not json_data:
return False
return tv.my_subscriptions_to_items(provider,
context,
json_data,
do_filter=True)
do_filter=filtered)


def process(category, provider, context):
Expand All @@ -333,7 +326,7 @@ def process(category, provider, context):
if category == 'new_uploaded_videos_tv':
return _process_new_uploaded_videos_tv(provider, context)
if category == 'new_uploaded_videos_tv_filtered':
return _process_new_uploaded_videos_tv_filtered(provider, context)
return _process_new_uploaded_videos_tv(provider, context, filtered=True)
if category == 'disliked_videos':
return _process_disliked_videos(provider, context)
if category == 'live':
Expand Down

0 comments on commit 1f4c5ac

Please sign in to comment.