Browse Source

Add options to choose audio language for the video (default is English)

develop
LecygneNoir 6 years ago
parent
commit
f3e0369710
6 changed files with 85 additions and 3 deletions
  1. +8
    -1
      README.md
  2. +6
    -0
      lib/pt_upload.py
  3. +38
    -0
      lib/utils.py
  4. +5
    -0
      lib/yt_upload.py
  5. +2
    -1
      nfo_example.txt
  6. +26
    -1
      prismedia_upload.py

+ 8
- 1
README.md View File

@ -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)

+ 6
- 0
lib/pt_upload.py View File

@ -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:

+ 38
- 0
lib/utils.py View File

@ -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')) + "/"

+ 5
- 0
lib/yt_upload.py View File

@ -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"),

+ 2
- 1
nfo_example.txt View File

@ -14,4 +14,5 @@ cca = True
privacy = private
disable-comments = True
nsfw = True
platform = youtub
platform = youtube, peertube
language = French

+ 26
- 1
prismedia_upload.py View File

@ -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,

Loading…
Cancel
Save