Skip to content

Commit

Permalink
meliman now waits x minutes before processing a file.
Browse files Browse the repository at this point in the history
  • Loading branch information
aftco committed Mar 18, 2009
1 parent 3a7f0fa commit 18cd62a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion config.py
Expand Up @@ -65,5 +65,5 @@ def getTitleCharsToIgnore(self):
return self.config.get('Miscellaneous', 'title_chars_to_ignore').strip()

def getWaitFromFileCreationInMinutes(self):
return self.config.get('Miscellaneous', 'wait_from_file_creation_in_minutes').strip()
return self.config.get('Miscellaneous', 'wait_after_file_creation_in_minutes').strip()

34 changes: 24 additions & 10 deletions file_manager.py
Expand Up @@ -38,6 +38,8 @@ def __init__(self, config, database, thetvdb, debug):

self.format = config.getLibraryFormat()

self.wait_from_file_creation_minutes = config.getWaitFromFileCreationInMinutes()

# create FileMatcher objects for each watched series
self.file_matchers = []
watched_series = self.database.get_watched_series()
Expand All @@ -47,21 +49,33 @@ def __init__(self, config, database, thetvdb, debug):

# returns a tuple of the form: (file_name, series, episode)
def match_file(self, file_path):
for file_matcher in self.file_matchers:
if file_matcher.matches_series_title(file_path):
if self.debug:
print "File '%s' matches series '%s'." % (file_path, file_matcher.series.title)

matches = file_matcher.match_episode(file_path)
for match in matches:
episode = match.get_episode_metadata(self.database, self.thetvdb)
if episode:
return (match.file_name, match.series, episode)
if self.is_time_to_process_file(file_path):
for file_matcher in self.file_matchers:
if file_matcher.matches_series_title(file_path):
if self.debug:
print "File '%s' matches series '%s'." % (file_path, file_matcher.series.title)

matches = file_matcher.match_episode(file_path)
for match in matches:
episode = match.get_episode_metadata(self.database, self.thetvdb)
if episode:
return (match.file_name, match.series, episode)

# if no matcher matches the file (or if matched episode doesn't exist), return None
return None


def is_time_to_process_file(self, file_path):
now = datetime.now()
create_time = datetime.fromtimestamp(os.path.getmtime(file_path))
minutes_from_creation = (now - create_time).seconds / 60.0

if minutes_from_creation > self.wait_from_file_creation_minutes:
return True

return False


def generate_metadata(self, episode):
if self.format == 'pyTivo':
if self.debug:
Expand Down

0 comments on commit 18cd62a

Please sign in to comment.