Put back sort by oldest logic since YouTube added it back
Previous commit replaced it with shorts-filtering, use sort code number 4 for that instead. Sort by oldest is still broken pending reverse engineering of new ctoken format, however.
This commit is contained in:
parent
b45e3476c8
commit
4be01d3964
@ -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):
|
def get_channel_page_general_url(base_url, tab, request, channel_id=None):
|
||||||
|
|
||||||
page_number = int(request.args.get('page', 1))
|
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')
|
sort = request.args.get('sort', '3')
|
||||||
view = request.args.get('view', '1')
|
view = request.args.get('view', '1')
|
||||||
query = request.args.get('query', '')
|
query = request.args.get('query', '')
|
||||||
ctoken = request.args.get('ctoken', '')
|
ctoken = request.args.get('ctoken', '')
|
||||||
include_shorts = (sort != '2')
|
include_shorts = (sort != '4')
|
||||||
default_params = (page_number == 1 and sort in ('2', '3') and view == '1')
|
default_params = (page_number == 1 and sort in ('3', '4') and view == '1')
|
||||||
continuation = bool(ctoken) # whether or not we're using a continuation
|
continuation = bool(ctoken) # whether or not we're using a continuation
|
||||||
page_size = 30
|
page_size = 30
|
||||||
|
try_channel_api = True
|
||||||
|
polymer_json = None
|
||||||
|
|
||||||
# Use the special UU playlist which contains all the channel's uploads
|
# Use the special UU playlist which contains all the channel's uploads
|
||||||
playlist_method_failed = False
|
if tab == 'videos' and sort in ('3', '4'):
|
||||||
if tab == 'videos':
|
|
||||||
if not channel_id:
|
if not channel_id:
|
||||||
channel_id = get_channel_id(base_url)
|
channel_id = get_channel_id(base_url)
|
||||||
if page_number == 1 and include_shorts:
|
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_json = tasks[0].value
|
||||||
pl_info = yt_data_extract.extract_playlist_info(pl_json)
|
pl_info = yt_data_extract.extract_playlist_info(pl_json)
|
||||||
number_of_videos = tasks[2].value
|
number_of_videos = tasks[2].value
|
||||||
print(number_of_videos)
|
|
||||||
info = pl_info
|
info = pl_info
|
||||||
info['channel_id'] = channel_id
|
info['channel_id'] = channel_id
|
||||||
info['current_tab'] = 'videos'
|
info['current_tab'] = 'videos'
|
||||||
if info['items']:
|
if info['items']: # Success
|
||||||
page_size = 100
|
page_size = 100
|
||||||
else:
|
try_channel_api = False
|
||||||
playlist_method_failed = True # Try the first-page method next
|
else: # Try the first-page method next
|
||||||
|
try_channel_api = True
|
||||||
|
|
||||||
# Use the regular channel API
|
# 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:
|
if channel_id:
|
||||||
num_videos_call = (get_number_of_videos_channel, channel_id)
|
num_videos_call = (get_number_of_videos_channel, channel_id)
|
||||||
else:
|
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
|
# Use ctoken method, which YouTube changes all the time
|
||||||
if channel_id and not default_params:
|
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)
|
tab, view, ctoken)
|
||||||
# Use the first-page method, which won't break
|
# Use the first-page method, which won't break
|
||||||
else:
|
else:
|
||||||
@ -474,7 +484,7 @@ def get_channel_page_general_url(base_url, tab, request, channel_id=None):
|
|||||||
else:
|
else:
|
||||||
flask.abort(404, 'Unknown channel tab: ' + tab)
|
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(
|
info = yt_data_extract.extract_channel_info(
|
||||||
json.loads(polymer_json), tab, continuation=continuation
|
json.loads(polymer_json), tab, continuation=continuation
|
||||||
)
|
)
|
||||||
|
@ -74,7 +74,7 @@
|
|||||||
<!-- new-->
|
<!-- new-->
|
||||||
<div id="links-metadata">
|
<div id="links-metadata">
|
||||||
{% if current_tab in ('videos', 'shorts', 'streams') %}
|
{% 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>
|
<div id="number-of-results">{{ number_of_videos }} videos</div>
|
||||||
{% elif current_tab == 'playlists' %}
|
{% elif current_tab == 'playlists' %}
|
||||||
{% set sorts = [('2', 'oldest'), ('3', 'newest'), ('4', 'last video added')] %}
|
{% set sorts = [('2', 'oldest'), ('3', 'newest'), ('4', 'last video added')] %}
|
||||||
@ -112,7 +112,7 @@
|
|||||||
<footer class="pagination-container">
|
<footer class="pagination-container">
|
||||||
{% if current_tab in ('videos', 'shorts', 'streams') %}
|
{% if current_tab in ('videos', 'shorts', 'streams') %}
|
||||||
<nav class="pagination-list">
|
<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>
|
</nav>
|
||||||
{% elif current_tab == 'playlists' or current_tab == 'search' %}
|
{% elif current_tab == 'playlists' or current_tab == 'search' %}
|
||||||
<nav class="next-previous-button-row">
|
<nav class="next-previous-button-row">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user