Skip to content

Instantly share code, notes, and snippets.

@paulfurber
Created Jun 2, 2020
Embed
What would you like to do?
# -*- coding: utf-8 -*-
import os
import arrow
import google_auth_oauthlib.flow
import googleapiclient.discovery
import googleapiclient.errors
from pprint import pprint
SEBASTIAN_CHANNEL = 'UC2OB-K2aZ8IT6bddJoDm1JA'
def write_item(f, item):
f.write("Title: %s\n" % item['snippet']['title'])
f.write("Date: %s \n" % item['snippet']['publishedAt'])
f.write("VideoID: %s\n" % item['contentDetails']['videoId'])
f.write("Description: %s\n\n\n" % item['snippet']['description'])
def main():
api_service_name = "youtube"
api_version = "v3"
DEVELOPER_KEY = "YOUR-DEVELOPER-KEY"
youtube = googleapiclient.discovery.build(
api_service_name, api_version, developerKey=DEVELOPER_KEY)
request = youtube.channels().list(
part="snippet,contentDetails",
id=SEBASTIAN_CHANNEL
)
response = request.execute()
upload_playlist_id = response['items'][0]['contentDetails']['relatedPlaylists']['uploads']
request2 = youtube.playlistItems().list(
part="snippet,contentDetails",
playlistId = upload_playlist_id,
maxResults = 50
)
response2 = request2.execute()
fname = "sebastian-{}".format(arrow.now().ctime())
with open(fname, "w") as f:
for i in response2['items']:
write_item(f, i)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment