aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--youtube/channel.py32
-rw-r--r--youtube/templates/channel.html4
2 files changed, 23 insertions, 13 deletions
diff --git a/youtube/channel.py b/youtube/channel.py
index fe72e64..aaf4f79 100644
--- a/youtube/channel.py
+++ b/youtube/channel.py
@@ -378,18 +378,23 @@ playlist_sort_codes = {'2': "da", '3': "dd", '4': "lad"}
def get_channel_page_general_url(base_url, tab, request, channel_id=None):
page_number = int(request.args.get('page', 1))
+ # sort 1: views
+ # sort 2: oldest
+ # sort 3: newest
+ # sort 4: newest - no shorts (Just a kludge on our end, not internal to yt)
sort = request.args.get('sort', '3')
view = request.args.get('view', '1')
query = request.args.get('query', '')
ctoken = request.args.get('ctoken', '')
- include_shorts = (sort != '2')
- default_params = (page_number == 1 and sort in ('2', '3') and view == '1')
+ include_shorts = (sort != '4')
+ default_params = (page_number == 1 and sort in ('3', '4') and view == '1')
continuation = bool(ctoken) # whether or not we're using a continuation
page_size = 30
+ try_channel_api = True
+ polymer_json = None
# Use the special UU playlist which contains all the channel's uploads
- playlist_method_failed = False
- if tab == 'videos':
+ if tab == 'videos' and sort in ('3', '4'):
if not channel_id:
channel_id = get_channel_id(base_url)
if page_number == 1 and include_shorts:
@@ -424,17 +429,18 @@ def get_channel_page_general_url(base_url, tab, request, channel_id=None):
pl_json = tasks[0].value
pl_info = yt_data_extract.extract_playlist_info(pl_json)
number_of_videos = tasks[2].value
- print(number_of_videos)
+
info = pl_info
info['channel_id'] = channel_id
info['current_tab'] = 'videos'
- if info['items']:
+ if info['items']: # Success
page_size = 100
- else:
- playlist_method_failed = True # Try the first-page method next
+ try_channel_api = False
+ else: # Try the first-page method next
+ try_channel_api = True
# Use the regular channel API
- if tab in ('shorts','streams') or tab=='videos' and playlist_method_failed:
+ if tab in ('shorts', 'streams') or (tab=='videos' and try_channel_api):
if channel_id:
num_videos_call = (get_number_of_videos_channel, channel_id)
else:
@@ -442,7 +448,11 @@ def get_channel_page_general_url(base_url, tab, request, channel_id=None):
# Use ctoken method, which YouTube changes all the time
if channel_id and not default_params:
- page_call = (get_channel_tab, channel_id, page_number, sort,
+ if sort == 4:
+ _sort = 3
+ else:
+ _sort = sort
+ page_call = (get_channel_tab, channel_id, page_number, _sort,
tab, view, ctoken)
# Use the first-page method, which won't break
else:
@@ -474,7 +484,7 @@ def get_channel_page_general_url(base_url, tab, request, channel_id=None):
else:
flask.abort(404, 'Unknown channel tab: ' + tab)
- if tab != 'videos' or playlist_method_failed:
+ if polymer_json is not None:
info = yt_data_extract.extract_channel_info(
json.loads(polymer_json), tab, continuation=continuation
)
diff --git a/youtube/templates/channel.html b/youtube/templates/channel.html
index 5fff9de..8d2249c 100644
--- a/youtube/templates/channel.html
+++ b/youtube/templates/channel.html
@@ -74,7 +74,7 @@
<!-- new-->
<div id="links-metadata">
{% if current_tab in ('videos', 'shorts', 'streams') %}
- {% set sorts = [('1', 'views'), ('2', 'newest - no shorts'), ('3', 'newest')] %}
+ {% set sorts = [('1', 'views'), ('2', 'oldest'), ('3', 'newest'), ('4', 'newest - no shorts'),] %}
<div id="number-of-results">{{ number_of_videos }} videos</div>
{% elif current_tab == 'playlists' %}
{% set sorts = [('2', 'oldest'), ('3', 'newest'), ('4', 'last video added')] %}
@@ -112,7 +112,7 @@
<footer class="pagination-container">
{% if current_tab in ('videos', 'shorts', 'streams') %}
<nav class="pagination-list">
- {{ common_elements.page_buttons(number_of_pages, channel_url + '/' + current_tab, parameters_dictionary, include_ends=(current_sort.__str__() in '23')) }}
+ {{ common_elements.page_buttons(number_of_pages, channel_url + '/' + current_tab, parameters_dictionary, include_ends=(current_sort.__str__() in '34')) }}
</nav>
{% elif current_tab == 'playlists' or current_tab == 'search' %}
<nav class="next-previous-button-row">