Compare commits
No commits in common. "f97e6b5b1c5db19daf53c5146345e0a46224ff03" and "4d256d6aa408b4aab6a3f28741bca532947fb044" have entirely different histories.
f97e6b5b1c
...
4d256d6aa4
@ -1,35 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
# Python wrapper for REST API for some of the YouTube API.
|
|
||||||
from requests import get, post
|
|
||||||
import json
|
|
||||||
|
|
||||||
class YouTubeAPI(object):
|
|
||||||
def __init__(self, key):
|
|
||||||
self.url = 'https://www.googleapis.com/youtube/v3/'
|
|
||||||
self.key = key
|
|
||||||
|
|
||||||
# Sends get requests and turns requested data.
|
|
||||||
def getRequest(self, domain):
|
|
||||||
response = get('{}{}&key={}'.format(self.url,
|
|
||||||
domain,
|
|
||||||
self.key))
|
|
||||||
return json.loads(response.text)
|
|
||||||
|
|
||||||
def getVideo(self, part, id):
|
|
||||||
return self.getRequest('videos?part={}&id={}'.format(part, id))
|
|
||||||
|
|
||||||
def getVideoInfo(self, tag):
|
|
||||||
snippet = self.getVideo('snippet', tag)
|
|
||||||
status = self.getVideo('status', tag)
|
|
||||||
snippet = snippet['items'][0]['snippet']
|
|
||||||
status = status['items'][0]['status']
|
|
||||||
title = snippet['title']
|
|
||||||
date = snippet['publishedAt']
|
|
||||||
channel = snippet['channelTitle']
|
|
||||||
description = snippet['description']
|
|
||||||
tags = snippet['tags']
|
|
||||||
privacy = status['privacyStatus']
|
|
||||||
return title, date, channel, description, tags, privacy
|
|
||||||
|
|
||||||
|
|
@ -1,11 +1,6 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
from youtube_api import YouTubeAPI
|
|
||||||
import sys
|
|
||||||
|
|
||||||
# Read YouTube API Key
|
# Read YouTube API Key
|
||||||
def getYouTubeAPIKey():
|
def getYouTubeAPIKey():
|
||||||
return open('youtube.key', 'r').read()
|
return open('youtube.key', 'r').read()
|
||||||
|
|
||||||
api = YouTubeAPI(getYouTubeAPIKey())
|
print(getYouTubeAPIKey())
|
||||||
print(api.getVideoInfo(sys.argv[1]))
|
exit(0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user