
    lj=                        d dl Z d dlmZ d dlmZ d dlmZmZmZ d dl	m
Z
mZmZmZ d dlmZ d dlmZmZ ej&                   G d d	ee             Zej&                   G d
 dee
e             Zej&                   G d dee             Zy)    N)Path)
quote_plus)mediautilsvideo)PlayablePlexPartialObjectPlexSessioncached_data_property)
BadRequest)PhotoalbumMixinsPhotoMixinsc                       e Zd ZdZdZdZdZd Zed        Z	ed        Z
d Zd	 Zd
 Zd Zd Zd Zd ZddZddZed        Zy)
Photoalbuma   Represents a single Photoalbum (collection of photos).

        Attributes:
            TAG (str): 'Directory'
            TYPE (str): 'photo'
            addedAt (datetime): Datetime the photo album was added to the library.
            art (str): URL to artwork image (/library/metadata/<ratingKey>/art/<artid>).
            composite (str): URL to composite image (/library/metadata/<ratingKey>/composite/<compositeid>)
            fields (List<:class:`~plexapi.media.Field`>): List of field objects.
            guid (str): Plex GUID for the photo album (local://229674).
            images (List<:class:`~plexapi.media.Image`>): List of image objects.
            index (sting): Plex index number for the photo album.
            key (str): API URL (/library/metadata/<ratingkey>).
            lastRatedAt (datetime): Datetime the photo album was last rated.
            librarySectionID (int): :class:`~plexapi.library.LibrarySection` ID.
            librarySectionKey (str): :class:`~plexapi.library.LibrarySection` key.
            librarySectionTitle (str): :class:`~plexapi.library.LibrarySection` title.
            listType (str): Hardcoded as 'photo' (useful for search filters).
            ratingKey (int): Unique key identifying the photo album.
            summary (str): Summary of the photoalbum.
            thumb (str): URL to thumbnail image (/library/metadata/<ratingKey>/thumb/<thumbid>).
            title (str): Name of the photo album. (Trip to Disney World)
            titleSort (str): Title to use when sorting (defaults to title).
            type (str): 'photo'
            updatedAt (datetime): Datetime the photo album was updated.
            userRating (float): Rating of the photo album (0.0 - 10.0) equaling (0 stars - 5 stars).
    	Directoryphoto
photoalbumc                    t        j                  |j                  j                  d            | _        |j                  j                  d      | _        |j                  j                  d      | _        |j                  j                  d      | _        t        j                  t        |j                  j                  d            | _
        |j                  j                  dd      j                  dd      | _        t        j                  |j                  j                  d	            | _        t        j                  t        |j                  j                  d
            | _        |j                  j                  d      | _        |j                  j                  d      | _        d| _        t        j                  t        |j                  j                  d            | _        |j                  j                  d      | _        |j                  j                  d      | _        |j                  j                  d      | _        |j                  j                  d| j*                        | _        |j                  j                  d      | _        t        j                  |j                  j                  d            | _        t        j                  t2        |j                  j                  d            | _        y)/ Load attribute values from Plex XML response. addedAtart	compositeguidindexkey 	/childrenlastRatedAtlibrarySectionIDlibrarySectionKeylibrarySectionTitler   	ratingKeysummarythumbtitle	titleSorttype	updatedAt
userRatingN)r   
toDatetimeattribgetr   r   r   r   castintr   replacer   r   r   r    r!   listTyper"   r#   r$   r%   r&   r'   r(   floatr)   selfdatas     :/DATA/.local/lib/python3.12/site-packages/plexapi/photo.py	_loadDatazPhotoalbum._loadData.   s   ''	(BC;;??5)5KKOOF+	ZZT[[__W%=>
;;??5"-55k2F ++DKKOOM,JK %

3@R0S T!%1D!E#';;??3H#I C)EF{{y1[[__W-
[[__W-
djjAKKOOF+	))$++//+*FG**UDKKOOL,IJ    c                 V    | j                  | j                  t        j                        S N	findItems_datar   Fieldr3   s    r5   fieldszPhotoalbum.fieldsD       ~~djj%++66r7   c                 V    | j                  | j                  t        j                        S r9   r;   r<   r   Imager>   s    r5   imageszPhotoalbum.imagesH   r@   r7   c                 P    | j                    d}| j                  |t        |      S )z Returns the :class:`~plexapi.photo.Photoalbum` that matches the specified title.

            Parameters:
                title (str): Title of the photo album to return.
        r   title__iexact)r   	fetchItemr   r3   r%   r   s      r5   albumzPhotoalbum.albumL   s)     
)$~~c:U~CCr7   c                 P    | j                    d} | j                  |t        fi |S )zL Returns a list of :class:`~plexapi.photo.Photoalbum` objects in the album. r   )r   
fetchItemsr   r3   kwargsr   s      r5   albumszPhotoalbum.albumsU   s*    
)$tsJ9&99r7   c                 P    | j                    d}| j                  |t        |      S )z Returns the :class:`~plexapi.photo.Photo` that matches the specified title.

            Parameters:
                title (str): Title of the photo to return.
        r   rF   )r   rH   PhotorI   s      r5   r   zPhotoalbum.photoZ   s)     
)$~~c5~>>r7   c                 P    | j                    d} | j                  |t        fi |S )zG Returns a list of :class:`~plexapi.photo.Photo` objects in the album. r   )r   rL   rQ   rM   s      r5   photoszPhotoalbum.photosc   s*    
)$tsE4V44r7   c                 d    | j                    d}| j                  |t        j                  |      S )z Returns the :class:`~plexapi.video.Clip` that matches the specified title.

            Parameters:
                title (str): Title of the clip to return.
        r   rF   )r   rH   r   CliprI   s      r5   clipzPhotoalbum.cliph   s-     
)$~~c5::U~CCr7   c                 d    | j                    d} | j                  |t        j                  fi |S )zF Returns a list of :class:`~plexapi.video.Clip` objects in the album. r   )r   rL   r   rU   rM   s      r5   clipszPhotoalbum.clipsq   s.    
)$tsEJJ9&99r7   c                 $    | j                  |      S )z3 Alias to :func:`~plexapi.photo.Photoalbum.photo`. )episode)r3   r%   s     r5   r,   zPhotoalbum.getv   s    ||E""r7   Nc                 0   g }| j                         D ]E  }|r*t        j                  j                  ||j                        n|}||j                  ||      z  }G | j                         | j                         z   D ]  }||j                  ||      z  } |S )a   Download all photos and clips from the photo album. See :func:`~plexapi.base.Playable.download` for details.

            Parameters:
                savepath (str): Defaults to current working dir.
                keep_original_name (bool): True to keep the original filename otherwise
                    a friendlier filename is generated.
                subfolders (bool): True to separate photos/clips in to photo album folders.
        )rO   ospathjoinr%   downloadrS   rX   )r3   savepathkeep_original_name
subfolders	filepathsrJ   	_savepathr   s           r5   r_   zPhotoalbum.downloadz   s     	[[]E?IXu{{;xI	3EFFI # [[]TZZ\1E2DEEI 2r7   c                 T    | j                   j                  |d| j                  d      S z3 Get the Plex Web URL with the correct parameters. details   )baseendpointr   legacy)_server_buildWebURLr   r3   ri   s     r5   
_getWebURLzPhotoalbum._getWebURL   s%    ||((dYDHH]^(__r7   c                     t        j                  | j                        }t        t	        d      dz  |d   z  |dd  dz        S zL Returns the Plex Media Server data directory where the metadata is stored. MetadataPhotosr   rh   Nz.bundle)r   sha1hashr   strr   r3   	guid_hashs     r5   metadataDirectoryzPhotoalbum.metadataDirectory   sG     NN499-	4
#h.1=9QR=/QX@YYZZr7   )NFFr9   )__name__
__module____qualname____doc__TAGTYPE_searchTyper6   r   r?   rD   rJ   rO   r   rS   rV   rX   r,   r_   ro   propertyrx    r7   r5   r   r      s    6 CDKK, 7 7 7 7D:
?5
D:
#"` [ [r7   r   c                       e Zd ZdZd ZdZdZd Zed        Z	ed        Z
ed        Zed        Zd Zd	 Zd
 Zed        ZddZddZed        Zy)rQ   a	   Represents a single Photo.

        Attributes:
            TAG (str): 'Photo'
            TYPE (str): 'photo'
            addedAt (datetime): Datetime the photo was added to the library.
            createdAtAccuracy (str): Unknown (local).
            createdAtTZOffset (int): Unknown (-25200).
            fields (List<:class:`~plexapi.media.Field`>): List of field objects.
            guid (str): Plex GUID for the photo (com.plexapp.agents.none://231714?lang=xn).
            images (List<:class:`~plexapi.media.Image`>): List of image objects.
            index (sting): Plex index number for the photo.
            key (str): API URL (/library/metadata/<ratingkey>).
            lastRatedAt (datetime): Datetime the photo was last rated.
            librarySectionID (int): :class:`~plexapi.library.LibrarySection` ID.
            librarySectionKey (str): :class:`~plexapi.library.LibrarySection` key.
            librarySectionTitle (str): :class:`~plexapi.library.LibrarySection` title.
            listType (str): Hardcoded as 'photo' (useful for search filters).
            media (List<:class:`~plexapi.media.Media`>): List of media objects.
            originallyAvailableAt (datetime): Datetime the photo was added to Plex.
            parentGuid (str): Plex GUID for the photo album (local://229674).
            parentIndex (int): Plex index number for the photo album.
            parentKey (str): API URL of the photo album (/library/metadata/<parentRatingKey>).
            parentRatingKey (int): Unique key identifying the photo album.
            parentThumb (str): URL to photo album thumbnail image (/library/metadata/<parentRatingKey>/thumb/<thumbid>).
            parentTitle (str): Name of the photo album for the photo.
            ratingKey (int): Unique key identifying the photo.
            sourceURI (str): Remote server URI (server://<machineIdentifier>/com.plexapp.plugins.library)
                (remote playlist item only).
            summary (str): Summary of the photo.
            tags (List<:class:`~plexapi.media.Tag`>): List of tag objects.
            thumb (str): URL to thumbnail image (/library/metadata/<ratingKey>/thumb/<thumbid>).
            title (str): Name of the photo.
            titleSort (str): Title to use when sorting (defaults to title).
            type (str): 'photo'
            updatedAt (datetime): Datetime the photo was updated.
            userRating (float): Rating of the photo (0.0 - 10.0) equaling (0 stars - 5 stars).
            year (int): Year the photo was taken.
    r   c                 0	   t        j                  | |       t        j                  |j                  j                  d            | _        |j                  j                  d      | _        t        j                  t        |j                  j                  d            | _
        |j                  j                  d      | _        t        j                  t        |j                  j                  d            | _        |j                  j                  dd      | _        t        j                  |j                  j                  d            | _        t        j                  t        |j                  j                  d	            | _        |j                  j                  d
      | _        |j                  j                  d      | _        d| _        t        j                  |j                  j                  d      d      | _        |j                  j                  d      | _        t        j                  t        |j                  j                  d            | _        |j                  j                  d      | _        t        j                  t        |j                  j                  d            | _        |j                  j                  d      | _        |j                  j                  d      | _        t        j                  t        |j                  j                  d            | _        |j                  j                  d      | _        |j                  j                  d      | _        |j                  j                  d      | _        |j                  j                  d      | _        |j                  j                  d| j<                        | _        |j                  j                  d      | _         t        j                  |j                  j                  d            | _!        t        j                  tD        |j                  j                  d            | _#        t        j                  t        |j                  j                  d            | _$        y) r   r   createdAtAccuracycreatedAtTZOffsetr   r   r   r   r   r   r    r!   r   originallyAvailableAtz%Y-%m-%d
parentGuidparentIndex	parentKeyparentRatingKeyparentThumbparentTitler"   sourcer#   r$   r%   r&   r'   r(   r)   yearN)%r   r6   r   r*   r+   r,   r   r   r-   r.   r   r   r   r   r   r   r    r!   r0   r   r   r   r   r   r   r   r"   	sourceURIr#   r$   r%   r&   r'   r(   r1   r)   r   r2   s     r5   r6   zPhoto._loadData   s   4&''	(BC!%1D!E!&CAT1U!VKKOOF+	ZZT[[__W%=>
;;??5"- ++DKKOOM,JK %

3@R0S T!%1D!E#';;??3H#I %*%5%5dkkooF]6^`j%k"++//,7 ::c4;;??=+IJ5$zz#t{{?P/QR;;??=9;;??=9C)EF2{{y1[[__W-
[[__W-
djjAKKOOF+	))$++//+*FG**UDKKOOL,IJJJsDKKOOF$;<	r7   c                 V    | j                  | j                  t        j                        S r9   r:   r>   s    r5   r?   zPhoto.fields   r@   r7   c                 V    | j                  | j                  t        j                        S r9   rB   r>   s    r5   rD   zPhoto.images   r@   r7   c                 V    | j                  | j                  t        j                        S r9   )r;   r<   r   Mediar>   s    r5   r   zPhoto.media   r@   r7   c                 V    | j                  | j                  t        j                        S r9   )r;   r<   r   Tagr>   s    r5   tagsz
Photo.tags   s    ~~djj%))44r7   c                 h    | j                   r| j                    d| j                   S | j                  S )z) Returns a filename for use in download. z - )r   r%   r>   s    r5   _prettyfilenamezPhoto._prettyfilename   s1    &&'s4::,77zzr7   c                 8    | j                  | j                        S )z8 Return the photo's :class:`~plexapi.photo.Photoalbum`. )rH   r   r>   s    r5   r   zPhoto.photoalbum   s    ~~dnn--r7   c                     t        | d      r/| j                  j                  j                  | j                        S | j
                  r=| j                  j                  j                  | j                         j                        S t        d      )zK Returns the :class:`~plexapi.library.LibrarySection` the item belongs to. r   z<Unable to get section for photo, can't find librarySectionID)hasattrrl   librarysectionByIDr   r   r   r   r>   s    r5   sectionzPhoto.section   si    4+,<<''33D4I4IJJ^^<<''33DOO4E4V4VWW[\\r7   c                     | j                   D cg c]"  }|j                  D ]  }|s|j                   $ c}}S c c}}w )z This does not exist in plex xml response but is added to have a common
            interface to get the locations of the photo.

            Returns:
                List<str> of file paths where the photo is found on disk.
        )r   partsfile)r3   itemparts      r5   	locationszPhoto.locations  s2     '+jjPjdTZZT4		Z	jPPPs   ;;Nc                 *   ddl m}m}m} | j                  j                         }	 || j                  d      }
|r|n| j                  |
_        | j                  |
_        | j                  |
_	        | j                  |
_        | j                  j                  |
_        | j                         }d|j                   dt        | j                          |
_        |j%                  |      |
_        |j)                  |      |
_        |	j-                  |
||      S )a   Add current photo as sync item for specified device.
            See :func:`~plexapi.myplex.MyPlexAccount.sync` for possible exceptions.

            Parameters:
                resolution (str): maximum allowed resolution for synchronized photos, see PHOTO_QUALITY_* values in the
                                  module :mod:`~plexapi.sync`.
                client (:class:`~plexapi.myplex.MyPlexDevice`): sync destination, see
                                                               :func:`~plexapi.myplex.MyPlexAccount.sync`.
                clientId (str): sync destination, see :func:`~plexapi.myplex.MyPlexAccount.sync`.
                limit (int): maximum count of items to sync, unlimited if `None`.
                title (str): descriptive title for the new :class:`~plexapi.sync.SyncItem`, if empty the value would be
                             generated from metadata of current photo.

            Returns:
                :class:`~plexapi.sync.SyncItem`: an instance of created syncItem.
        r   )SyncItemPolicyMediaSettingsNz
library://z/item/)clientclientId)plexapi.syncr   r   r   rl   myPlexAccountr%   	rootTitler0   contentTypeMETADATA_TYPEmetadataTypemachineIdentifierr   uuidr   r   locationcreatepolicycreatePhotomediaSettingssync)r3   
resolutionr   r   limitr%   r   r   r   myplex	sync_itemr   s               r5   r   z
Photo.sync  s    $ 	A@++-T\\40	#(%djj	"jj	 $	!%!3!3	&*ll&D&D	#,,.)',,vj>R=ST	!==/	"/";";J"G	{{9Vh{GGr7   c                 T    | j                   j                  |d| j                  d      S rf   )rl   rm   r   rn   s     r5   ro   zPhoto._getWebURL6  s%    ||((dYDNNcd(eer7   c                     t        j                  | j                        }t        t	        d      dz  |d   z  |dd  dz        S rq   )r   rt   r   ru   r   rv   s     r5   rx   zPhoto.metadataDirectory:  sG     NN4??3	4
#h.1=9QR=/QX@YYZZr7   )NNNNr9   )ry   rz   r{   r|   r}   r~   r   r6   r   r?   rD   r   r   r   r   r   r   r   r   ro   rx   r   r7   r5   rQ   rQ      s    &N CDM=@ 7 7 7 7 7 7 5 5.] Q Q"HHf [ [r7   rQ   c                       e Zd ZdZdZd Zy)PhotoSessionzh Represents a single Photo session
        loaded from :func:`~plexapi.server.PlexServer.sessions`.
    Tc                 \    t         j                  | |       t        j                  | |       y)r   N)rQ   r6   r
   r2   s     r5   r6   zPhotoSession._loadDataH  s     d#dD)r7   N)ry   rz   r{   r|   _SESSIONTYPEr6   r   r7   r5   r   r   A  s     L*r7   r   )r\   pathlibr   urllib.parser   plexapir   r   r   plexapi.baser   r	   r
   r   plexapi.exceptionsr   plexapi.mixinsr   r   registerPlexObjectr   rQ   r   r   r7   r5   <module>r      s    	  # ' ' W W ) 8 G['G[ G[T g[xg[ g[T 	*; 	* 	*r7   