diff --git a/README.md b/README.md index 4aa09ac..122a39c 100644 --- a/README.md +++ b/README.md @@ -4,17 +4,25 @@ A scripting way to upload videos to Peertube and Youtube written in python3. ## Dependencies Search in your package manager, or with `pip` use ``pip install -r requirements.txt`` + - configparser + - docopt + - future + - google-api-python-client - google-auth - - google-auth-oauthlib - google-auth-httplib2 - - google-api-python-client - - docopt - - schema + - google-auth-oauthlib + - httplib2 + - oauthlib - python-magic - python-magic-bin + - requests + - requests-oauthlib - requests-toolbelt + - schema - tzlocal - - unidecode + - Unidecode + - uritemplate + - urllib3 ## Configuration @@ -39,14 +47,14 @@ Prismedia will try to use this file at each launch, and re-ask for authenticatio The default youtube_secret.json should allow you to upload some videos. If you plan an larger usage, please consider creating your own youtube_secret file: -- 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 -- 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. + - 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 + - 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. ## How To Support only mp4 for cross compatibility between Youtube and Peertube @@ -153,7 +161,7 @@ Languages: - [x] add videos to playlist - [x] create playlist - [x] schedule your video with publishAt - - [x] combine channel and playlist (Peertube only as channel is Peertube feature). See [issue 40](https://git.lecygnenoir.info/LecygneNoir/prismedia/issues/40 for detailed usage. + - [x] combine channel and playlist (Peertube only as channel is Peertube feature). See [issue 40](https://git.lecygnenoir.info/LecygneNoir/prismedia/issues/40) for detailed usage. - [x] Use a config file (NFO) file to retrieve videos arguments - [x] Allow to choose peertube or youtube upload (to resume failed upload for example) - [x] Usable on Desktop (Linux and/or Windows and/or MacOS) diff --git a/lib/utils.py b/lib/utils.py index 0a22383..fca5f51 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -132,7 +132,7 @@ def loadNFO(options): logging.info("Using " + options.get('--nfo') + " as NFO, loading...") if isfile(options.get('--nfo')): nfo = RawConfigParser() - nfo.read(options.get('--nfo')) + nfo.read(options.get('--nfo'), encoding='utf-8') return nfo else: logging.error("Given NFO file does not exist, please check your path.") @@ -147,7 +147,7 @@ def loadNFO(options): try: logging.info("Using " + nfo_file + " as NFO, loading...") nfo = RawConfigParser() - nfo.read(nfo_file) + nfo.read(nfo_file, encoding='utf-8') return nfo except Exception as e: logging.error("Problem with NFO file: " + str(e)) @@ -160,7 +160,7 @@ def loadNFO(options): try: logging.info("Using " + nfo_file + " as NFO, loading...") nfo = RawConfigParser() - nfo.read(nfo_file) + nfo.read(nfo_file, encoding='utf-8') return nfo except Exception as e: logging.error("Problem with nfo file: " + str(e)) @@ -196,17 +196,3 @@ def cleanString(toclean): cleaned = re.sub('[^A-Za-z0-9]+', '', toclean) return cleaned - -def decodeArgumentStrings(options, encoding): - # Python crash when decoding from UTF-8 to UTF-8, so we prevent this - if "utf-8" == encoding.lower(): - return; - - if options["--name"] is not None: - options["--name"] = options["--name"].decode(encoding) - - if options["--description"] is not None: - options["--description"] = options["--description"].decode(encoding) - - if options["--tags"] is not None: - options["--tags"] = options["--tags"].decode(encoding) diff --git a/prismedia_upload.py b/prismedia_upload.py index 93daa9f..9c6b96e 100755 --- a/prismedia_upload.py +++ b/prismedia_upload.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # coding: utf-8 """ @@ -13,6 +13,7 @@ Usage: Options: -f, --file=STRING Path to the video file to upload in mp4 --name=NAME Name of the video to upload. (default to video filename) + --debug Show some debug informations like the option actually used (default: no debug info) -d, --description=STRING Description of the video. (default: default description) -t, --tags=STRING Tags for the video. comma separated. WARN: tags with space and special characters (!, ', ", ?, ...) @@ -97,6 +98,9 @@ except ImportError: 'see https://github.com/ahupp/python-magic\n') exit(1) +if sys.version_info[0] < 3: + raise Exception("Python 3 or a more recent version is required.") + VERSION = "prismedia v0.7.1" VALID_PRIVACY_STATUSES = ('public', 'private', 'unlisted') @@ -107,7 +111,7 @@ VALID_CATEGORIES = ( "how to", "education", "activism", "science & technology", "science", "technology", "animals" ) -VALID_PLATFORM = ('youtube', 'peertube') +VALID_PLATFORM = ('youtube', 'peertube', 'none') VALID_LANGUAGES = ('arabic', 'english', 'french', 'german', 'hindi', 'italian', 'japanese', 'korean', 'mandarin', @@ -206,6 +210,7 @@ if __name__ == '__main__': validatePublish, error="DATE should be the form YYYY-MM-DDThh:mm:ss and has to be in the future") ), + Optional('--debug'): bool, Optional('--cca'): bool, Optional('--disable-comments'): bool, Optional('--nsfw'): bool, @@ -220,7 +225,6 @@ if __name__ == '__main__': '--version': bool }) - utils.decodeArgumentStrings(options, locale.getpreferredencoding()) options = utils.parseNFO(options) if not options.get('--thumbnail'): @@ -231,7 +235,11 @@ if __name__ == '__main__': except SchemaError as e: exit(e) - if options.get('--platform') is None or "youtube" in options.get('--platform'): - yt_upload.run(options) - if options.get('--platform') is None or "peertube" in options.get('--platform'): - pt_upload.run(options) + if options.get('--debug'): + print(sys.version) + print(options) + + #if options.get('--platform') is None or "peertube" in options.get('--platform'): + # pt_upload.run(options) + #if options.get('--platform') is None or "youtube" in options.get('--platform'): + # yt_upload.run(options) diff --git a/requirements.txt b/requirements.txt index 65b335e..e645e88 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,6 +8,7 @@ google-auth-oauthlib httplib2 oauthlib python-magic +python-magic-bin requests requests-oauthlib requests-toolbelt