From 736582b495db2ec90ee4b9966fa43dd41eef88af Mon Sep 17 00:00:00 2001 From: LecygneNoir Date: Fri, 4 Dec 2020 09:52:46 +0100 Subject: [PATCH] Change the originalDate behaviour to not default, and add option to auto manage the original date if needed --- prismedia/pt_upload.py | 2 +- prismedia/upload.py | 22 +++++++++++++--------- prismedia/yt_upload.py | 4 +++- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/prismedia/pt_upload.py b/prismedia/pt_upload.py index 23c1453..7c779ad 100644 --- a/prismedia/pt_upload.py +++ b/prismedia/pt_upload.py @@ -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)) diff --git a/prismedia/upload.py b/prismedia/upload.py index 77ad873..ea907ee 100755 --- a/prismedia/upload.py +++ b/prismedia/upload.py @@ -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: diff --git a/prismedia/yt_upload.py b/prismedia/yt_upload.py index 1ffc2a5..22db640 100644 --- a/prismedia/yt_upload.py +++ b/prismedia/yt_upload.py @@ -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)