Subscriptions: Use playlist method to get channel videos
Use the UU (user uploads) playlist since it includes streams
This commit is contained in:
parent
4be01d3964
commit
2140f48919
@ -28,7 +28,8 @@ def playlist_ctoken(playlist_id, offset, include_shorts=True):
|
|||||||
return base64.urlsafe_b64encode(pointless_nest).decode('ascii')
|
return base64.urlsafe_b64encode(pointless_nest).decode('ascii')
|
||||||
|
|
||||||
|
|
||||||
def playlist_first_page(playlist_id, report_text="Retrieved playlist", use_mobile=False):
|
def playlist_first_page(playlist_id, report_text="Retrieved playlist",
|
||||||
|
use_mobile=False):
|
||||||
if use_mobile:
|
if use_mobile:
|
||||||
url = 'https://m.youtube.com/playlist?list=' + playlist_id + '&pbj=1'
|
url = 'https://m.youtube.com/playlist?list=' + playlist_id + '&pbj=1'
|
||||||
content = util.fetch_url(
|
content = util.fetch_url(
|
||||||
@ -47,7 +48,8 @@ def playlist_first_page(playlist_id, report_text="Retrieved playlist", use_mobil
|
|||||||
return content
|
return content
|
||||||
|
|
||||||
|
|
||||||
def get_videos(playlist_id, page, include_shorts=True, use_mobile=False):
|
def get_videos(playlist_id, page, include_shorts=True, use_mobile=False,
|
||||||
|
report_text='Retrieved playlist'):
|
||||||
# mobile requests return 20 videos per page
|
# mobile requests return 20 videos per page
|
||||||
if use_mobile:
|
if use_mobile:
|
||||||
page_size = 20
|
page_size = 20
|
||||||
@ -62,7 +64,7 @@ def get_videos(playlist_id, page, include_shorts=True, use_mobile=False):
|
|||||||
include_shorts=include_shorts)
|
include_shorts=include_shorts)
|
||||||
url += "&pbj=1"
|
url += "&pbj=1"
|
||||||
content = util.fetch_url(
|
content = util.fetch_url(
|
||||||
url, headers, report_text="Retrieved playlist",
|
url, headers, report_text=report_text,
|
||||||
debug_name='playlist_videos'
|
debug_name='playlist_videos'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from youtube import util, yt_data_extract, channel, local_playlist
|
from youtube import util, yt_data_extract, channel, local_playlist, playlist
|
||||||
from youtube import yt_app
|
from youtube import yt_app
|
||||||
import settings
|
import settings
|
||||||
|
|
||||||
@ -463,7 +463,20 @@ def _get_atoma_feed(channel_id):
|
|||||||
|
|
||||||
def _get_channel_videos_first_page(channel_id, channel_status_name):
|
def _get_channel_videos_first_page(channel_id, channel_status_name):
|
||||||
try:
|
try:
|
||||||
return channel.get_channel_first_page(channel_id=channel_id)
|
# First try the playlist method
|
||||||
|
pl_json = playlist.get_videos('UU' + channel_id[2:], 1,
|
||||||
|
include_shorts=False, report_text=None)
|
||||||
|
pl_info = yt_data_extract.extract_playlist_info(pl_json)
|
||||||
|
if pl_info.get('items'):
|
||||||
|
pl_info['items'] = pl_info['items'][0:30]
|
||||||
|
return pl_info
|
||||||
|
|
||||||
|
# Try the channel api method
|
||||||
|
channel_json = channel.get_channel_first_page(channel_id=channel_id)
|
||||||
|
channel_info = yt_data_extract.extract_channel_info(
|
||||||
|
json.loads(channel_json), 'videos'
|
||||||
|
)
|
||||||
|
return channel_info
|
||||||
except util.FetchError as e:
|
except util.FetchError as e:
|
||||||
if e.code == '429' and settings.route_tor:
|
if e.code == '429' and settings.route_tor:
|
||||||
error_message = ('Error checking channel ' + channel_status_name
|
error_message = ('Error checking channel ' + channel_status_name
|
||||||
@ -497,7 +510,7 @@ def _get_upstream_videos(channel_id):
|
|||||||
)
|
)
|
||||||
gevent.joinall(tasks)
|
gevent.joinall(tasks)
|
||||||
|
|
||||||
channel_tab, feed = tasks[0].value, tasks[1].value
|
channel_info, feed = tasks[0].value, tasks[1].value
|
||||||
|
|
||||||
# extract published times from atoma feed
|
# extract published times from atoma feed
|
||||||
times_published = {}
|
times_published = {}
|
||||||
@ -535,9 +548,8 @@ def _get_upstream_videos(channel_id):
|
|||||||
except defusedxml.ElementTree.ParseError:
|
except defusedxml.ElementTree.ParseError:
|
||||||
print('Failed to read atoma feed for ' + channel_status_name)
|
print('Failed to read atoma feed for ' + channel_status_name)
|
||||||
|
|
||||||
if channel_tab is None: # there was an error
|
if channel_info is None: # there was an error
|
||||||
return
|
return
|
||||||
channel_info = yt_data_extract.extract_channel_info(json.loads(channel_tab), 'videos')
|
|
||||||
if channel_info['error']:
|
if channel_info['error']:
|
||||||
print('Error checking channel ' + channel_status_name + ': ' + channel_info['error'])
|
print('Error checking channel ' + channel_status_name + ': ' + channel_info['error'])
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user