def __init__(self, api_key, channels): Session = sessionmaker(bind=engine) self.logger = getLogger('youtuber.grabber') self.api = API(api_key=api_key, client_id='', client_secret='') self.channels = channels self.session = Session()
def init(): YouTubeController.refresh_token = SecureSettings.get_string( "youtube_refresh_token") YouTubeController.api = API( client_id=SecureSettings.get_string("youtube_client_id"), client_secret=SecureSettings.get_string("youtube_client_secret"), api_key=SecureSettings.get_string("youtube_api_key"))
def main(): parser = argparse.ArgumentParser() parser.add_argument( '-o', '--output', help='Absolute path to output file. Output file can exist.', required=True) parser.add_argument('-k', '--api-key', help='Youtube API key.', required=True) parser.add_argument('-v', '--visible', help='Append new videos as visible.', default=False) parser.add_argument('-u', '--update', help='Update video in output file if it exists.', default=False) parser.add_argument( '--update-attributes', '--update-attributes', help= 'Comma separated list of attributes allowed to update. Works only when --update flag is true', default='description,title,preview') args = parser.parse_args() global api api = API(api_key=args.api_key, client_secret='', client_id='') original_videos = get_original_videos(args.output) youtube_videos = fetch_videos() merged_videos = merge_videos(original_videos, youtube_videos, args.visible, args.update, args.update_attributes) save_videos(merged_videos, args.output)
def add_song_info_from_spotify_url(url: str, username): details = dict(sp.track(url)) name = details['name'] duration = round(int(details['duration_ms']) / 60000, 2) cover_url = details['album']['images'][0]['url'] add_song_if_not_exists(name, duration, username, cover_url) # Youtube ## login g_client_id = "724786455286-h797c1jpr7nq4ivsqca73gplkbol5u1c.apps.googleusercontent.com" g_client_secret = "AxRk4DHa9IfLHd4kDMUXuilQ" g_key = "AIzaSyDvyloHqIVcizjDdwu0CvTwVvZTGDmrrbE" g = API(client_id=g_client_id, client_secret=g_client_secret, api_key=g_key) ## Functions def get_id_from_url(url: str): if "youtu.be" in url: result = urlparse(url) v_id = result.path.replace('/', '') return v_id else: result = urlparse(url) v_id = result.query.replace('v=', '') return v_id
def set_up_youtube(self): self.yt = API(client_id='', client_secret='', api_key=self.api_key)
import json from yaml import load, FullLoader from youtube import API from youtube_transcript_api import YouTubeTranscriptApi with open("keys.yaml", "r") as keys: config = load(keys, Loader=FullLoader) api = API(client_id=config['client_id'], client_secret=config["client_secret"], api_key=config["api_key"]) terms = [ "linear algebra", "calculus", "derivative", "shakespear", "python coding tutorial" ] def get_transcript(video_id): return YouTubeTranscriptApi.get_transcript(video_id, languages=["en"]) def write_transcript_to_file(name, transcript): with open("transcripts/" + name + '.json', 'w') as writefile: json.dump(transcript, writefile) def get_search_ids(term, max_ids=10000): ids = list() token = None while len(ids) < max_ids: response = api.get( 'search', q=term,