Scanner code cleanup
This commit is contained in:
@@ -5,7 +5,7 @@ from couchpotato.core.helpers.variable import getExt, getImdb, tryInt
|
|||||||
from couchpotato.core.logger import CPLog
|
from couchpotato.core.logger import CPLog
|
||||||
from couchpotato.core.plugins.base import Plugin
|
from couchpotato.core.plugins.base import Plugin
|
||||||
from couchpotato.core.settings.model import File
|
from couchpotato.core.settings.model import File
|
||||||
from enzyme.exceptions import NoParserError
|
from enzyme.exceptions import NoParserError, ParseError
|
||||||
import enzyme
|
import enzyme
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
@@ -115,8 +115,11 @@ class Scanner(Plugin):
|
|||||||
files_in_path.update({'available': 0}, synchronize_session = False)
|
files_in_path.update({'available': 0}, synchronize_session = False)
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
update_after = []
|
while True and not self.shuttingDown():
|
||||||
for group in groups.itervalues():
|
try:
|
||||||
|
identifier, group = groups.popitem()
|
||||||
|
except:
|
||||||
|
break
|
||||||
|
|
||||||
# Save to DB
|
# Save to DB
|
||||||
if group['library']:
|
if group['library']:
|
||||||
@@ -125,10 +128,6 @@ class Scanner(Plugin):
|
|||||||
fireEvent('release.add', group = group)
|
fireEvent('release.add', group = group)
|
||||||
fireEvent('library.update', identifier = group['library'].get('identifier'))
|
fireEvent('library.update', identifier = group['library'].get('identifier'))
|
||||||
|
|
||||||
# Break if CP wants to shut down
|
|
||||||
if self.shuttingDown():
|
|
||||||
break
|
|
||||||
|
|
||||||
db.remove()
|
db.remove()
|
||||||
|
|
||||||
|
|
||||||
@@ -176,6 +175,13 @@ class Scanner(Plugin):
|
|||||||
else:
|
else:
|
||||||
leftovers.append(file_path)
|
leftovers.append(file_path)
|
||||||
|
|
||||||
|
# Break if CP wants to shut down
|
||||||
|
if self.shuttingDown():
|
||||||
|
break
|
||||||
|
|
||||||
|
# Cleanup
|
||||||
|
del files
|
||||||
|
|
||||||
# Sort reverse, this prevents "Iron man 2" from getting grouped with "Iron man" as the "Iron Man 2"
|
# Sort reverse, this prevents "Iron man 2" from getting grouped with "Iron man" as the "Iron Man 2"
|
||||||
# files will be grouped first.
|
# files will be grouped first.
|
||||||
leftovers = set(sorted(leftovers, reverse = True))
|
leftovers = set(sorted(leftovers, reverse = True))
|
||||||
@@ -224,9 +230,12 @@ class Scanner(Plugin):
|
|||||||
|
|
||||||
|
|
||||||
# Determine file types
|
# Determine file types
|
||||||
delete_identifier = []
|
processed_movies = {}
|
||||||
for identifier in movie_files:
|
while True and not self.shuttingDown():
|
||||||
group = movie_files[identifier]
|
try:
|
||||||
|
identifier, group = movie_files.popitem()
|
||||||
|
except:
|
||||||
|
break
|
||||||
|
|
||||||
# Check if movie is fresh and maybe still unpacking, ignore files new then 1 minute
|
# Check if movie is fresh and maybe still unpacking, ignore files new then 1 minute
|
||||||
file_too_new = False
|
file_too_new = False
|
||||||
@@ -238,7 +247,6 @@ class Scanner(Plugin):
|
|||||||
|
|
||||||
if file_too_new:
|
if file_too_new:
|
||||||
log.info('Files seem to be still unpacking or just unpacked (created on %s), ignoring for now: %s' % (time.ctime(file_time), identifier))
|
log.info('Files seem to be still unpacking or just unpacked (created on %s), ignoring for now: %s' % (time.ctime(file_time), identifier))
|
||||||
delete_identifier.append(identifier)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Group extra (and easy) files first
|
# Group extra (and easy) files first
|
||||||
@@ -288,15 +296,13 @@ class Scanner(Plugin):
|
|||||||
if not group['library']:
|
if not group['library']:
|
||||||
log.error('Unable to determin movie: %s' % group['identifiers'])
|
log.error('Unable to determin movie: %s' % group['identifiers'])
|
||||||
|
|
||||||
# Break if CP wants to shut down
|
processed_movies[identifier] = group
|
||||||
if self.shuttingDown():
|
|
||||||
break
|
|
||||||
|
|
||||||
# Delete still (asuming) unpacking files
|
|
||||||
for identifier in delete_identifier:
|
|
||||||
del movie_files[identifier]
|
|
||||||
|
|
||||||
return movie_files
|
# Clean up
|
||||||
|
self.path_identifiers = {}
|
||||||
|
|
||||||
|
return processed_movies
|
||||||
|
|
||||||
def getMetaData(self, group):
|
def getMetaData(self, group):
|
||||||
|
|
||||||
@@ -342,6 +348,8 @@ class Scanner(Plugin):
|
|||||||
'resolution_width': p.video[0].width,
|
'resolution_width': p.video[0].width,
|
||||||
'resolution_height': p.video[0].height,
|
'resolution_height': p.video[0].height,
|
||||||
}
|
}
|
||||||
|
except ParseError:
|
||||||
|
log.debug('Failed to parse meta for %s' % filename)
|
||||||
except NoParserError:
|
except NoParserError:
|
||||||
log.debug('No parser found for %s' % filename)
|
log.debug('No parser found for %s' % filename)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user