Browse Source

Change the originalDate behaviour to not default, and add option to auto manage the original date if needed

progress-youtube
LecygneNoir 3 years ago
parent
commit
736582b495
3 changed files with 17 additions and 11 deletions
  1. +1
    -1
      prismedia/pt_upload.py
  2. +13
    -9
      prismedia/upload.py
  3. +3
    -1
      prismedia/yt_upload.py

+ 1
- 1
prismedia/pt_upload.py View File

@ -270,7 +270,7 @@ def upload_video(oauth, secret, options):
fields.append(("privacy", str(PEERTUBE_PRIVACY[privacy or "private"])))
# Set originalDate except if the user force no originalDate
if not options.get('--no-originalDate'):
if options.get('--originalDate'):
originalDate = convert_peertube_date(options.get('--originalDate'))
fields.append(("originallyPublishedAt", originalDate))

+ 13
- 9
prismedia/upload.py View File

@ -37,8 +37,7 @@ Options:
--originalDate=DATE Configure the video as initially recorded at DATE
DATE should be on the form YYYY-MM-DDThh:mm:ss eg: 2018-03-12T19:00:00
DATE should be in the past
Default use the last modification date of the file.
--no-originalDate Do not set the initial record field when uploading
--auto-originalDate Automatically use the file modification time as original date
--thumbnail=STRING Path to a file to use as a thumbnail for the video.
Supported types are jpg and jpeg.
By default, prismedia search for an image based on video name followed by .jpg or .jpeg
@ -76,6 +75,7 @@ Strict options:
--withTags Prevent the upload without tags
--withPlaylist Prevent the upload if no playlist
--withPublishAt Prevent the upload if no schedule
--withOriginalDate Prevent the upload if no original date configured
--withPlatform Prevent the upload if at least one platform is not specified
--withCategory Prevent the upload if no category
--withLanguage Prevent upload if no language
@ -208,7 +208,7 @@ def validatePublishDate(publishDate):
def validateOriginalDate(originalDate):
# Check date format and if date is future
# Check date format and if date is past
try:
now = datetime.datetime.now()
originalDate = datetime.datetime.strptime(originalDate, '%Y-%m-%dT%H:%M:%S')
@ -234,6 +234,7 @@ def validateLogLevel(loglevel):
return False
return True
def _optionnalOrStrict(key, scope, error):
option = key.replace('-', '')
option = option[0].upper() + option[1:]
@ -297,6 +298,7 @@ def main():
Optional('--withTags', default=False): bool,
Optional('--withPlaylist', default=False): bool,
Optional('--withPublishAt', default=False): bool,
Optional('--withOriginalDate', default=False): bool,
Optional('--withPlatform', default=False): bool,
Optional('--withCategory', default=False): bool,
Optional('--withLanguage', default=False): bool,
@ -315,6 +317,7 @@ def main():
Hook('--language', handler=_optionnalOrStrict): object,
Hook('--platform', handler=_optionnalOrStrict): object,
Hook('--publishAt', handler=_optionnalOrStrict): object,
Hook('--originalDate', handler=_optionnalOrStrict): object,
Hook('--thumbnail', handler=_optionnalOrStrict): object,
Hook('--channel', handler=_optionnalOrStrict): object,
Hook('--playlist', handler=_optionnalOrStrict): object,
@ -371,7 +374,7 @@ def main():
validateOriginalDate,
error="Original date should be the form YYYY-MM-DDThh:mm:ss and has to be in the past")
),
Optional('--no-originalDate'): bool,
Optional('--auto-originalDate'): bool,
Optional('--cca'): bool,
Optional('--disable-comments'): bool,
Optional('--nsfw'): bool,
@ -400,6 +403,12 @@ def main():
options = utils.parseNFO(options)
# If after loading NFO we still has no original date and --auto-originalDate is enabled,
# then we need to search from the file
# We need to do that before the strict validation in case --withOriginalDate is enabled
if not options.get('--originalDate') and options.get('--auto-originalDate'):
options['--originalDate'] = utils.searchOriginalDate(options)
# Once NFO are loaded, we need to revalidate strict options in case some were in NFO
try:
options = earlyoptionSchema.validate(options)
@ -410,11 +419,6 @@ def main():
if not options.get('--thumbnail'):
options = utils.searchThumbnail(options)
# If after loading NFO we still has no original date and --no-originalDate is not enabled,
# then we need to search from the file
if not options.get('--originalDate') and not options.get('--no-originalDate'):
options['--originalDate'] = utils.searchOriginalDate(options)
try:
options = schema.validate(options)
except SchemaError as e:

+ 3
- 1
prismedia/yt_upload.py View File

@ -116,6 +116,8 @@ def initialize_upload(youtube, options):
if options.get('--cca'):
license = "creativeCommon"
# We set recordingDetails empty because it's easier to add options if it already exists
# and if empty, it does not cause problem during upload
body = {
"snippet": {
"title": options.get('--name') or splitext(basename(path))[0],
@ -146,7 +148,7 @@ def initialize_upload(youtube, options):
body['status']['publishAt'] = str(publishAt)
# Set originalDate except if the user force no originalDate
if not options.get('--no-originalDate'):
if options.get('--originalDate'):
originalDate = convert_youtube_date(options.get('--originalDate'))
body['recordingDetails']['recordingDate'] = str(originalDate)

Loading…
Cancel
Save