Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

One operation for renaming and file move & fixe for episodes without seasons #83

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions tvnamer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def wrap_validfname(fname):
'seriesname': wrap_validfname(episode.seriesname),
'episodenumbers': wrap_validfname(formatEpisodeNumbers(episode.episodenumbers)),
'originalfilename': episode.originalfilename,
'seasonnumber': 0,
}
else:
destdir = Config['move_files_destination'] % {
Expand All @@ -94,7 +95,7 @@ def doRenameFile(cnamer, newName):
warn(e)


def doMoveFile(cnamer, destDir = None, destFilepath = None, getPathPreview = False):
def doMoveFile(cnamer, destDir = None, destFilepath = None, getPathPreview = False, newName = None):
"""Moves file to destDir, or to destFilepath
"""

Expand All @@ -108,13 +109,21 @@ def doMoveFile(cnamer, destDir = None, destFilepath = None, getPathPreview = Fal
raise ValueError("Config value for move_files_destination cannot be None if move_files_enabled is True")

try:
return cnamer.newPath(
new_path = destDir,
new_fullpath = destFilepath,
always_move = Config['always_move'],
leave_symlink = Config['leave_symlink'],
getPathPreview = getPathPreview,
force = Config['overwrite_destination_on_move'])
if (newName is None):
return cnamer.newPath(
new_path = destDir,
new_fullpath = destFilepath,
always_move = Config['always_move'],
leave_symlink = Config['leave_symlink'],
getPathPreview = getPathPreview,
force = Config['overwrite_destination_on_move'])
else:
return cnamer.newPath(
new_fullpath = destDir + os.sep + newName,
always_move = Config['always_move'],
leave_symlink = Config['leave_symlink'],
getPathPreview = getPathPreview,
force = Config['overwrite_destination_on_move'])

except OSError, e:
warn(e)
Expand Down Expand Up @@ -212,12 +221,14 @@ def processFile(tvdb_instance, episode):
p("New filename: %s" % newName)

if Config['always_rename']:
doRenameFile(cnamer, newName)
if Config['move_files_enable']:
if Config['move_files_destination_is_filepath']:
doRenameFile(cnamer, newName) # TODO: understand this option
doMoveFile(cnamer = cnamer, destFilepath = getMoveDestination(episode))
else:
doMoveFile(cnamer = cnamer, destDir = getMoveDestination(episode))
doMoveFile(cnamer = cnamer, destDir = getMoveDestination(episode) , newName = newName)
else:
doRenameFile(cnamer, newName)
return

ans = confirm("Rename?", options = ['y', 'n', 'a', 'q'], default = 'y')
Expand Down Expand Up @@ -245,7 +256,7 @@ def processFile(tvdb_instance, episode):
if Config['move_files_destination_is_filepath']:
doMoveFile(cnamer = cnamer, destFilepath = newPath, getPathPreview = True)
else:
doMoveFile(cnamer = cnamer, destDir = newPath, getPathPreview = True)
doMoveFile(cnamer = cnamer, destDir = newPath, getPathPreview = True, newName = newName )

if not Config['batch'] and Config['move_files_confirmation']:
ans = confirm("Move file?", options = ['y', 'n', 'q'], default = 'y')
Expand Down