Skip to content

Instantly share code, notes, and snippets.

@jmhublar
Created November 16, 2023 07:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmhublar/edc3daebea068764318a14baa03e88c9 to your computer and use it in GitHub Desktop.
Save jmhublar/edc3daebea068764318a14baa03e88c9 to your computer and use it in GitHub Desktop.
List liked youtubes.
import os
import google_auth_oauthlib.flow
import googleapiclient.discovery
import googleapiclient.errors
scopes = ["https://www.googleapis.com/auth/youtube.readonly"]
def main():
# Disable OAuthlib's HTTPS verification when running locally.
# *DO NOT* leave this option enabled in production.
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
api_service_name = "youtube"
api_version = "v3"
client_secrets_file = "client_secret.json"
# Get credentials and create an API client
flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
client_secrets_file, scopes)
credentials = flow.run_local_server(port=0)
youtube = googleapiclient.discovery.build(
api_service_name, api_version, credentials=credentials)
next_page_token = None
markdown_list = []
while True:
request = youtube.videos().list(
myRating="like",
part="snippet",
maxResults=50,
pageToken=next_page_token
)
response = request.execute()
for item in response['items']:
video_id = item['id']
video_title = item['snippet']['title']
markdown_list.append(f'[{video_title}](https://www.youtube.com/watch?v={video_id})')
next_page_token = response.get('nextPageToken')
if next_page_token is None:
break
# Print Markdown
for markdown in markdown_list:
print(markdown)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment