@ -1,5 +1,5 @@
import os , re
import os , re
from datetime import datetime
from datetime import datetime , timedelta , timezone
from modules import plex , util , anidb
from modules import plex , util , anidb
from modules . util import Failed , LimitReached , YAML
from modules . util import Failed , LimitReached , YAML
from plexapi . exceptions import NotFound
from plexapi . exceptions import NotFound
@ -10,14 +10,15 @@ logger = util.logger
meta_operations = [
meta_operations = [
" mass_audience_rating_update " , " mass_user_rating_update " , " mass_critic_rating_update " ,
" mass_audience_rating_update " , " mass_user_rating_update " , " mass_critic_rating_update " ,
" mass_episode_audience_rating_update " , " mass_episode_user_rating_update " , " mass_episode_critic_rating_update " ,
" mass_episode_audience_rating_update " , " mass_episode_user_rating_update " , " mass_episode_critic_rating_update " ,
" mass_genre_update " , " mass_content_rating_update " , " mass_originally_available_update " , " mass_ original_title _update" ,
" mass_genre_update " , " mass_content_rating_update " , " mass_originally_available_update " , " mass_ added_at _update" ,
" mass_ poster_update" , " mass_background_update " , " mass_studio_update "
" mass_ original_title_update" , " mass_ poster_update" , " mass_background_update " , " mass_studio_update "
]
]
name_display = {
name_display = {
" audienceRating " : " Audience Rating " ,
" audienceRating " : " Audience Rating " ,
" rating " : " Critic Rating " ,
" rating " : " Critic Rating " ,
" userRating " : " User Rating " ,
" userRating " : " User Rating " ,
" originallyAvailableAt " : " Originally Available Date " ,
" originallyAvailableAt " : " Originally Available Date " ,
" addedAt " : " Added At Date " ,
" contentRating " : " Content Rating "
" contentRating " : " Content Rating "
}
}
@ -45,6 +46,7 @@ class Operations:
logger . debug ( f " Mass Content Rating Update: { self . library . mass_content_rating_update } " )
logger . debug ( f " Mass Content Rating Update: { self . library . mass_content_rating_update } " )
logger . debug ( f " Mass Original Title Update: { self . library . mass_original_title_update } " )
logger . debug ( f " Mass Original Title Update: { self . library . mass_original_title_update } " )
logger . debug ( f " Mass Originally Available Update: { self . library . mass_originally_available_update } " )
logger . debug ( f " Mass Originally Available Update: { self . library . mass_originally_available_update } " )
logger . debug ( f " Mass Added At Update: { self . library . mass_added_at_update } " )
logger . debug ( f " Mass IMDb Parental Labels: { self . library . mass_imdb_parental_labels } " )
logger . debug ( f " Mass IMDb Parental Labels: { self . library . mass_imdb_parental_labels } " )
logger . debug ( f " Mass Poster Update: { self . library . mass_poster_update } " )
logger . debug ( f " Mass Poster Update: { self . library . mass_poster_update } " )
logger . debug ( f " Mass Background Update: { self . library . mass_background_update } " )
logger . debug ( f " Mass Background Update: { self . library . mass_background_update } " )
@ -88,7 +90,7 @@ class Operations:
genre_edits = { " add " : { } , " remove " : { } }
genre_edits = { " add " : { } , " remove " : { } }
content_edits = { }
content_edits = { }
studio_edits = { }
studio_edits = { }
available_edits = { }
date_edits = { " originallyAvailableAt " : { } , " addedAt " : { } }
remove_edits = { }
remove_edits = { }
reset_edits = { }
reset_edits = { }
lock_edits = { }
lock_edits = { }
@ -664,65 +666,69 @@ class Operations:
except Failed :
except Failed :
continue
continue
if self . library . mass_originally_available_update :
for attribute , item_attr in [
current_available = item . originallyAvailableAt
( self . library . mass_originally_available_update , " originallyAvailableAt " ) ,
if current_available :
( self . library . mass_added_at_update , " addedAt " )
current_available = current_available . strftime ( " % Y- % m- %d " )
] :
for option in self . library . mass_originally_available_update :
if attribute :
if option in [ " lock " , " remove " ] :
current = getattr ( item , item_attr )
if option == " remove " and current_available :
if current :
if " originallyAvailableAt " not in remove_edits :
current = current . strftime ( " % Y- % m- %d " )
remove_edits [ " originallyAvailableAt " ] = [ ]
for option in attribute :
remove_edits [ " originallyAvailableAt " ] . append ( item . ratingKey )
if option in [ " lock " , " remove " ] :
item_edits + = " \n Remove Originally Available Date (Batched) "
if option == " remove " and current :
elif " originallyAvailableAt " not in locked_fields :
if item_attr not in remove_edits :
if " originallyAvailableAt " not in lock_edits :
remove_edits [ item_attr ] = [ ]
lock_edits [ " originallyAvailableAt " ] = [ ]
remove_edits [ item_attr ] . append ( item . ratingKey )
lock_edits [ " originallyAvailableAt " ] . append ( item . ratingKey )
item_edits + = f " \n Remove { name_display [ item_attr ] } (Batched) "
item_edits + = " \n Lock Originally Available Date (Batched) "
elif item_attr not in locked_fields :
break
if item_attr not in lock_edits :
elif option in [ " unlock " , " reset " ] :
lock_edits [ item_attr ] = [ ]
if option == " reset " and current_available :
lock_edits [ item_attr ] . append ( item . ratingKey )
if " originallyAvailableAt " not in reset_edits :
item_edits + = f " \n Lock { name_display [ item_attr ] } (Batched) "
reset_edits [ " originallyAvailableAt " ] = [ ]
reset_edits [ " originallyAvailableAt " ] . append ( item . ratingKey )
item_edits + = " \n Reset Originally Available Date (Batched) "
elif " originallyAvailableAt " in locked_fields :
if " originallyAvailableAt " not in unlock_edits :
unlock_edits [ " originallyAvailableAt " ] = [ ]
unlock_edits [ " originallyAvailableAt " ] . append ( item . ratingKey )
item_edits + = " \n Unlock Originally Available Date (Batched) "
break
else :
try :
if option == " tmdb " :
new_available = tmdb_obj ( ) . release_date if self . library . is_movie else tmdb_obj ( ) . first_air_date # noqa
elif option == " omdb " :
new_available = omdb_obj ( ) . released # noqa
elif option == " tvdb " :
new_available = tvdb_obj ( ) . release_date # noqa
elif option == " mdb " :
new_available = mdb_obj ( ) . released # noqa
elif option == " mdb_digital " :
new_available = mdb_obj ( ) . released_digital # noqa
elif option == " anidb " :
new_available = anidb_obj ( ) . released # noqa
elif option == " mal " :
new_available = mal_obj ( ) . aired # noqa
else :
new_available = option
if not new_available :
logger . info ( f " No { option } Originally Available Date Found " )
raise Failed
new_available = new_available . strftime ( " % Y- % m- %d " )
if current_available != new_available :
if new_available not in available_edits :
available_edits [ new_available ] = [ ]
available_edits [ new_available ] . append ( item . ratingKey )
item_edits + = f " \n Update Originally Available Date (Batched) | { new_available } "
break
break
except Failed :
elif option in [ " unlock " , " reset " ] :
continue
if option == " reset " and current :
if item_attr not in reset_edits :
reset_edits [ item_attr ] = [ ]
reset_edits [ item_attr ] . append ( item . ratingKey )
item_edits + = f " \n Reset { name_display [ item_attr ] } (Batched) "
elif item_attr in locked_fields :
if item_attr not in unlock_edits :
unlock_edits [ item_attr ] = [ ]
unlock_edits [ item_attr ] . append ( item . ratingKey )
item_edits + = f " \n Unlock { name_display [ item_attr ] } (Batched) "
break
else :
try :
if option == " tmdb " :
new_date = tmdb_obj ( ) . release_date if self . library . is_movie else tmdb_obj ( ) . first_air_date # noqa
elif option == " omdb " :
new_date = omdb_obj ( ) . released # noqa
elif option == " tvdb " :
new_date = tvdb_obj ( ) . release_date # noqa
elif option == " mdb " :
new_date = mdb_obj ( ) . released # noqa
elif option == " mdb_digital " :
new_date = mdb_obj ( ) . released_digital # noqa
elif option == " anidb " :
new_date = anidb_obj ( ) . released # noqa
elif option == " mal " :
new_date = mal_obj ( ) . aired # noqa
else :
new_date = option
if not new_date :
logger . info ( f " No { option } { name_display [ item_attr ] } Found " )
raise Failed
new_date = new_date . strftime ( " % Y- % m- %d " )
if current != new_date :
if new_date not in date_edits [ item_attr ] :
date_edits [ item_attr ] [ new_date ] = [ ]
date_edits [ item_attr ] [ new_date ] . append ( item . ratingKey )
item_edits + = f " \n Update { name_display [ item_attr ] } (Batched) | { new_date } "
break
except Failed :
continue
if len ( item_edits ) > 0 :
if len ( item_edits ) > 0 :
logger . info ( f " Item Edits { item_edits } " )
logger . info ( f " Item Edits { item_edits } " )
@ -920,11 +926,27 @@ class Operations:
self . library . Plex . editStudio ( new_studio )
self . library . Plex . editStudio ( new_studio )
self . library . Plex . saveMultiEdits ( )
self . library . Plex . saveMultiEdits ( )
_size = len ( available_edits . items ( ) )
_size = len ( date_edits[ " originallyAvailableAt " ] . items ( ) )
for i , ( new_ availabl e, rating_keys ) in enumerate ( sorted ( available_edits . items ( ) ) , 1 ) :
for i , ( new_ dat e, rating_keys ) in enumerate ( sorted ( date_edits[ " originallyAvailableAt " ] . items ( ) ) , 1 ) :
logger . info ( get_batch_info ( i , _size , " originallyAvailableAt " , len ( rating_keys ) , display_value = new_ availabl e) )
logger . info ( get_batch_info ( i , _size , " originallyAvailableAt " , len ( rating_keys ) , display_value = new_ dat e) )
self . library . Plex . batchMultiEdits ( self . library . load_list_from_cache ( rating_keys ) )
self . library . Plex . batchMultiEdits ( self . library . load_list_from_cache ( rating_keys ) )
self . library . Plex . editOriginallyAvailable ( new_available )
self . library . Plex . editOriginallyAvailable ( new_date )
self . library . Plex . saveMultiEdits ( )
epoch = datetime ( 1970 , 1 , 1 )
_size = len ( date_edits [ " addedAt " ] . items ( ) )
for i , ( new_date , rating_keys ) in enumerate ( sorted ( date_edits [ " addedAt " ] . items ( ) ) , 1 ) :
logger . info ( get_batch_info ( i , _size , " addedAt " , len ( rating_keys ) , display_value = new_date ) )
self . library . Plex . batchMultiEdits ( self . library . load_list_from_cache ( rating_keys ) )
new_date = datetime . strptime ( new_date , " % Y- % m- %d " )
logger . trace ( new_date )
try :
ts = int ( round ( new_date . timestamp ( ) ) )
except ( TypeError , OSError ) :
offset = int ( datetime ( 2000 , 1 , 1 , tzinfo = timezone . utc ) . timestamp ( ) - datetime ( 2000 , 1 , 1 ) . timestamp ( ) )
ts = int ( ( new_date - epoch ) . total_seconds ( ) ) - offset
logger . trace ( epoch + timedelta ( seconds = ts ) )
self . library . Plex . editAddedAt ( ts )
self . library . Plex . saveMultiEdits ( )
self . library . Plex . saveMultiEdits ( )
_size = len ( remove_edits . items ( ) )
_size = len ( remove_edits . items ( ) )