Use absolut paths for credential files
This commit is contained in:
parent
756d4c2afb
commit
d901a969f2
19
robocyp.py
19
robocyp.py
@ -17,6 +17,7 @@ _playlists = {}
|
|||||||
DEFAULT_OUTPUT_TMPL = "%(channel)s/%(upload_date)s_%(title)s_[%(id)s].%(ext)s"
|
DEFAULT_OUTPUT_TMPL = "%(channel)s/%(upload_date)s_%(title)s_[%(id)s].%(ext)s"
|
||||||
# download video 1080p or lower with audio
|
# download video 1080p or lower with audio
|
||||||
DEFAULT_FORMAT = "bestvideo[height<=720]+bestaudio/best[height<=720]"
|
DEFAULT_FORMAT = "bestvideo[height<=720]+bestaudio/best[height<=720]"
|
||||||
|
program_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|
||||||
|
|
||||||
def _truncate_title(title: str, length: int = 30) -> str:
|
def _truncate_title(title: str, length: int = 30) -> str:
|
||||||
@ -32,14 +33,15 @@ def _truncate_title(title: str, length: int = 30) -> str:
|
|||||||
def get_yt_creds():
|
def get_yt_creds():
|
||||||
""" Get YouTube API credentials """
|
""" Get YouTube API credentials """
|
||||||
creds = None
|
creds = None
|
||||||
client_secrets_file = "client_secrets_file.json"
|
client_secrets_file = os.path.join(program_dir, "client_secrets_file.json")
|
||||||
scopes = ["https://www.googleapis.com/auth/youtube.force-ssl"]
|
scopes = ["https://www.googleapis.com/auth/youtube.force-ssl"]
|
||||||
|
|
||||||
# The file token.json stores the user's access and refresh tokens, and is
|
# The file token.json stores the user's access and refresh tokens, and is
|
||||||
# created automatically when the authorization flow completes for the first
|
# created automatically when the authorization flow completes for the first
|
||||||
# time.
|
# time.
|
||||||
if os.path.exists("token.json"):
|
token_file = os.path.join(program_dir, "token.json")
|
||||||
creds = Credentials.from_authorized_user_file("token.json", scopes)
|
if os.path.exists(token_file):
|
||||||
|
creds = Credentials.from_authorized_user_file(token_file, scopes)
|
||||||
|
|
||||||
# If there are no (valid) credentials available, let the user log in.
|
# If there are no (valid) credentials available, let the user log in.
|
||||||
if not creds or not creds.valid:
|
if not creds or not creds.valid:
|
||||||
@ -54,7 +56,7 @@ def get_yt_creds():
|
|||||||
)
|
)
|
||||||
creds = flow.run_local_server(port=0)
|
creds = flow.run_local_server(port=0)
|
||||||
# Save the credentials for the next run
|
# Save the credentials for the next run
|
||||||
with open("token.json", "w") as token:
|
with open(token_file, "w") as token:
|
||||||
token.write(creds.to_json())
|
token.write(creds.to_json())
|
||||||
|
|
||||||
return creds
|
return creds
|
||||||
@ -71,10 +73,11 @@ def exit_on_exceeded_quota(e: HttpError):
|
|||||||
def read_playlists_file():
|
def read_playlists_file():
|
||||||
""" Read playlists.csv and return a dictionary of playlist names to playlist IDs """
|
""" Read playlists.csv and return a dictionary of playlist names to playlist IDs """
|
||||||
global _playlists
|
global _playlists
|
||||||
if not os.path.exists('playlists.csv'):
|
playlists_file = os.path.join(program_dir, 'playlists.csv')
|
||||||
print('playlists.csv not found')
|
if not os.path.exists(playlists_file):
|
||||||
|
print(f'{playlists_file} not found')
|
||||||
return {}
|
return {}
|
||||||
with open('playlists.csv', newline='') as csvfile:
|
with open(playlists_file, newline='') as csvfile:
|
||||||
reader = csv.DictReader(csvfile)
|
reader = csv.DictReader(csvfile)
|
||||||
_playlists = {row['name']: row['playlist_id'] for row in reader}
|
_playlists = {row['name']: row['playlist_id'] for row in reader}
|
||||||
|
|
||||||
@ -352,7 +355,7 @@ def main():
|
|||||||
plitems_processed.add(video_id)
|
plitems_processed.add(video_id)
|
||||||
|
|
||||||
elif args.command == "download":
|
elif args.command == "download":
|
||||||
db = TinyDB('db.json')
|
db = TinyDB(os.path.join(program_dir, 'db.json'))
|
||||||
query = Query()
|
query = Query()
|
||||||
ydl_opts = {
|
ydl_opts = {
|
||||||
'outtmpl': os.path.join(args.dst_folder, DEFAULT_OUTPUT_TMPL),
|
'outtmpl': os.path.join(args.dst_folder, DEFAULT_OUTPUT_TMPL),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user