mirror of
https://github.com/spaam/svtplay-dl.git
synced 2024-11-27 21:54:17 +01:00
Option to automatically create a subfolder for tvshows, named as the show title. When not a series will use a subfolder titled movies.
This commit is contained in:
parent
bf0e38a6f9
commit
184f79a377
@ -57,7 +57,7 @@ def get_media(url, options, version="Unknown"):
|
||||
|
||||
|
||||
def get_all_episodes(stream, url):
|
||||
name = os.path.dirname(formatname(dict(), stream.config))
|
||||
name = os.path.dirname(formatname({"basedir": True}, stream.config))
|
||||
|
||||
if name and os.path.isfile(name):
|
||||
log.error("Output must be a directory if used with --all-episodes")
|
||||
|
@ -130,6 +130,19 @@ def filename(stream):
|
||||
|
||||
def formatname(output, config, extension="mp4"):
|
||||
name = _formatname(output, config, extension)
|
||||
if not output.get("basedir", False):
|
||||
# If tvshow have not been derived by service do it by if season and episode is set
|
||||
if output.get("tvshow", None) is None:
|
||||
tvshow = (output.get("season", None) is not None and
|
||||
output.get("episode", None) is not None)
|
||||
else:
|
||||
tvshow = output.get("tvshow", False)
|
||||
if config.get("subfolder") and "title" in output and tvshow:
|
||||
# Add subfolder with name title
|
||||
name = os.path.join(output["title"], name)
|
||||
elif config.get("subfolder") and not tvshow:
|
||||
# Add subfolder with name movies
|
||||
name = os.path.join("movies", name)
|
||||
if config.get("output") and os.path.isdir(os.path.expanduser(config.get("output"))):
|
||||
name = os.path.join(config.get("output"), name)
|
||||
elif config.get("path") and os.path.isdir(os.path.expanduser(config.get("path"))):
|
||||
@ -180,6 +193,10 @@ def output(output, config, extension="mp4", mode="wb", **kwargs):
|
||||
if os.path.isfile(name) and not config.get("force"):
|
||||
logging.warning("File ({}) already exists. Use --force to overwrite".format(name))
|
||||
return None
|
||||
dir = os.path.dirname(os.path.realpath(name))
|
||||
if not os.path.isdir(dir):
|
||||
# Create directory, needed for creating tvshow subfolder
|
||||
os.makedirs(dir)
|
||||
if findexpisode(output, os.path.dirname(os.path.realpath(name)), os.path.basename(name)):
|
||||
if extension in subtitlefiles:
|
||||
if not config.get("force_subtitle"):
|
||||
|
@ -58,6 +58,8 @@ def parser(version):
|
||||
|
||||
general.add_argument('--version', action='version', version='%(prog)s {0}'.format(version))
|
||||
general.add_argument("-o", "--output", metavar="output", default=None, help="outputs to the given filename or folder")
|
||||
general.add_argument("--subfolder", action="store_true", default=False,
|
||||
help="Create a subfolder titled as the show, non-series gets in folder movies")
|
||||
general.add_argument("--config", dest="configfile", metavar="configfile", default=CONFIGFILE, help="Specify configuration file")
|
||||
general.add_argument("-f", "--force", action="store_true", dest="force", default=False,
|
||||
help="overwrite if file exists already")
|
||||
@ -144,6 +146,7 @@ def parser(version):
|
||||
def setup_defaults():
|
||||
options = Options()
|
||||
options.set("output", None)
|
||||
options.set("subfolder", False)
|
||||
options.set("configfile", CONFIGFILE)
|
||||
options.set("resume", False)
|
||||
options.set("live", False)
|
||||
@ -187,6 +190,7 @@ def setup_defaults():
|
||||
|
||||
def parsertoconfig(config, parser):
|
||||
config.set("output", parser.output)
|
||||
config.set("subfolder", parser.subfolder)
|
||||
config.set("configfile", parser.configfile)
|
||||
config.set("resume", parser.resume)
|
||||
config.set("live", parser.live)
|
||||
|
Loading…
Reference in New Issue
Block a user