def config(): completer = WordCompleter(['youtube']) option = prompt('Configure >>> ', completer=completer) if option == 'youtube': youtube = YouTube() youtube.init() result = youtube.video_categories() if len(result['items']) > 1: print("Sample request succesful; all seems to be working.")
def upload_video(): vfs = VideoFileSegments() pi = ProcessingInformation() if vfs.count_with_status('processing') != 1: print("Need to process exactly one video") sys.exit(1) processing = vfs.get_first_with_status('processing') video_filename = processing['video_file'] print("Uploading video to YouTube") print("") title = prompt("Title >>> ") print("Uploading video", video_filename, "with title", title) youtube = YouTube() youtube.init() description = pi.get_description() youtube.upload_file(video_filename, title, description) vfs.update_status_from_to('processing', 'youtube') vfs.save() pi.done()
import os from flask import Flask, jsonify from flask_sqlalchemy import SQLAlchemy from lib.youtube import YouTube app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get( 'SQLALCHEMY_DATABASE_URI') app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['YOUTUBE_API_KEY'] = os.environ.get('YOUTUBE_API_KEY') db = SQLAlchemy(app) youtube = YouTube(app) @app.route('/') def index(): return 'test-flask' @app.route('/youtube/most_rated/<string:channel_id>', methods=['GET', 'OPTIONS']) def youtube_most_rated(channel_id): most_rated = youtube.list_channel_videos(channel_id=channel_id) def video_like_ratio(video): statistics = video['video']['statistics'] if 'likeCount' not in statistics or 'dislikeCount' not in statistics: return 0
import argparse from lib.youtube import YouTube parser = argparse.ArgumentParser(description='Uploads video to youtube') parser.add_argument('--input', help='video to upload', default='output/tmp.mp4') parser.add_argument('--title', help='title of video') parser.add_argument('--description', help='description of video') args = parser.parse_args() youtube = YouTube() youtube.init() youtube.upload_file(args.input, args.title, args.description)
from lib.git import Git from lib.git import parser as github_parser from lib.spreadsheet import Spreadsheet from lib.spreadsheet import parser as spreadsheet_parser from lib.youtube import YouTube parent_parsers = [spreadsheet_parser, github_parser] parser = argparse.ArgumentParser( description='Add YouTube metadata and publish new videos', parents=parent_parsers) args = parser.parse_args() spreadsheet = Spreadsheet(args.spreadsheet_id) youtube = YouTube() print('Getting all talks from spreadsheet with YouTube IDs') talks = spreadsheet.get_unpublished_youtube_talks() print('{} unpublished talks'.format(len(talks))) ids = [talk.youtube_id for talk in talks] print('Getting videos from YouTube') videos = youtube.get_videos(ids) for talk in talks: print('Unpublished talk: {}'.format(talk.title)) video = filter(lambda x: talk.youtube_id == x.youtube_id, videos)[0] print('\tYouTube ID: {}'.format(video.youtube_id)) print('\tSetting metadata and setting status to UNLISTED') title = '{} ({})'.format(talk.title, talk.speakers) video.publish(title, talk.description)
from lib.youtube import YouTube youtube = YouTube() youtube.init() print("All done")
parser.add_argument('--description', help='description of video', default=None) args = parser.parse_args() vfs = VideoFileSegments() pi = ProcessingInformation() if vfs.count_with_status('processing') != 1: print("Need to process exactly one video") sys.exit(1) processing = vfs.get_first_with_status('processing') video_filename = processing['video_file'] print("Uploading video", video_filename, "with title", args.title) youtube = YouTube() youtube.init() if args.description: description = args.description + \ "\n\nCode for processing video available at https://github.com/HelgeKrueger/video" else: description = pi.get_description() youtube.upload_file(video_filename, args.title, description) vfs.update_status_from_to('processing', 'youtube') vfs.save() pi.done()