
    ҫfi                    p    d dl mZ d dlmZmZmZmZ ddlmZ erddl	m
Z
 ddlmZ ddlmZ  G d	 d
      Zy)    )annotations)TYPE_CHECKINGClassVarAsyncIteratorOptional   )InvalidResponseException)	TikTokApi   )Video)Userc                      e Zd ZU dZded<   ded<   	 ded<   	 ded<   	 d	ed
<   	 ded<   	 ded<   	 	 	 d	 	 	 ddZddZdddZd Zd Z	d Z
y)Playlistz
    A TikTok video playlist.

    Example Usage:
        .. code-block:: python

            playlist = api.playlist(id='7426714779919797038')
    zClassVar[TikTokApi]parentOptional[str]idnamezOptional[int]video_countzOptional[User]creator	cover_urldictas_dictNc                    ||j                  d      t        d      || _        ||| _        | j	                          yy)zw
        You must provide the playlist id or playlist data otherwise this
        will not function correctly.
        Nr   zYou must provide id parameter.)get	TypeErrorr   r   _Playlist__extract_from_data)selfr   datas      V/home/homepc/tiktok-worker/venv/lib/python3.12/site-packages/TikTokApi/api/playlist.py__init__zPlaylist.__init__$   sG     :$((4.0<==DL$$&     c                H  K   t        | dd      }|st        d      ||j                  d      d}| j                  j	                  d||j                  d      |j                  d      	       d{   }|t        |d
      |d   | _        | j                          |S 7 .w)a  
        Returns a dictionary of information associated with this Playlist.

        Returns:
            dict: A dictionary of information associated with this Playlist.

        Raises:
            InvalidResponseException: If TikTok returns an invalid response, or one we don't understand.

        Example Usage:
            .. code-block:: python

                user_data = await api.playlist(id='7426714779919797038').info()
        r   NzMYou must provide the playlist id when creating this class to use this method.ms_token)mixIdmsTokenz&https://www.tiktok.com/api/mix/detail/headerssession_indexurlparamsr&   r'   $TikTok returned an invalid response.mixInfo)getattrr   r   r   make_requestr	   r   r   )r   kwargsr   
url_paramsresps        r   infozPlaylist.info7   s       T4&_ 
 zz*-


 [[--8JJy) **_5	 . 
 
 <*41WXXI  "
s   A/B"1B 2/B"c                 K   t        | dd      }||dk(  r | j                  di | d{    d}||k  r|t        |d      |d}| j                  j	                  d||j                  d      |j                  d	      
       d{   }|t        |d      |j                  dg       D ]&  }| j                  j                  |       |dz  }( |j                  dd      sy|j                  d      }||k  ryy7 7 {w)a  
        Returns an iterator of videos in this User's playlist.

        Returns:
            Iterator[dict]: An iterator of videos in this User's playlist.

        Raises:
            InvalidResponseException: If TikTok returns an invalid response, or one we don't understand.

        Example Usage:
            .. code-block:: python

                playlist_videos = await api.playlist(id='7426714779919797038').videos()
        r   N r      )r$   countcursorz)https://www.tiktok.com/api/mix/item_list/r&   r'   r(   r+   itemListr   r   hasMoreFr7    )r-   r2   minr   r.   r   r	   video)	r   r6   r7   r/   r   foundr*   r1   r=   s	            r   videoszPlaylist.videos`   s$     T4&:r$))%f%%%emUB F 11?

9-$jj9	 2  D |.@  *b1 kk''U'33
 88Iu-XXh'F5 em &s)   *DDADD	A6D DDc                   | j                   }|j                         }d|v r|d   }|j                  dd       xs |j                  dd       | _        |j                  dd       xs |j                  dd       | _        |j                  dd       | _        | j                  j                  |j                  di             | _        |j                  d	d       | _	        d | j                  | j                  | j
                  | j                  | j                  fv r>t        j                  j                  j                  d
| d|j                                 y y )Nr,   r   r$   r   mixName
videoCountr   r9   coverz%Failed to create Playlist with data: z
which has keys )r   keysr   r   r   r   r   userr   r   r   loggererror)r   r   rD   s      r   __extract_from_datazPlaylist.__extract_from_data   s   ||yy{	?D((4&A$((7D*AHHVT*Gdhhy$.G	88L$7{{''TXXi-D'E'40DGGTYY(8(8$,,WWKK$$7v=Ntyy{m\ Xr!   c                "    | j                         S )N)__str__)r   s    r   __repr__zPlaylist.__repr__   s    ||~r!   c                (    t        | dd       }d| dS )Nr   zTikTokApi.playlist(id='z''))r-   )r   r   s     r   rJ   zPlaylist.__str__   s    T4&(C00r!   )NN)r   r   r   zOptional[dict])returnr   )r5   r   )rM   zAsyncIterator[Video])__name__
__module____qualname____doc____annotations__r    r2   r?   r   rK   rJ   r;   r!   r   r   r      s~      !
#*&(M5 !#'' '&'R.(`$1r!   r   N)
__future__r   typingr   r   r   r   
exceptionsr	   tiktokr
   r=   r   rE   r   r   r;   r!   r   <module>rW      s)    " C C 1"\1 \1r!   