diff --git a/README.md b/README.md index 68ef739..473293e 100644 --- a/README.md +++ b/README.md @@ -83,10 +83,12 @@ If you plan a larger usage, please consider creating your own youtube_secret fil - Go to the [Google console](https://console.developers.google.com/). - Create project. - - Side menu: APIs & auth -> APIs - - Top menu: Enabled API(s): Enable all Youtube APIs. - - Side menu: APIs & auth -> Credentials. - - Create a Client ID: Add credentials -> OAuth 2.0 Client ID -> Other -> Name: prismedia1 -> Create -> OK + - Side menu: APIs & Services -> APIs + - Top menu: Enabled API(s): Enable Youtube Data v3 APIs. + - Side menu: OAuth consent screen + - Create an app -> User type External -> Add scope from Youtube Data API v3: `.../auth/youtube.force-ssl` and `.../auth/youtube.upload` -> No test user -> save & create + - Side menu: APIs & Services -> Credentials. + - Create a Client ID: Create credentials -> OAuth Client ID -> Other -> Name: prismedia1 -> Create -> OK - Download JSON: Under the section "OAuth 2.0 client IDs". Save the file to your local system. - Save this JSON as your youtube_secret.json file. diff --git a/prismedia/pt_upload.py b/prismedia/pt_upload.py index adb5a36..6afbdd3 100644 --- a/prismedia/pt_upload.py +++ b/prismedia/pt_upload.py @@ -381,7 +381,10 @@ def create_callback(encoder, progress_type): def run(options): secret = RawConfigParser() try: - secret.read(PEERTUBE_SECRETS_FILE) + if options.get('--credentialsdir') : + secret.read(os.path.join(options.get('--credentialsdir'), PEERTUBE_SECRETS_FILE)) + else : + secret.read(PEERTUBE_SECRETS_FILE) except Exception as e: logger.critical("Peertube: Error loading " + str(PEERTUBE_SECRETS_FILE) + ": " + str(e)) exit(1) diff --git a/prismedia/upload.py b/prismedia/upload.py index 6fd1778..a5e7f92 100755 --- a/prismedia/upload.py +++ b/prismedia/upload.py @@ -27,6 +27,7 @@ Options: By default Prismedia search a .txt based on the video name and will decode the file as UTF-8 (so make sure your nfo file is UTF-8 encoded) See nfo_example.txt for more details + --credentialsdir=STRING Set directory where to search for secret file. --platform=STRING List of platform(s) to upload to, comma separated. Supported platforms are youtube and peertube (default is both) --language=STRING Specify the default language for video. See below for supported language. (default is English) @@ -279,6 +280,7 @@ def main(): Optional('--withCategory', default=False): bool, Optional('--withLanguage', default=False): bool, Optional('--withChannel', default=False): bool, + Optional('--credentialsdir'): Or(None, And(str, os.path.exists, error='credentialsdir does not exist')), # This allow to return all other options for further use: https://github.com/keleshev/schema#extra-keys object: object }) diff --git a/prismedia/yt_upload.py b/prismedia/yt_upload.py index e8809c5..b00dd52 100644 --- a/prismedia/yt_upload.py +++ b/prismedia/yt_upload.py @@ -48,8 +48,8 @@ RETRIABLE_EXCEPTIONS = ( RETRIABLE_STATUS_CODES = [500, 502, 503, 504] -CLIENT_SECRETS_FILE = 'youtube_secret.json' -CREDENTIALS_PATH = ".youtube_credentials.json" +CLIENT_SECRETS_FILE_BASE = 'youtube_secret.json' +CREDENTIALS_PATH_BASE = ".youtube_credentials.json" SCOPES = ['https://www.googleapis.com/auth/youtube.upload', 'https://www.googleapis.com/auth/youtube.force-ssl'] API_SERVICE_NAME = 'youtube' API_VERSION = 'v3' @@ -358,6 +358,13 @@ def hearthbeat(): def run(options): + global CLIENT_SECRETS_FILE, CREDENTIALS_PATH + if options.get('--credentialsdir') : + CLIENT_SECRETS_FILE = os.path.join(options.get('--credentialsdir'), CLIENT_SECRETS_FILE_BASE) + CREDENTIALS_PATH = os.path.join(options.get('--credentialsdir'), CREDENTIALS_PATH_BASE) + else : + CLIENT_SECRETS_FILE = CLIENT_SECRETS_FILE_BASE + CREDENTIALS_PATH = CREDENTIALS_PATH_BASE youtube = get_authenticated_service() try: initialize_upload(youtube, options)