mirror of
https://github.com/anatolykopyl/youtube-cdl.git
synced 2026-03-26 12:55:11 +00:00
✨ Oauth arguments passthrough
This commit is contained in:
@@ -12,7 +12,7 @@ from rich.progress import track
|
|||||||
|
|
||||||
CLIENT_SECRETS_FILE = "client_secrets.json"
|
CLIENT_SECRETS_FILE = "client_secrets.json"
|
||||||
|
|
||||||
YOUTUBE_READ_WRITE_SCOPE = "https://www.googleapis.com/auth/youtube"
|
YOUTUBE_READ_SCOPE = "https://www.googleapis.com/auth/youtube"
|
||||||
YOUTUBE_API_SERVICE_NAME = "youtube"
|
YOUTUBE_API_SERVICE_NAME = "youtube"
|
||||||
YOUTUBE_API_VERSION = "v3"
|
YOUTUBE_API_VERSION = "v3"
|
||||||
|
|
||||||
@@ -35,11 +35,11 @@ https://developers.google.com/api-client-library/python/guide/aaa_client_secrets
|
|||||||
CLIENT_SECRETS_FILE)))
|
CLIENT_SECRETS_FILE)))
|
||||||
|
|
||||||
|
|
||||||
def retrieve_youtube_subscriptions():
|
def retrieve_youtube_subscriptions(args):
|
||||||
# In order to retrieve the YouTube subscriptions for the current user,
|
# In order to retrieve the YouTube subscriptions for the current user,
|
||||||
# the user needs to authenticate and authorize access to their YouTube
|
# the user needs to authenticate and authorize access to their YouTube
|
||||||
# subscriptions.
|
# subscriptions.
|
||||||
youtube_authorization = get_authenticated_service()
|
youtube_authorization = get_authenticated_service(args)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# init
|
# init
|
||||||
@@ -69,7 +69,7 @@ def retrieve_youtube_subscriptions():
|
|||||||
err.resp.status, err.content))
|
err.resp.status, err.content))
|
||||||
|
|
||||||
|
|
||||||
def get_authenticated_service():
|
def get_authenticated_service(args):
|
||||||
# Create a Storage instance to store and retrieve a single
|
# Create a Storage instance to store and retrieve a single
|
||||||
# credential to and from a file. Used to store the
|
# credential to and from a file. Used to store the
|
||||||
# oauth2 credentials for the current python script.
|
# oauth2 credentials for the current python script.
|
||||||
@@ -80,15 +80,16 @@ def get_authenticated_service():
|
|||||||
if credentials is None or credentials.invalid:
|
if credentials is None or credentials.invalid:
|
||||||
# Create a Flow instance from a client secrets file
|
# Create a Flow instance from a client secrets file
|
||||||
flow = flow_from_clientsecrets(CLIENT_SECRETS_FILE,
|
flow = flow_from_clientsecrets(CLIENT_SECRETS_FILE,
|
||||||
scope=YOUTUBE_READ_WRITE_SCOPE,
|
scope=YOUTUBE_READ_SCOPE,
|
||||||
message=MISSING_CLIENT_SECRETS_MESSAGE)
|
message=MISSING_CLIENT_SECRETS_MESSAGE)
|
||||||
# The run_flow method requires arguments.
|
|
||||||
# Initial default arguments are setup in tools, and any
|
oauth_args = argparser.parse_args(args=[])
|
||||||
# additional arguments can be added from the command-line
|
oauth_args.auth_host_name = args.auth_host_name
|
||||||
# and passed into this method.
|
oauth_args.auth_host_port = [args.auth_host_port]
|
||||||
args = argparser.parse_args()
|
oauth_args.noauth_local_webserver = args.noauth_local_webserver
|
||||||
|
|
||||||
# Obtain valid credentials
|
# Obtain valid credentials
|
||||||
credentials = run_flow(flow, storage, args)
|
credentials = run_flow(flow, storage, oauth_args)
|
||||||
|
|
||||||
# Build and return a Resource object for interacting with an YouTube API
|
# Build and return a Resource object for interacting with an YouTube API
|
||||||
return build(YOUTUBE_API_SERVICE_NAME,
|
return build(YOUTUBE_API_SERVICE_NAME,
|
||||||
|
|||||||
10
main.py
10
main.py
@@ -43,6 +43,14 @@ parser.add_argument('-a', '--all', action='store_true',
|
|||||||
parser.add_argument('-f', '--format', action='store', type=str, default='best',
|
parser.add_argument('-f', '--format', action='store', type=str, default='best',
|
||||||
help='Format to pass to youtube-dl. (default: best)')
|
help='Format to pass to youtube-dl. (default: best)')
|
||||||
|
|
||||||
|
# oauth2client.tools.run_flow arguments
|
||||||
|
parser.add_argument('--auth_host_name', action='store', type=str, default='localhost',
|
||||||
|
help='Host name to use when running a local web server to handle redirects during OAuth authorization.')
|
||||||
|
parser.add_argument('--auth_host_port', action='store', type=int, default=8080,
|
||||||
|
help='Port to use when running a local web server to handle redirects during OAuth authorization.')
|
||||||
|
parser.add_argument('--noauth_local_webserver', action='store_true',
|
||||||
|
help='Run a local web server to handle redirects during OAuth authorization.')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
json_input = args.input
|
json_input = args.input
|
||||||
@@ -84,7 +92,7 @@ if json_input:
|
|||||||
all_channels = json.loads(f.read())
|
all_channels = json.loads(f.read())
|
||||||
f.close()
|
f.close()
|
||||||
else:
|
else:
|
||||||
all_channels = retrieve_youtube_subscriptions()
|
all_channels = retrieve_youtube_subscriptions(args)
|
||||||
curr_channel = 0
|
curr_channel = 0
|
||||||
c.print(
|
c.print(
|
||||||
f'You will be prompted if you want to download a channel for each of your subscriptions. (total {len(all_channels)})', style='bold')
|
f'You will be prompted if you want to download a channel for each of your subscriptions. (total {len(all_channels)})', style='bold')
|
||||||
|
|||||||
Reference in New Issue
Block a user