@ -598,6 +598,7 @@ class Renamer(Plugin):
break
break
self . renaming_started = False
self . renaming_started = False
db . close ( )
def getRenameExtras ( self , extra_type = ' ' , replacements = None , folder_name = ' ' , file_name = ' ' , destination = ' ' , group = None , current_file = ' ' , remove_multiple = False ) :
def getRenameExtras ( self , extra_type = ' ' , replacements = None , folder_name = ' ' , file_name = ' ' , destination = ' ' , group = None , current_file = ' ' , remove_multiple = False ) :
if not group : group = { }
if not group : group = { }
@ -851,197 +852,200 @@ Remove it if you want it to be renamed (again, or at least let it try again)
snatched_status , ignored_status , failed_status , seeding_status , downloaded_status , missing_status = \
snatched_status , ignored_status , failed_status , seeding_status , downloaded_status , missing_status = \
fireEvent ( ' status.get ' , [ ' snatched ' , ' ignored ' , ' failed ' , ' seeding ' , ' downloaded ' , ' missing ' ] , single = True )
fireEvent ( ' status.get ' , [ ' snatched ' , ' ignored ' , ' failed ' , ' seeding ' , ' downloaded ' , ' missing ' ] , single = True )
db = get_session ( )
try :
rels = db . query ( Release ) . filter (
db = get_session ( )
Release . status_id . in_ ( [ snatched_status . get ( ' id ' ) , seeding_status . get ( ' id ' ) , missing_status . get ( ' id ' ) ] )
rels = db . query ( Release ) . filter (
) . all ( )
Release . status_id . in_ ( [ snatched_status . get ( ' id ' ) , seeding_status . get ( ' id ' ) , missing_status . get ( ' id ' ) ] )
) . all ( )
if not rels :
if not rels :
#No releases found that need status checking
#No releases found that need status checking
self . checking_snatched = False
self . checking_snatched = False
return True
return True
# Collect all download information with the download IDs from the releases
# Collect all download information with the download IDs from the releases
download_ids = [ ]
download_ids = [ ]
no_status_support = [ ]
no_status_support = [ ]
try :
try :
for rel in rels :
for rel in rels :
rel_dict = rel . to_dict ( { ' info ' : { } } )
rel_dict = rel . to_dict ( { ' info ' : { } } )
if rel_dict [ ' info ' ] . get ( ' download_id ' ) and rel_dict [ ' info ' ] . get ( ' download_downloader ' ) :
if rel_dict [ ' info ' ] . get ( ' download_id ' ) and rel_dict [ ' info ' ] . get ( ' download_downloader ' ) :
download_ids . append ( { ' id ' : rel_dict [ ' info ' ] [ ' download_id ' ] , ' downloader ' : rel_dict [ ' info ' ] [ ' download_downloader ' ] } )
download_ids . append ( { ' id ' : rel_dict [ ' info ' ] [ ' download_id ' ] , ' downloader ' : rel_dict [ ' info ' ] [ ' download_downloader ' ] } )
ds = rel_dict [ ' info ' ] . get ( ' download_status_support ' )
ds = rel_dict [ ' info ' ] . get ( ' download_status_support ' )
if ds == False or ds == ' False ' :
if ds == False or ds == ' False ' :
no_status_support . append ( ss ( rel_dict [ ' info ' ] . get ( ' download_downloader ' ) ) )
no_status_support . append ( ss ( rel_dict [ ' info ' ] . get ( ' download_downloader ' ) ) )
except :
except :
log . error ( ' Error getting download IDs from database ' )
log . error ( ' Error getting download IDs from database ' )
self . checking_snatched = False
self . checking_snatched = False
return False
return False
release_downloads = fireEvent ( ' download.status ' , download_ids , merge = True ) if download_ids else [ ]
release_downloads = fireEvent ( ' download.status ' , download_ids , merge = True ) if download_ids else [ ]
if len ( no_status_support ) > 0 :
if len ( no_status_support ) > 0 :
log . debug ( ' Download status functionality is not implemented for one of the active downloaders: %s ' , no_status_support )
log . debug ( ' Download status functionality is not implemented for one of the active downloaders: %s ' , no_status_support )
if not release_downloads :
if not release_downloads :
if fire_scan :
if fire_scan :
self . scan ( )
self . scan ( )
self . checking_snatched = False
self . checking_snatched = False
return True
return True
scan_releases = [ ]
scan_releases = [ ]
scan_required = False
scan_required = False
log . debug ( ' Checking status snatched releases... ' )
log . debug ( ' Checking status snatched releases... ' )
try :
try :
for rel in rels :
for rel in rels :
rel_dict = rel . to_dict ( { ' info ' : { } } )
rel_dict = rel . to_dict ( { ' info ' : { } } )
movie_dict = fireEvent ( ' media.get ' , media_id = rel . movie_id , single = True )
movie_dict = fireEvent ( ' media.get ' , media_id = rel . movie_id , single = True )
if not isinstance ( rel_dict [ ' info ' ] , dict ) :
if not isinstance ( rel_dict [ ' info ' ] , dict ) :
log . error ( ' Faulty release found without any info, ignoring. ' )
log . error ( ' Faulty release found without any info, ignoring. ' )
fireEvent ( ' release.update_status ' , rel . id , status = ignored_status , single = True )
fireEvent ( ' release.update_status ' , rel . id , status = ignored_status , single = True )
continue
continue
# Check if download ID is available
# Check if download ID is available
if not rel_dict [ ' info ' ] . get ( ' download_id ' ) or not rel_dict [ ' info ' ] . get ( ' download_downloader ' ) :
if not rel_dict [ ' info ' ] . get ( ' download_id ' ) or not rel_dict [ ' info ' ] . get ( ' download_downloader ' ) :
log . debug ( ' Download status functionality is not implemented for downloader ( %s ) of release %s . ' , ( rel_dict [ ' info ' ] . get ( ' download_downloader ' , ' unknown ' ) , rel_dict [ ' info ' ] [ ' name ' ] ) )
log . debug ( ' Download status functionality is not implemented for downloader ( %s ) of release %s . ' , ( rel_dict [ ' info ' ] . get ( ' download_downloader ' , ' unknown ' ) , rel_dict [ ' info ' ] [ ' name ' ] ) )
scan_required = True
scan_required = True
# Continue with next release
# Continue with next release
continue
continue
# Find release in downloaders
# Find release in downloaders
nzbname = self . createNzbName ( rel_dict [ ' info ' ] , movie_dict )
nzbname = self . createNzbName ( rel_dict [ ' info ' ] , movie_dict )
found_release = False
for release_download in release_downloads :
found_release = False
found_release = False
if rel_dict [ ' info ' ] . get ( ' download_id ' ) :
for release_download in release_downloads :
if release_download [ ' id ' ] == rel_dict [ ' info ' ] [ ' download_id ' ] and release_download [ ' downloader ' ] == rel_dict [ ' info ' ] [ ' download_downloader ' ] :
found_release = False
log . debug ( ' Found release by id: %s ' , release_download [ ' id ' ] )
if rel_dict [ ' info ' ] . get ( ' download_id ' ) :
found_release = True
if release_download [ ' id ' ] == rel_dict [ ' info ' ] [ ' download_id ' ] and release_download [ ' downloader ' ] == rel_dict [ ' info ' ] [ ' download_downloader ' ] :
break
log . debug ( ' Found release by id: %s ' , release_download [ ' id ' ] )
else :
found_release = True
if release_download [ ' name ' ] == nzbname or rel_dict [ ' info ' ] [ ' name ' ] in release_download [ ' name ' ] or getImdb ( release_download [ ' name ' ] ) == movie_dict [ ' library ' ] [ ' identifier ' ] :
break
log . debug ( ' Found release by release name or imdb ID: %s ' , release_download [ ' name ' ] )
else :
found_release = True
if release_download [ ' name ' ] == nzbname or rel_dict [ ' info ' ] [ ' name ' ] in release_download [ ' name ' ] or getImdb ( release_download [ ' name ' ] ) == movie_dict [ ' library ' ] [ ' identifier ' ] :
break
log . debug ( ' Found release by release name or imdb ID: %s ' , release_download [ ' name ' ] )
found_release = True
break
if not found_release :
if not found_release :
log . info ( ' %s not found in downloaders ' , nzbname )
log . info ( ' %s not found in downloaders ' , nzbname )
#Check status if already missing and for how long, if > 1 week, set to ignored else to missing
#Check status if already missing and for how long, if > 1 week, set to ignored else to missing
if rel . status_id == missing_status . get ( ' id ' ) :
if rel . status_id == missing_status . get ( ' id ' ) :
if rel . last_edit < int ( time . time ( ) ) - 7 * 24 * 60 * 60 :
if rel . last_edit < int ( time . time ( ) ) - 7 * 24 * 60 * 60 :
fireEvent ( ' release.update_status ' , rel . id , status = ignored_status , single = True )
fireEvent ( ' release.update_status ' , rel . id , status = ignored_status , single = True )
else :
else :
# Set the release to missing
# Set the release to missing
fireEvent ( ' release.update_status ' , rel . id , status = missing_status , single = True )
fireEvent ( ' release.update_status ' , rel . id , status = missing_status , single = True )
# Continue with next release
# Continue with next release
continue
continue
# Log that we found the release
timeleft = ' N/A ' if release_download [ ' timeleft ' ] == - 1 else release_download [ ' timeleft ' ]
log . debug ( ' Found %s : %s , time to go: %s ' , ( release_download [ ' name ' ] , release_download [ ' status ' ] . upper ( ) , timeleft ) )
# Log that we found the release
# Check status of release
timeleft = ' N/A ' if release_download [ ' timeleft ' ] == - 1 else release_download [ ' timeleft ' ]
if release_download [ ' status ' ] == ' busy ' :
log . debug ( ' Found %s : %s , time to go: %s ' , ( release_download [ ' name ' ] , release_download [ ' status ' ] . upper ( ) , timeleft ) )
# Set the release to snatched if it was missing before
fireEvent ( ' release.update_status ' , rel . id , status = snatched_status , single = True )
# Check status of release
# Tag folder if it is in the 'from' folder and it will not be processed because it is still downloading
if release_download [ ' status ' ] == ' busy ' :
if self . movieInFromFolder ( release_download [ ' folder ' ] ) :
# Set the release to snatched if it was missing before
self . tagRelease ( release_download = release_download , tag = ' downloading ' )
fireEvent ( ' release.update_status ' , rel . id , status = snatched_status , single = True )
# Tag folder if it is in the 'from' folder and it will not be processed because it is still downloading
elif release_download [ ' status ' ] == ' seeding ' :
if self . movieInFromFolder ( release_download [ ' folder ' ] ) :
#If linking setting is enabled, process release
self . tagRelease ( release_download = release_download , tag = ' downloading ' )
if self . conf ( ' file_action ' ) != ' move ' and not rel . status_id == seeding_status . get ( ' id ' ) and self . statusInfoComplete ( release_download ) :
log . info ( ' Download of %s completed! It is now being processed while leaving the original files alone for seeding. Current ratio: %s . ' , ( release_download [ ' name ' ] , release_download [ ' seed_ratio ' ] ) )
elif release_download [ ' status ' ] == ' seeding ' :
# Remove the downloading tag
#If linking setting is enabled, process release
self . untagRelease ( release_download = release_download , tag = ' downloading ' )
if self . conf ( ' file_action ' ) != ' move ' and not rel . status_id == seeding_status . get ( ' id ' ) and self . statusInfoComplete ( release_download ) :
log . info ( ' Download of %s completed! It is now being processed while leaving the original files alone for seeding. Current ratio: %s . ' , ( release_download [ ' name ' ] , release_download [ ' seed_ratio ' ] ) )
# Remove the downloading tag
# Scan and set the torrent to paused if required
self . untagRelease ( release_download = release_download , tag = ' downloading ' )
release_download . update ( { ' pause ' : True , ' scan ' : True , ' process_complete ' : False } )
scan_releases . append ( release_download )
else :
#let it seed
log . debug ( ' %s is seeding with ratio: %s ' , ( release_download [ ' name ' ] , release_download [ ' seed_ratio ' ] ) )
# Scan and set the torrent to paused if required
# Set the release to seeding
release_download . update ( { ' pause ' : True , ' scan ' : True , ' process_complete ' : False } )
fireEvent ( ' release.update_status ' , rel . id , status = seeding_status , single = True )
scan_releases . append ( release_download )
else :
#let it seed
log . debug ( ' %s is seeding with ratio: %s ' , ( release_download [ ' name ' ] , release_download [ ' seed_ratio ' ] ) )
# Set the release to seeding
elif release_download [ ' status ' ] == ' failed ' :
fireEvent ( ' release.update_status ' , rel . id , status = seeding_status , single = True )
# Set the release to failed
fireEvent ( ' release.update_status ' , rel . id , status = failed_status , single = True )
elif release_download [ ' status ' ] == ' failed ' :
fireEvent ( ' download.remove_failed ' , release_download , single = True )
# Set the release to failed
fireEvent ( ' release.update_status ' , rel . id , status = failed_status , single = True )
fireEvent ( ' download.remove_failed ' , release_download , single = True )
if self . conf ( ' next_on_failed ' ) :
fireEvent ( ' movie.searcher.try_next_release ' , media_id = rel . movie_id )
if self . conf ( ' next_on_failed ' ) :
elif release_download [ ' status ' ] == ' completed ' :
fireEvent ( ' movie.searcher.try_next_release ' , media_id = rel . movie_id )
log . info ( ' Download of %s completed! ' , release_download [ ' name ' ] )
elif release_download [ ' status ' ] == ' completed ' :
#Make sure the downloader sent over a path to look in
log . info ( ' Download of %s completed! ' , release_download [ ' name ' ] )
if self . statusInfoComplete ( release_download ) :
#Make sure the downloader sent over a path to look in
# If the release has been seeding, process now the seeding is done
if self . statusInfoComplete ( release_download ) :
if rel . status_id == seeding_status . get ( ' id ' ) :
if self . conf ( ' file_action ' ) != ' move ' :
# Set the release to done as the movie has already been renamed
fireEvent ( ' release.update_status ' , rel . id , status = downloaded_status , single = True )
# If the release has been seeding, process now the seeding is done
# Allow the downloader to clean-up
if rel . status_id == seeding_status . get ( ' id ' ) :
release_download . update ( { ' pause ' : False , ' scan ' : False , ' process_complete ' : True } )
if self . conf ( ' file_action ' ) != ' move ' :
scan_releases . append ( release_download )
# Set the release to done as the movie has already been renamed
else :
fireEvent ( ' release.update_status ' , rel . id , status = downloaded_status , single = True )
# Scan and Allow the downloader to clean-up
release_download . update ( { ' pause ' : False , ' scan ' : True , ' process_complete ' : True } )
scan_releases . append ( release_download )
# Allow the downloader to clean-up
release_download . update ( { ' pause ' : False , ' scan ' : False , ' process_complete ' : True } )
scan_releases . append ( release_download )
else :
else :
# Set the release to snatched if it was missing before
fireEvent ( ' release.update_status ' , rel . id , status = snatched_status , single = True )
# Remove the downloading tag
self . untagRelease ( release_download = release_download , tag = ' downloading ' )
# Scan and Allow the downloader to clean-up
# Scan and Allow the downloader to clean-up
release_download . update ( { ' pause ' : False , ' scan ' : True , ' process_complete ' : True } )
release_download . update ( { ' pause ' : False , ' scan ' : True , ' process_complete ' : True } )
scan_releases . append ( release_download )
scan_releases . append ( release_download )
else :
else :
# Set the release to snatched if it was missing before
scan_required = True
fireEvent ( ' release.update_status ' , rel . id , status = snatched_status , single = True )
# Remove the downloading tag
self . untagRelease ( release_download = release_download , tag = ' downloading ' )
# Scan and Allow the downloader to clean-up
except :
release_download . update ( { ' pause ' : False , ' scan ' : True , ' process_complete ' : True } )
log . error ( ' Failed checking for release in downloader: %s ' , traceback . format_exc ( ) )
scan_releases . append ( release_download )
else :
# The following can either be done here, or inside the scanner if we pass it scan_items in one go
scan_required = True
for release_download in scan_releases :
# Ask the renamer to scan the item
if release_download [ ' scan ' ] :
if release_download [ ' pause ' ] and self . conf ( ' file_action ' ) == ' link ' :
fireEvent ( ' download.pause ' , release_download = release_download , pause = True , single = True )
self . scan ( release_download = release_download )
if release_download [ ' pause ' ] and self . conf ( ' file_action ' ) == ' link ' :
fireEvent ( ' download.pause ' , release_download = release_download , pause = False , single = True )
if release_download [ ' process_complete ' ] :
#First make sure the files were succesfully processed
if not self . hastagRelease ( release_download = release_download , tag = ' failed_rename ' ) :
# Remove the seeding tag if it exists
self . untagRelease ( release_download = release_download , tag = ' renamed_already ' )
# Ask the downloader to process the item
fireEvent ( ' download.process_complete ' , release_download = release_download , single = True )
if fire_scan and ( scan_required or len ( no_status_support ) > 0 ) :
self . scan ( )
except :
self . checking_snatched = False
log . error ( ' Failed checking for release in downloader: %s ' , traceback . format_exc ( ) )
return True
finally :
# The following can either be done here, or inside the scanner if we pass it scan_items in one go
db . close ( )
for release_download in scan_releases :
# Ask the renamer to scan the item
if release_download [ ' scan ' ] :
if release_download [ ' pause ' ] and self . conf ( ' file_action ' ) == ' link ' :
fireEvent ( ' download.pause ' , release_download = release_download , pause = True , single = True )
self . scan ( release_download = release_download )
if release_download [ ' pause ' ] and self . conf ( ' file_action ' ) == ' link ' :
fireEvent ( ' download.pause ' , release_download = release_download , pause = False , single = True )
if release_download [ ' process_complete ' ] :
#First make sure the files were succesfully processed
if not self . hastagRelease ( release_download = release_download , tag = ' failed_rename ' ) :
# Remove the seeding tag if it exists
self . untagRelease ( release_download = release_download , tag = ' renamed_already ' )
# Ask the downloader to process the item
fireEvent ( ' download.process_complete ' , release_download = release_download , single = True )
if fire_scan and ( scan_required or len ( no_status_support ) > 0 ) :
self . scan ( )
self . checking_snatched = False
return True
def extendReleaseDownload ( self , release_download ) :
def extendReleaseDownload ( self , release_download ) :
@ -1064,6 +1068,8 @@ Remove it if you want it to be renamed (again, or at least let it try again)
if not rls :
if not rls :
log . error ( ' Download ID %s from downloader %s not found in releases ' , ( release_download . get ( ' id ' ) , release_download . get ( ' downloader ' ) ) )
log . error ( ' Download ID %s from downloader %s not found in releases ' , ( release_download . get ( ' id ' ) , release_download . get ( ' downloader ' ) ) )
db . close ( )
if rls :
if rls :
rls_dict = rls . to_dict ( { ' info ' : { } } )
rls_dict = rls . to_dict ( { ' info ' : { } } )