Exit on youtube quotes
This commit is contained in:
parent
32c372bb9b
commit
9a8d23592f
11
main.py
11
main.py
@ -51,6 +51,14 @@ def get_yt_creds():
|
||||
return creds
|
||||
|
||||
|
||||
def exit_on_exceeded_quota(e: HttpError):
|
||||
if e.resp.status == 403:
|
||||
for error in e.error_details:
|
||||
if error.get('reason') == 'quotaExceeded':
|
||||
print('Youtube quota exceeded, exiting')
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def read_playlists_file():
|
||||
""" Read playlists.csv and return a dictionary of playlist names to playlist IDs """
|
||||
global _playlists
|
||||
@ -96,6 +104,7 @@ def get_videos(yt_api, playlist_id):
|
||||
for item in response['items']:
|
||||
videos.append(item)
|
||||
except HttpError as e:
|
||||
exit_on_exceeded_quota(e)
|
||||
print(f'Error getting video IDs from playlist {playlist_name}: {e}')
|
||||
|
||||
print(f'Fetched {fetched} videos from playlist {playlist_name}')
|
||||
@ -126,6 +135,7 @@ def add_video_to_playlist(yt_api, video, playlist_id,
|
||||
print(f"Added video '{video_title}' [{video_id}] to playlist {playlist_name}")
|
||||
return True
|
||||
except HttpError as e:
|
||||
exit_on_exceeded_quota(e)
|
||||
print(f"Error adding video '{video_title}' [{video_id}] to playlist {playlist_name}: {e}")
|
||||
return False
|
||||
|
||||
@ -147,6 +157,7 @@ def remove_video_from_playlist(yt_api, video, playlist_id,
|
||||
f" from playlist {playlist_name}")
|
||||
return True
|
||||
except HttpError as e:
|
||||
exit_on_exceeded_quota(e)
|
||||
print(f"Error removing video '{video_title}' [{video_id}]"
|
||||
f" from playlist {playlist_name}: {e}")
|
||||
return False
|
||||
|
||||
Loading…
Reference in New Issue
Block a user