aboutsummaryrefslogtreecommitdiffstats
path: root/youtube/channel.py
diff options
context:
space:
mode:
authorJames Taylor <user234683@users.noreply.github.com>2020-08-12 14:46:29 -0700
committerJames Taylor <user234683@users.noreply.github.com>2020-08-12 14:46:29 -0700
commitac9b7f01620210de55d4bb50808877f2a0f4ccef (patch)
treefd17f1602b2778de0f1d9fe765252e874dcdd744 /youtube/channel.py
parent4bedf554610191065f374492ab261260d9d5492a (diff)
downloadyt-local-ac9b7f01620210de55d4bb50808877f2a0f4ccef.tar.lz
yt-local-ac9b7f01620210de55d4bb50808877f2a0f4ccef.tar.xz
yt-local-ac9b7f01620210de55d4bb50808877f2a0f4ccef.zip
Switch to desktop endpnt w/ new ctoken format except sort by old>1
Sorting by old for pages > 1 currently broken on some channels; it's still using the mobile endpoint.
Diffstat (limited to 'youtube/channel.py')
-rw-r--r--youtube/channel.py31
1 files changed, 19 insertions, 12 deletions
diff --git a/youtube/channel.py b/youtube/channel.py
index 2ba2440..efb336b 100644
--- a/youtube/channel.py
+++ b/youtube/channel.py
@@ -28,7 +28,8 @@ headers_pbj = (
('X-YouTube-Client-Name', '2'),
('X-YouTube-Client-Version', '2.20180830'),
)
-generic_cookie = (('Cookie', 'VISITOR_INFO1_LIVE=8XihrAcN1l4'),)
+real_cookie = (('Cookie', 'VISITOR_INFO1_LIVE=8XihrAcN1l4'),)
+generic_cookie = (('Cookie', 'VISITOR_INFO1_LIVE=ST1Ti53r4fU'),)
# SORT:
# videos:
@@ -89,17 +90,23 @@ def channel_ctoken_mobile(channel_id, page, sort, tab, view=1):
return base64.urlsafe_b64encode(pointless_nest).decode('ascii')
def get_channel_tab(channel_id, page="1", sort=3, tab='videos', view=1, print_status=True):
- ctoken = channel_ctoken_mobile(channel_id, page, sort, tab, view)
- ctoken = ctoken.replace('=', '%3D')
- url = ('https://m.youtube.com/channel/' + channel_id + '/' + tab
- + '?ctoken=' + ctoken + '&pbj=1')
-
- if print_status:
- print("Sending channel tab ajax request")
- content = util.fetch_url(url,
- util.mobile_ua + headers_pbj + generic_cookie, debug_name='channel_tab')
- if print_status:
- print("Finished recieving channel tab response")
+ message = 'Got channel tab' if print_status else None
+
+ if int(sort) == 2 and int(page) > 1: # use mobile endpoint
+ ctoken = channel_ctoken_mobile(channel_id, page, sort, tab, view)
+ ctoken = ctoken.replace('=', '%3D')
+ url = ('https://m.youtube.com/channel/' + channel_id + '/' + tab
+ + '?ctoken=' + ctoken + '&pbj=1')
+ content = util.fetch_url(url,
+ util.mobile_ua + headers_pbj + real_cookie,
+ debug_name='channel_tab', report_text=message)
+ else: # use desktop endpoint
+ ctoken = channel_ctoken_desktop(channel_id, page, sort, tab, view)
+ ctoken = ctoken.replace('=', '%3D')
+ url = 'https://www.youtube.com/browse_ajax?ctoken=' + ctoken
+ content = util.fetch_url(url,
+ util.desktop_ua + headers_1 + generic_cookie,
+ debug_name='channel_tab', report_text=message)
return content