mirror of
https://git.lecygnenoir.info/LecygneNoir/prismedia.git
synced 2025-10-05 18:24:19 +02:00
Add options and bunch of functions to maange the originalDate fields in prismedia, cf #50
This commit is contained in:
parent
9b597f461e
commit
447310a17e
2 changed files with 43 additions and 11 deletions
|
@ -34,6 +34,11 @@ Options:
|
|||
DATE should be in the future
|
||||
--peertubeAt=DATE
|
||||
--youtubeAt=DATE Override publishAt for the corresponding platform. Allow to create preview on specific platform
|
||||
--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
|
||||
--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
|
||||
|
@ -190,11 +195,11 @@ def validateLanguage(language):
|
|||
return False
|
||||
|
||||
|
||||
def validatePublish(publish):
|
||||
def validatePublishDate(publishDate):
|
||||
# Check date format and if date is future
|
||||
try:
|
||||
now = datetime.datetime.now()
|
||||
publishAt = datetime.datetime.strptime(publish, '%Y-%m-%dT%H:%M:%S')
|
||||
publishAt = datetime.datetime.strptime(publishDate, '%Y-%m-%dT%H:%M:%S')
|
||||
if now >= publishAt:
|
||||
return False
|
||||
except ValueError:
|
||||
|
@ -202,6 +207,18 @@ def validatePublish(publish):
|
|||
return True
|
||||
|
||||
|
||||
def validateOriginalDate(originalDate):
|
||||
# Check date format and if date is future
|
||||
try:
|
||||
now = datetime.datetime.now()
|
||||
originalDate = datetime.datetime.strptime(originalDate, '%Y-%m-%dT%H:%M:%S')
|
||||
if now <= originalDate:
|
||||
return False
|
||||
except ValueError:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def validateThumbnail(thumbnail):
|
||||
supported_types = ['image/jpg', 'image/jpeg']
|
||||
if os.path.exists(thumbnail) and \
|
||||
|
@ -336,19 +353,25 @@ def main():
|
|||
Optional('--platform'): Or(None, And(str, validatePlatform, error="Sorry, upload platform not supported")),
|
||||
Optional('--publishAt'): Or(None, And(
|
||||
str,
|
||||
validatePublish,
|
||||
error="DATE should be the form YYYY-MM-DDThh:mm:ss and has to be in the future")
|
||||
validatePublishDate,
|
||||
error="Publish Date should be the form YYYY-MM-DDThh:mm:ss and has to be in the future")
|
||||
),
|
||||
Optional('--peertubeAt'): Or(None, And(
|
||||
str,
|
||||
validatePublish,
|
||||
error="DATE should be the form YYYY-MM-DDThh:mm:ss and has to be in the future")
|
||||
validatePublishDate,
|
||||
error="Publish Date should be the form YYYY-MM-DDThh:mm:ss and has to be in the future")
|
||||
),
|
||||
Optional('--youtubeAt'): Or(None, And(
|
||||
str,
|
||||
validatePublish,
|
||||
error="DATE should be the form YYYY-MM-DDThh:mm:ss and has to be in the future")
|
||||
validatePublishDate,
|
||||
error="Publish Date should be the form YYYY-MM-DDThh:mm:ss and has to be in the future")
|
||||
),
|
||||
Optional('--originalDate'): Or(None, And(
|
||||
str,
|
||||
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('--cca'): bool,
|
||||
Optional('--disable-comments'): bool,
|
||||
Optional('--nsfw'): bool,
|
||||
|
@ -387,6 +410,11 @@ 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:
|
||||
|
|
|
@ -2,12 +2,11 @@
|
|||
# coding: utf-8
|
||||
|
||||
from configparser import RawConfigParser, NoOptionError, NoSectionError
|
||||
from os.path import dirname, splitext, basename, isfile
|
||||
from os.path import dirname, splitext, basename, isfile, getmtime
|
||||
import re
|
||||
from os import devnull
|
||||
from subprocess import check_call, CalledProcessError, STDOUT
|
||||
import unidecode
|
||||
import logging
|
||||
import datetime
|
||||
|
||||
logger = logging.getLogger('Prismedia')
|
||||
|
||||
|
@ -135,6 +134,11 @@ def searchThumbnail(options):
|
|||
return options
|
||||
|
||||
|
||||
def searchOriginalDate(options):
|
||||
fileModificationDate = getmtime(options.get('--file'))
|
||||
return datetime.datetime.fromtimestamp(fileModificationDate).isoformat()
|
||||
|
||||
|
||||
# return the nfo as a RawConfigParser object
|
||||
def loadNFO(filename):
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue