diff --git a/README.md b/README.md index 5727c4a..762bab7 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,7 @@ Options: See nfo_example.txt for more details --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) -h --help Show this help. --version Show version. @@ -106,6 +107,12 @@ Categories: comedy, entertainment, news, how to, education, activism, science & technology, science, technology, animals + +Languages: + Language of the video (audio track), choose one. Default is English + Here are available languages from Peertube and Youtube: + Arabic, English, French, German, Hindi, Italian, + Japanese, Korean, Mandarin, Portuguese, Punjabi, Russian, Spanish ``` ## Features @@ -120,7 +127,7 @@ Categories: - [x] privacy (between public, unlisted or private) - [x] enabling/disabling comment (Peertube only as Youtube API does not support it) - [x] nsfw (Peertube only as Youtube API does not support it) - - [ ] set default language + - [x] set default language - ~~thumbnail/preview~~ Canceled, waiting for Youtube's API support - [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) diff --git a/lib/pt_upload.py b/lib/pt_upload.py index 05e22da..669be5d 100644 --- a/lib/pt_upload.py +++ b/lib/pt_upload.py @@ -83,6 +83,12 @@ def upload_video(oauth, secret, options): # if no category, set default to 2 (Films) fields.append(("category", "2")) + if options.get('--language'): + fields.append(("language", str(utils.getLanguage(options.get('--language'), "peertube")))) + else: + # if no language, set default to 1 (English) + fields.append(("language", "1")) + if options.get('--privacy'): fields.append(("privacy", str(PEERTUBE_PRIVACY[options.get('--privacy').lower()]))) else: diff --git a/lib/utils.py b/lib/utils.py index 54c4b06..63c1f58 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -45,7 +45,38 @@ PEERTUBE_CATEGORY = { "animals": 16 } +### LANGUAGES ### +YOUTUBE_LANGUAGE = { + "arabic": 'ar', + "english": 'en', + "french": 'fr', + "german": 'de', + "hindi": 'hi', + "italian": 'it', + "japanese": 'ja', + "korean": 'ko', + "mandarin": 'zh-CN', + "portuguese": 'pt-PT', + "punjabi": 'pa', + "russian": 'ru', + "spanish": 'es' +} +PEERTUBE_LANGUAGE = { + "arabic": 5, + "english": 1, + "french": 13, + "german": 11, + "hindi": 4, + "italian": 14, + "japanese": 9, + "korean": 12, + "mandarin": 3, + "portuguese": 6, + "punjabi": 10, + "russian": 8, + "spanish": 2 +} ###################### @@ -56,6 +87,13 @@ def getCategory(category, platform): return PEERTUBE_CATEGORY[category.lower()] +def getLanguage(language, platform): + if platform == "youtube": + return YOUTUBE_LANGUAGE[language.lower()] + else: + return PEERTUBE_LANGUAGE[language.lower()] + + # return the nfo as a RawConfigParser object def loadNFO(options): video_directory = dirname(options.get('--file')) + "/" diff --git a/lib/yt_upload.py b/lib/yt_upload.py index 495c17b..23234a7 100644 --- a/lib/yt_upload.py +++ b/lib/yt_upload.py @@ -81,6 +81,10 @@ def initialize_upload(youtube, options): if options.get('--category'): category = utils.getCategory(options.get('--category'), 'youtube') + language = None + if options.get('--language'): + language = utils.getLanguage(options.get('--language'), "youtube") + license = None if options.get('--cca'): license = "creativeCommon" @@ -92,6 +96,7 @@ def initialize_upload(youtube, options): "tags": tags, # if no category, set default to 1 (Films) "categoryId": str(category or 1), + "defaultAudioLanguage": str(language or 'en') }, "status": { "privacyStatus": str(options.get('--privacy') or "private"), diff --git a/nfo_example.txt b/nfo_example.txt index d2edce5..5ee2f8d 100644 --- a/nfo_example.txt +++ b/nfo_example.txt @@ -14,4 +14,5 @@ cca = True privacy = private disable-comments = True nsfw = True -platform = youtub \ No newline at end of file +platform = youtube, peertube +language = French \ No newline at end of file diff --git a/prismedia_upload.py b/prismedia_upload.py index d0359d9..e606fb8 100755 --- a/prismedia_upload.py +++ b/prismedia_upload.py @@ -23,6 +23,7 @@ Options: See nfo_example.txt for more details --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) -h --help Show this help. --version Show version. @@ -34,6 +35,13 @@ Categories: comedy, entertainment, news, how to, education, activism, science & technology, science, technology, animals + +Languages: + Language of the video (audio track), choose one. Default is English + Here are available languages from Peertube and Youtube: + Arabic, English, French, German, Hindi, Italian, + Japanese, Korean, Mandarin, Portuguese, Punjabi, Russian, Spanish + """ from os.path import dirname, realpath import sys @@ -64,6 +72,7 @@ except ImportError: 'see https://github.com/ahupp/python-magic\n') VERSION = "prismedia v0.3" + VALID_PRIVACY_STATUSES = ('public', 'private', 'unlisted') VALID_CATEGORIES = ( "music", "films", "vehicles", @@ -73,6 +82,10 @@ VALID_CATEGORIES = ( "science", "technology", "animals" ) VALID_PLATFORM = ('youtube', 'peertube') +VALID_LANGUAGES = ('arabic', 'english', 'french', + 'german', 'hindi', 'italian', + 'japanese', 'korean', 'mandarin', + 'portuguese', 'punjabi', 'russian', 'spanish') def validateVideo(path): @@ -99,12 +112,19 @@ def validatePrivacy(privacy): def validatePlatform(platform): for plfrm in platform.split(','): - if plfrm not in VALID_PLATFORM: + if plfrm.lower().replace(" ", "") not in VALID_PLATFORM: return False return True +def validateLanguage(language): + if language.lower() in VALID_LANGUAGES: + return True + else: + return False + + if __name__ == '__main__': options = docopt(__doc__, version=VERSION) @@ -131,6 +151,11 @@ if __name__ == '__main__': validateCategory, error="Category not recognized, please see --help") ), + Optional('--language'): Or(None, And( + str, + validateLanguage, + error="Language not recognized, please see --help") + ), Optional('--privacy'): Or(None, And( str, validatePrivacy,