Created
June 2, 2020 19:34
-
-
Save paulfurber/e82672419d84da0f62462effd4670b2d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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