Skip to content

Commit

Permalink
Fix error if channel has no Videos tab
Browse files Browse the repository at this point in the history
  • Loading branch information
glubsy committed Nov 1, 2022
1 parent 7df8ab2 commit 7a0cf1d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
7 changes: 3 additions & 4 deletions livestream_saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,16 +489,15 @@ def monitor_mode(config, args):
ch = YoutubeChannel(
URL, channel_id, session,
output_dir=args["output_dir"], hooks=args["hooks"], notifier=NOTIFIER)
ch.load_params()
ch.load_endpoints()
logger.info(f"Monitoring channel: {ch._id}")

while True:
live_videos = []
try:
# Get the list of upcoming videos. This is done separately because
# detection is flaky right now.
ch.get_upcoming_videos(update=True)
live_videos = ch.filter_videos('isLiveNow') # get the actual live stream
ch.get_upcoming_videos(update=True)

# TODO print to stdout and overwrite line
logger.debug(
"Live videos found for channel "
Expand Down
35 changes: 27 additions & 8 deletions livestream_saver/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self, URL, channel_id, session, notifier,
self.output_dir = output_dir
self.log = logger

def load_params(self) -> None:
def load_endpoints(self) -> None:
"""
Load params values to navigate through the innertube API.
This essentially gets the values from the Home tab json.
Expand Down Expand Up @@ -529,21 +529,40 @@ def filter_videos(self, filter_type: str = 'isLiveNow', update=True) -> List:
Usually there is only one live video active at a time.
"""
live_videos = []
for vid in self.get_community_videos(update=update):
if vid.get(filter_type):
live_videos.append(vid)

try:
for vid in self.get_community_videos(update=update):
if vid.get(filter_type):
live_videos.append(vid)
except TabNotFound as e:
# self.log.debug(f"No Community tab available for this channel: {e}")
pass

try:
for vid in self.get_membership_videos(update=update):
if vid.get(filter_type):
live_videos.append(vid)
except TabNotFound as e:
self.log.debug("No membership tab available.")
# self.log.debug(f"No membership tab available for this channel: {e}")
pass

public_videos = []
try:
public_videos = self.get_public_videos(update=update)
except TabNotFound as e:
# self.log.debug(f"No Videos tab available for this channel: {e}")
pass

public_streams = []
try:
public_streams = self.get_public_streams(update=update)
except TabNotFound as e:
# self.log.debug(f"No Live tab available for this channel: {e}")
pass

# No need to check for "upcoming_videos" because live videos should
# appear in the public videos list.
for vid in self.get_public_videos(update=update)\
+ self.get_public_streams(update=update):
for vid in public_videos + public_streams:
if vid.get(filter_type):
live_videos.append(vid)
return live_videos
Expand Down Expand Up @@ -597,7 +616,7 @@ def get_current_videos_response(self) -> Optional[Dict]:
"""
endpoint = self._endpoints.get("Videos")
if not endpoint:
raise Exception("Missing Videos tab endpoint data.")
raise TabNotFound("Missing Videos tab endpoint data.")

browseEndpoint = endpoint.get("browseEndpoint")
canonicalBaseUrl = browseEndpoint.get("canonicalBaseUrl", "")
Expand Down

0 comments on commit 7a0cf1d

Please sign in to comment.