@ -66,7 +66,7 @@ class InputfileAction(argparse.Action):
class MtimeAction ( argparse . Action ) :
class MtimeAction ( argparse . Action ) :
""" Configure mtime post processor """
""" Configure mtime post processor s """
def __call__ ( self , parser , namespace , value , option_string = None ) :
def __call__ ( self , parser , namespace , value , option_string = None ) :
namespace . postprocessors . append ( {
namespace . postprocessors . append ( {
" name " : " mtime " ,
" name " : " mtime " ,
@ -74,6 +74,64 @@ class MtimeAction(argparse.Action):
} )
} )
class UgoiraAction ( argparse . Action ) :
""" Configure ugoira post processors """
def __call__ ( self , parser , namespace , value , option_string = None ) :
if self . const :
value = self . const
else :
value = value . strip ( ) . lower ( )
if value in ( " webm " , " vp9 " ) :
pp = {
" extension " : " webm " ,
" ffmpeg-args " : ( " -c:v " , " libvpx-vp9 " ,
" -crf " , " 12 " ,
" -b:v " , " 0 " , " -an " ) ,
}
elif value == " vp9-lossless " :
pp = {
" extension " : " webm " ,
" ffmpeg-args " : ( " -c:v " , " libvpx-vp9 " ,
" -lossless " , " 1 " ,
" -pix_fmt " , " yuv420p " , " -an " ) ,
}
elif value == " vp8 " :
pp = {
" extension " : " webm " ,
" ffmpeg-args " : ( " -c:v " , " libvpx " ,
" -crf " , " 4 " ,
" -b:v " , " 5000k " , " -an " ) ,
}
elif value == " mp4 " :
pp = {
" extension " : " mp4 " ,
" ffmpeg-args " : ( " -c:v " , " libx264 " , " -an " , " -b:v " , " 5M " ) ,
" libx264-prevent-odd " : True ,
}
elif value == " gif " :
pp = {
" extension " : " gif " ,
" ffmpeg-args " : ( " -filter_complex " , " [0:v] split [a][b]; "
" [a] palettegen [p];[b][p] paletteuse " ) ,
" repeat-last-frame " : False ,
}
elif value in ( " mkv " , " copy " ) :
pp = {
" extension " : " mkv " ,
" ffmpeg-args " : ( " -c:v " , " copy " ) ,
" repeat-last-frame " : False ,
}
else :
parser . error ( " Unsupported Ugoira format ' {} ' " . format ( value ) )
pp [ " name " ] = " ugoira "
pp [ " whitelist " ] = ( " pixiv " , " danbooru " )
namespace . options . append ( ( ( ) , " ugoira " , True ) )
namespace . postprocessors . append ( pp )
class Formatter ( argparse . HelpFormatter ) :
class Formatter ( argparse . HelpFormatter ) :
""" Custom HelpFormatter class to customize help output """
""" Custom HelpFormatter class to customize help output """
def __init__ ( self , prog ) :
def __init__ ( self , prog ) :
@ -487,38 +545,28 @@ def build_parser():
} ,
} ,
help = " Store downloaded files in a CBZ archive " ,
help = " Store downloaded files in a CBZ archive " ,
)
)
postprocessor . add_argument (
" --ugoira " ,
dest = " postprocessors " , metavar = " FORMAT " , action = UgoiraAction ,
help = ( " Convert Pixiv Ugoira to FORMAT using FFmpeg. "
" Supported formats are ' webm ' , ' mp4 ' , ' gif ' , "
" ' vp8 ' , ' vp9 ' , ' vp9-lossless ' , ' copy ' . " ) ,
)
postprocessor . add_argument (
postprocessor . add_argument (
" --ugoira-conv " ,
" --ugoira-conv " ,
dest = " postprocessors " , action = " append_const " , const = {
dest = " postprocessors " , nargs = 0 , action = UgoiraAction , const = " vp8 " ,
" name " : " ugoira " ,
help = argparse . SUPPRESS ,
" ffmpeg-args " : ( " -c:v " , " libvpx " , " -crf " , " 4 " , " -b:v " , " 5000k " ) ,
" ffmpeg-twopass " : True ,
" whitelist " : ( " pixiv " , " danbooru " ) ,
} ,
help = " Convert Pixiv Ugoira to WebM (requires FFmpeg) " ,
)
)
postprocessor . add_argument (
postprocessor . add_argument (
" --ugoira-conv-lossless " ,
" --ugoira-conv-lossless " ,
dest = " postprocessors " , action = " append_const " , const = {
dest = " postprocessors " , nargs = 0 , action = UgoiraAction ,
" name " : " ugoira " ,
const = " vp9-lossless " ,
" ffmpeg-args " : ( " -c:v " , " libvpx-vp9 " , " -lossless " , " 1 " ,
help = argparse . SUPPRESS ,
" -pix_fmt " , " yuv420p " ) ,
" ffmpeg-twopass " : False ,
" whitelist " : ( " pixiv " , " danbooru " ) ,
} ,
help = " Convert Pixiv Ugoira to WebM in VP9 lossless mode " ,
)
)
postprocessor . add_argument (
postprocessor . add_argument (
" --ugoira-conv-copy " ,
" --ugoira-conv-copy " ,
dest = " postprocessors " , action = " append_const " , const = {
dest = " postprocessors " , nargs = 0 , action = UgoiraAction , const = " copy " ,
" name " : " ugoira " ,
help = argparse . SUPPRESS ,
" extension " : " mkv " ,
" ffmpeg-args " : ( " -c:v " , " copy " ) ,
" ffmpeg-twopass " : False ,
" repeat-last-frame " : False ,
" whitelist " : ( " pixiv " , " danbooru " ) ,
} ,
help = " Convert Pixiv Ugoira to MKV without re-encoding any frames " ,
)
)
postprocessor . add_argument (
postprocessor . add_argument (
" --write-metadata " ,
" --write-metadata " ,