Permalink
Browse files

Merge pull request #475 from itofzo/fix_rename_multi_episodes_dev

Fix rename multi episodes dev
  • Loading branch information...
2 parents 8843793 + 266dbaa commit 6374529e90b9dfc6ad191fc2ef7be7b683be6249 @midgetspy midgetspy committed Sep 14, 2012
Showing with 58 additions and 22 deletions.
  1. +1 −1 data/interfaces/default/testRename.tmpl
  2. +1 −1 sickbeard/__init__.py
  3. +10 −10 sickbeard/helpers.py
  4. +13 −3 sickbeard/show_queue.py
  5. +26 −5 sickbeard/tv.py
  6. +7 −2 sickbeard/webserve.py
@@ -15,7 +15,7 @@
<h3>Preview of the proposed name changes</h3>
<blockquote style="margin-bottom: 0; color: #3A87AD;">
-#if int($show.air_by_date) == 1 & $sickbeard.NAMING_CUSTOM_ABD:
+#if int($show.air_by_date) == 1 and $sickbeard.NAMING_CUSTOM_ABD:
$sickbeard.NAMING_ABD_PATTERN
#else
$sickbeard.NAMING_PATTERN
@@ -953,7 +953,7 @@ def save_config():
new_config['General']['naming_pattern'] = NAMING_PATTERN
new_config['General']['naming_custom_abd'] = int(NAMING_CUSTOM_ABD)
new_config['General']['naming_abd_pattern'] = NAMING_ABD_PATTERN
- new_config['General']['naming_multi_ep_type'] = int(NAMING_MULTI_EP)
+ new_config['General']['naming_multi_ep'] = int(NAMING_MULTI_EP)
new_config['General']['launch_browser'] = int(LAUNCH_BROWSER)
new_config['General']['use_banner'] = int(USE_BANNER)
View
@@ -469,37 +469,37 @@ def make_dirs(path):
return True
+
def rename_ep_file(cur_path, new_path):
"""
Creates all folders needed to move a file to its new location, renames it, then cleans up any folders
left that are now empty.
-
+
cur_path: The absolute path to the file you want to move/rename
new_path: The absolute path to the destination for the file WITHOUT THE EXTENSION
"""
-
- logger.log(u"Renaming file from "+cur_path+" to "+new_path)
-
+
new_dest_dir, new_dest_name = os.path.split(new_path) #@UnusedVariable
cur_file_name, cur_file_ext = os.path.splitext(cur_path) #@UnusedVariable
-
+
# put the extension on the incoming file
new_path += cur_file_ext
-
+
make_dirs(os.path.dirname(new_path))
-
+
# move the file
try:
+ logger.log(u"Renaming file from " + cur_path + " to " + new_path)
ek.ek(os.rename, cur_path, new_path)
except (OSError, IOError), e:
logger.log(u"Failed renaming " + cur_path + " to " + new_path + ": " + ex(e), logger.ERROR)
return False
-
+
# clean up any old folders that are empty
delete_empty_folders(ek.ek(os.path.dirname, cur_path))
-
+
return True
-
+
def delete_empty_folders(check_empty_dir):
"""
@@ -353,11 +353,21 @@ def execute(self):
logger.log(u"Can't perform rename on " + self.show.name + " when the show dir is missing.", logger.WARNING)
return
- ep_obj_list = self.show.getAllEpisodes()
+ ep_obj_rename_list = []
+
+ ep_obj_list = self.show.getAllEpisodes(has_location=True)
for cur_ep_obj in ep_obj_list:
- # Only want to rename if we have a location
+ # Only want to rename if we have a location
if cur_ep_obj.location:
- cur_ep_obj.rename()
+ if cur_ep_obj.relatedEps:
+ for cur_related_ep in cur_ep_obj.relatedEps:
+ if cur_related_ep not in ep_obj_rename_list:
+ ep_obj_rename_list.append(cur_ep_obj)
+ else:
+ ep_obj_rename_list.append(cur_ep_obj)
+
+ for cur_ep_obj in ep_obj_rename_list:
+ cur_ep_obj.rename()
self.inProgress = False
View
@@ -116,18 +116,39 @@ def flushEpisodes(self):
self.episodes[curSeason][curEp] = None
del myEp
- def getAllEpisodes(self, season=None):
+ def getAllEpisodes(self, season=None, has_location=False):
myDB = db.DBConnection()
- if season == None:
- results = myDB.select("SELECT season, episode FROM tv_episodes WHERE showid = ? ORDER BY season DESC, episode DESC", [self.tvdbid])
- else:
- results = myDB.select("SELECT season, episode FROM tv_episodes WHERE showid = ? AND season = ? ORDER BY season DESC, episode DESC", [self.tvdbid, season])
+
+ sql_selection = "SELECT season, episode, "
+
+ # subselection to detect multi-episodes early, share_location > 0
+ sql_selection = sql_selection + " (SELECT COUNT (*) FROM tv_episodes WHERE showid = tve.showid AND season = tve.season AND location != '' AND location = tve.location AND episode != tve.episode) AS share_location "
+
+ sql_selection = sql_selection + " FROM tv_episodes tve WHERE showid = " + str(self.tvdbid)
+
+ if season is not None:
+ sql_selection = sql_selection + " AND season = " + str(season)
+ if has_location:
+ sql_selection = sql_selection + " AND location != '' "
+
+ # need ORDER episode ASC to rename multi-episodes in order S01E01-02
+ sql_selection = sql_selection + " ORDER BY season ASC, episode ASC"
+
+ results = myDB.select(sql_selection)
ep_list = []
for cur_result in results:
cur_ep = self.getEpisode(int(cur_result["season"]), int(cur_result["episode"]))
if cur_ep:
+ if cur_ep.location:
+ # if there is a location, check if it's a multi-episode (share_location > 0) and put them in relatedEps
+ if cur_result["share_location"] > 0:
+ related_eps_result = myDB.select("SELECT * FROM tv_episodes WHERE showid = ? AND season = ? AND location = ? AND episode != ? ORDER BY episode ASC", [self.tvdbid, cur_ep.season, cur_ep.location, cur_ep.episode])
+ for cur_related_ep in related_eps_result:
+ related_ep = self.getEpisode(int(cur_related_ep["season"]), int(cur_related_ep["episode"]))
+ if related_ep not in cur_ep.relatedEps:
+ cur_ep.relatedEps.append(related_ep)
ep_list.append(cur_ep)
return ep_list
@@ -2567,12 +2567,17 @@ def testRename(self, show=None):
ep_obj_rename_list = []
- ep_obj_list = showObj.getAllEpisodes()
+ ep_obj_list = showObj.getAllEpisodes(has_location=True)
for cur_ep_obj in ep_obj_list:
# Only want to rename if we have a location
if cur_ep_obj.location:
- ep_obj_rename_list.append(cur_ep_obj)
+ if cur_ep_obj.relatedEps:
+ for cur_related_ep in cur_ep_obj.relatedEps:
+ if cur_related_ep not in ep_obj_rename_list:
+ ep_obj_rename_list.append(cur_ep_obj)
+ else:
+ ep_obj_rename_list.append(cur_ep_obj)
t = PageTemplate(file="testRename.tmpl")
t.submenu = [{'title': 'Edit', 'path': 'home/editShow?show=%d' % showObj.tvdbid}]

0 comments on commit 6374529

Please sign in to comment.