<jupyter_start><jupyter_text>From drive to youtube video upload Required packages<jupyter_code>!pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib<jupyter_output>Requirement already satisfied: google-api-python-client in /usr/local/lib/python3.7/dist-packages (1.12.8)
Collecting google-api-python-client
  Downloading google_api_python_client-2.15.0-py2.py3-none-any.whl (7.2 MB)
[K     |████████████████████████████████| 7.2 MB 15.8 MB/s 
[?25hRequirement already satisfied: google-auth-httplib2 in /usr/local/lib/python3.7/dist-packages (0.0.4)
Collecting google-auth-httplib2
  Downloading google_auth_httplib2-0.1.0-py2.py3-none-any.whl (9.3 kB)
Requirement already satisfied: google-auth-oauthlib in /usr/local/lib/python3.7/dist-packages (0.4.4)
Collecting google-auth-oauthlib
  Downloading google_auth_oauthlib-0.4.5-py2.py3-none-any.whl (18 kB)
Requirement already satisfied: google-api-core<3.0.0dev,>=1.21.0 in /usr/local/lib/python3.7/dist-packages (from google-api-python-client) (1.26.3)
Requirement already satisfied: uritemplate<4dev,>=3.0.0 in /usr/local/lib/python3.7/dist-packages (from google-api-python-client) (3.0.1)
Requirement already[...]<jupyter_text>Copying file from drive to colab<jupyter_code>!cp '/content/drive/MyDrive/Comp final BIGGER.mp4' '/content/'<jupyter_output><empty_output><jupyter_text>Now uploading file to youtube  *'' in following code notifies important changes*<jupyter_code>import datetime
from googleapiclient.http import MediaFileUpload
import pickle
import os
from google_auth_oauthlib.flow import Flow, InstalledAppFlow
from googleapiclient.discovery import build
from googleapiclient.http import MediaFileUpload, MediaIoBaseDownload
from google.auth.transport.requests import Request
import datetime

CLIENT_SECRET_FILE = '/content/client_secret.json'  #
API_NAME = 'youtube'
API_VERSION = 'v3'
SCOPES = ['https://www.googleapis.com/auth/youtube.upload']



def Create_Service(client_secret_file, api_name, api_version, *scopes):
    print(client_secret_file, api_name, api_version, scopes, sep='-')
    CLIENT_SECRET_FILE = client_secret_file
    API_SERVICE_NAME = api_name
    API_VERSION = api_version
    SCOPES = [scope for scope in scopes[0]]
    print(SCOPES)

    cred = None

    pickle_file = f'token_{API_SERVICE_NAME}_{API_VERSION}.pickle'
    # print(pickle_file)

    if os.path.exists(pickle_file):
        with open(pickle_file, 'rb') as token:
            cred = pickle.load(token)

    if not cred or not cred.valid:
        if cred and cred.expired and cred.refresh_token:
            cred.refresh(Request())
        else:
            flow = InstalledAppFlow.from_client_secrets_file(CLIENT_SECRET_FILE, SCOPES)
            cred = flow.run_local_server()

        with open(pickle_file, 'wb') as token:
            pickle.dump(cred, token)

    try:
        service = build(API_SERVICE_NAME, API_VERSION, credentials=cred)
        print(API_SERVICE_NAME, 'service created successfully')
        return service
    except Exception as e:
        print('Unable to connect.')
        print(e)
        return None

def convert_to_RFC_datetime(year=1900, month=1, day=1, hour=0, minute=0):
    dt = datetime.datetime(year, month, day, hour, minute, 0).isoformat() + 'Z'
    return dt


service = Create_Service(CLIENT_SECRET_FILE, API_NAME, API_VERSION, SCOPES)

upload_date_time = datetime.datetime(2021, 8, 7, 2, 3, 0).isoformat() + '.000Z' #

request_body = {
    'snippet': {
        'categoryI': 19,
        'title': "Brother's wedding invitation",
        'description': 'sdasdHello World Description',
        'tags': ['Travel', 'video test', 'Travel Tips','wedding invitation']
    },
    'status': {
        'privacyStatus': 'public', #
        # 'publishAt': upload_date_time,  #this only works for private videos
        'selfDeclaredMadeForKids': False, 
    },
    'notifySubscribers': False #
}

mediaFile = MediaFileUpload('/content/comp_final_bigger.mp4')  ##

response_upload = service.videos().insert(
    part='snippet,status',
    body=request_body,
    media_body=mediaFile
).execute()


service.thumbnails().set(
    videoId=response_upload.get('id'),
    media_body=MediaFileUpload('thumbnail.png')   ##
).execute()<jupyter_output>/content/client_secret.json-youtube-v3-(['https://www.googleapis.com/auth/youtube.upload'],)
['https://www.googleapis.com/auth/youtube.upload']
youtube service created successfully
{'fraction_non_alphanumeric': 0.12823397075365578, 'fraction_numerical': 0.022272215973003374, 'mean_word_length': 4.206088992974239, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 3, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '150834', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 1568, 'n_tokens_neox': 1499, 'n_words': 296, 'path': 'yv3.ipynb', 'repo_name': 'sandeepyadav1478/Uploading-video-on-youtube', 'size': '4445'}