@ -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,62 +666,66 @@ 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 :
current = getattr ( item , item_attr )
if current :
current = current . strftime ( " % Y- % m- %d " )
for option in attribute :
if option in [ " lock " , " remove " ] :
if option in [ " lock " , " remove " ] :
if option == " remove " and current_available :
if option == " remove " and current :
if " originallyAvailableAt " not in remove_edits :
if item_attr not in remove_edits :
remove_edits [ " originallyAvailableAt " ] = [ ]
remove_edits [ item_attr ] = [ ]
remove_edits [ " originallyAvailableAt " ] . append ( item . ratingKey )
remove_edits [ item_attr ] . append ( item . ratingKey )
item_edits + = " \n Remove Originally Available Date (Batched)"
item_edits + = f " \n Remove { name_display [ item_attr ] } (Batched)"
elif " originallyAvailableAt " not in locked_fields :
elif item_attr not in locked_fields :
if " originallyAvailableAt " not in lock_edits :
if item_attr not in lock_edits :
lock_edits [ " originallyAvailableAt " ] = [ ]
lock_edits [ item_attr ] = [ ]
lock_edits [ " originallyAvailableAt " ] . append ( item . ratingKey )
lock_edits [ item_attr ] . append ( item . ratingKey )
item_edits + = " \n Lock Originally Available Date (Batched)"
item_edits + = f " \n Lock { name_display [ item_attr ] } (Batched)"
break
break
elif option in [ " unlock " , " reset " ] :
elif option in [ " unlock " , " reset " ] :
if option == " reset " and current _available :
if option == " reset " and current :
if " originallyAvailableAt " not in reset_edits :
if item_attr not in reset_edits :
reset_edits [ " originallyAvailableAt " ] = [ ]
reset_edits [ item_attr ] = [ ]
reset_edits [ " originallyAvailableAt " ] . append ( item . ratingKey )
reset_edits [ item_attr ] . append ( item . ratingKey )
item_edits + = " \n Reset Originally Available Date (Batched)"
item_edits + = f " \n Reset { name_display [ item_attr ] } (Batched)"
elif " originallyAvailableAt " in locked_fields :
elif item_attr in locked_fields :
if " originallyAvailableAt " not in unlock_edits :
if item_attr not in unlock_edits :
unlock_edits [ " originallyAvailableAt " ] = [ ]
unlock_edits [ item_attr ] = [ ]
unlock_edits [ " originallyAvailableAt " ] . append ( item . ratingKey )
unlock_edits [ item_attr ] . append ( item . ratingKey )
item_edits + = " \n Unlock Originally Available Date (Batched)"
item_edits + = f " \n Unlock { name_display [ item_attr ] } (Batched)"
break
break
else :
else :
try :
try :
if option == " tmdb " :
if option == " tmdb " :
new_availabl e = tmdb_obj ( ) . release_date if self . library . is_movie else tmdb_obj ( ) . first_air_date # noqa
new_dat e = tmdb_obj ( ) . release_date if self . library . is_movie else tmdb_obj ( ) . first_air_date # noqa
elif option == " omdb " :
elif option == " omdb " :
new_availabl e = omdb_obj ( ) . released # noqa
new_dat e = omdb_obj ( ) . released # noqa
elif option == " tvdb " :
elif option == " tvdb " :
new_availabl e = tvdb_obj ( ) . release_date # noqa
new_dat e = tvdb_obj ( ) . release_date # noqa
elif option == " mdb " :
elif option == " mdb " :
new_availabl e = mdb_obj ( ) . released # noqa
new_dat e = mdb_obj ( ) . released # noqa
elif option == " mdb_digital " :
elif option == " mdb_digital " :
new_availabl e = mdb_obj ( ) . released_digital # noqa
new_dat e = mdb_obj ( ) . released_digital # noqa
elif option == " anidb " :
elif option == " anidb " :
new_availabl e = anidb_obj ( ) . released # noqa
new_dat e = anidb_obj ( ) . released # noqa
elif option == " mal " :
elif option == " mal " :
new_availabl e = mal_obj ( ) . aired # noqa
new_dat e = mal_obj ( ) . aired # noqa
else :
else :
new_availabl e = option
new_dat e = option
if not new_availabl e:
if not new_dat e:
logger . info ( f " No { option } Originally Available Date Found" )
logger . info ( f " No { option } { name_display [ item_attr ] } Found" )
raise Failed
raise Failed
new_available = new_availabl e. strftime ( " % Y- % m- %d " )
new_date = new_dat e. strftime ( " % Y- % m- %d " )
if current_available != new_availabl e:
if current != new_dat e:
if new_available not in available_edits :
if new_date not in date_edits [ item_attr ] :
available_edits [ new_availabl e] = [ ]
date_edits [ item_attr ] [ new_dat e] = [ ]
available_edits [ new_availabl e] . append ( item . ratingKey )
date_edits [ item_attr ] [ new_dat e] . append ( item . ratingKey )
item_edits + = f " \n Update Originally Available Date (Batched) | { new_availabl e} "
item_edits + = f " \n Update { name_display [ item_attr ] } (Batched) | { new_dat e} "
break
break
except Failed :
except Failed :
continue
continue
@ -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 ( ) )