Channel: use general pbj=1 endpoint to get first page of videos
YouTube disabled the browse_ajax endpoint. Quick fix for first channel page. In general, this will be more robust against api endpoint changes. As YouTube continues to change api endpoints, at least the subscriptions and first page will no longer break. Signed-off-by: Jesús <heckyel@hyperbola.info>
This commit is contained in:
parent
2d9aca4b8b
commit
f7ed8159cd
@ -198,6 +198,13 @@ def post_process_channel_info(info):
|
|||||||
util.add_extra_html_info(item)
|
util.add_extra_html_info(item)
|
||||||
|
|
||||||
|
|
||||||
|
def get_channel_first_page(base_url=None, channel_id=None):
|
||||||
|
if channel_id:
|
||||||
|
base_url = 'https://www.youtube.com/channel/' + channel_id
|
||||||
|
return util.fetch_url(base_url + '/videos?pbj=1&view=0', headers_desktop,
|
||||||
|
debug_name='gen_channel_videos')
|
||||||
|
|
||||||
|
|
||||||
playlist_sort_codes = {'2': "da", '3': "dd", '4': "lad"}
|
playlist_sort_codes = {'2': "da", '3': "dd", '4': "lad"}
|
||||||
|
|
||||||
# youtube.com/[channel_id]/[tab]
|
# youtube.com/[channel_id]/[tab]
|
||||||
@ -214,7 +221,7 @@ def get_channel_page_general_url(base_url, tab, request, channel_id=None):
|
|||||||
query = request.args.get('query', '')
|
query = request.args.get('query', '')
|
||||||
ctoken = request.args.get('ctoken', '')
|
ctoken = request.args.get('ctoken', '')
|
||||||
|
|
||||||
if tab == 'videos' and channel_id:
|
if tab == 'videos' and channel_id and page_number > 1:
|
||||||
tasks = (
|
tasks = (
|
||||||
gevent.spawn(get_number_of_videos_channel, channel_id),
|
gevent.spawn(get_number_of_videos_channel, channel_id),
|
||||||
gevent.spawn(get_channel_tab, channel_id, page_number, sort,
|
gevent.spawn(get_channel_tab, channel_id, page_number, sort,
|
||||||
@ -224,9 +231,13 @@ def get_channel_page_general_url(base_url, tab, request, channel_id=None):
|
|||||||
util.check_gevent_exceptions(*tasks)
|
util.check_gevent_exceptions(*tasks)
|
||||||
number_of_videos, polymer_json = tasks[0].value, tasks[1].value
|
number_of_videos, polymer_json = tasks[0].value, tasks[1].value
|
||||||
elif tab == 'videos':
|
elif tab == 'videos':
|
||||||
|
if channel_id:
|
||||||
|
num_videos_call = (get_number_of_videos_channel, channel_id)
|
||||||
|
else:
|
||||||
|
num_videos_call = (get_number_of_videos_general, base_url)
|
||||||
tasks = (
|
tasks = (
|
||||||
gevent.spawn(get_number_of_videos_general, base_url),
|
gevent.spawn(*num_videos_call),
|
||||||
gevent.spawn(util.fetch_url, base_url + '/videos?pbj=1&view=0', headers_desktop, debug_name='gen_channel_videos')
|
gevent.spawn(get_channel_first_page, base_url=base_url),
|
||||||
)
|
)
|
||||||
gevent.joinall(tasks)
|
gevent.joinall(tasks)
|
||||||
util.check_gevent_exceptions(*tasks)
|
util.check_gevent_exceptions(*tasks)
|
||||||
|
@ -484,7 +484,7 @@ def _get_upstream_videos(channel_id):
|
|||||||
|
|
||||||
tasks = (
|
tasks = (
|
||||||
# channel page, need for video duration
|
# channel page, need for video duration
|
||||||
gevent.spawn(_get_channel_tab, channel_id, channel_status_name),
|
gevent.spawn(channel.get_channel_first_page, channel_id=channel_id),
|
||||||
# need atoma feed for exact published time
|
# need atoma feed for exact published time
|
||||||
gevent.spawn(_get_atoma_feed, channel_id)
|
gevent.spawn(_get_atoma_feed, channel_id)
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user