
    lj                     @    d dl mZ d dlmZmZ d dlmZ  G d d      Zy)    )	urlencode)mediautils)NotFoundc                   &    e Zd ZdZd ZddZddZy)UnmatchMatchMixinz; Mixin for Plex objects that can be unmatched and matched. c                     | j                    d}| j                  j                  || j                  j                  j                         y)z' Unmatches metadata match from object. z/unmatchmethodN)key_serverquery_sessionput)selfr   s     I/DATA/.local/lib/python3.12/site-packages/plexapi/mixins/unmatch_match.pyunmatchzUnmatchMatchMixin.unmatch
   s9    
(#3t||'<'<'@'@A    Nc                    | j                    d}ddi}|rSt        |||g      sE| j                         j                  |d<   t	        j
                  | j                         |      |d<   nt        d ||||fD              r|| j                  |d<   n||d<   |t        | dd	      |d<   n||d<   |xs | j                         j                  |d<   || j                         j                  |d<   n't	        j
                  | j                         |      |d<   |d
z   t        |      z   }| j                  |t        j                        S )a   Return list of (:class:`~plexapi.media.SearchResult`) metadata matches.

             Parameters:
                agent (str): Agent name to be used (imdb, thetvdb, themoviedb, etc.)
                title (str): Title of item to search for
                year (str): Year of item to search in
                language (str) : Language of item to search in

            Examples:
                1. video.matches()
                2. video.matches(title="something", year=2020)
                3. video.matches(title="something")
                4. video.matches(year=2020)
                5. video.matches(title="something", year="")
                6. video.matches(title="", year=2020)
                7. video.matches(title="", year="")

                1. The default behaviour in Plex Web = no params in plexapi
                2. Both title and year specified by user
                3. Year automatically filled in
                4. Title automatically filled in
                5. Explicitly searches for title with blank year
                6. Explicitly searches for blank title with year
                7. I don't know what the user is thinking... return the same result as 1

                For 2 to 7, the agent and language is automatically filled in
        z/matchesmanual   languageagentc              3   $   K   | ]  }|d u 
 y w)N ).0xs     r   	<genexpr>z,UnmatchMatchMixin.matches.<locals>.<genexpr>2   s     I*HQ1D=*Hs   titleyear ?)cls)r   anysectionr   r   getAgentIdentifierr   getattrr   r   
fetchItemsr   SearchResult)r   r   r   r    r   r   paramss          r   matcheszUnmatchMatchMixin.matches   s/   8 
(#AeT845!%!8!8F:#66t||~uMF7OI5%x*HII=&*jjF7O&+F7O<%,T62%>F6N%)F6N%-%H1H1Hz"=&*lln&:&:F7O&+&>&>t||~u&UF7OCi)F++s(:(:;;r   c                 d   | j                    d}|r,| j                  |      }|r|d   }nt        d| d| d      |st        d      |j                  |j                  d}|d	z   t        |      z   }| j                  j                  || j                  j                  j                  
       | S )a   Use match result to update show metadata.

            Parameters:
                auto (bool): True uses first match from matches
                    False allows user to provide the match
                searchResult (:class:`~plexapi.media.SearchResult`): Search result from
                    ~plexapi.base.matches()
                agent (str): Agent name to be used (imdb, thetvdb, themoviedb, etc.)
        z/match)r   r   z$No matches found using this agent: (:)zZfixMatch() requires either auto=True or searchResult=:class:`~plexapi.media.SearchResult`.)guidnamer"   r
   )
r   r+   r   r/   r0   r   r   r   r   r   )r   searchResultautor   r   	autoMatchr*   datas           r   fixMatchzUnmatchMatchMixin.fixMatchG   s     
&!51I(|!EeWAi[XYZ[[ P Q Q '++&++- Sy9V,,4(=(=(A(ABr   )NNNN)NFN)__name__
__module____qualname____doc__r   r+   r5   r   r   r   r   r      s    EB
6<pr   r   N)urllib.parser   plexapir   r   plexapi.exceptionsr   r   r   r   r   <module>r=      s    "   'Z Zr   