§
    šŠtjk  ã                   óÊ   — d dl Z d dlZd dlZd dlmZmZ d dlZd dlmZ d dl	m
Z
  ej        d¦  «        Z ej        d¦  «        Z ej        d¦  «        Z G d„ d	e
¦  «        ZdS )
é    N)ÚListÚTuple)ÚDocument)Ú
BaseLoaderzBV\w+zav[0-9]+zp=(\d+)c            	       óv   — e Zd ZdZ	 	 	 ddee         dededefd„Zdee         fd	„Zd
ede	ee
f         fd„ZdS )ÚBiliBiliLoaderz9
    Load fetching transcripts from BiliBili videos.
    Ú Ú
video_urlsÚsessdataÚbili_jctÚbuvid3c                 ó¾   — || _         d| _        	 ddlm} n# t          $ r t	          d¦  «        ‚w xY w|r#|r#|r#|                     |||¬¦  «        | _        dS dS dS dS )aö  
        Initialize the loader with BiliBili video URLs and authentication cookies.
        if no authentication cookies are provided, the loader can't get transcripts
        and will only fetch videos info.

        Args:
            video_urls (List[str]): List of BiliBili video URLs.
            sessdata (str): SESSDATA cookie value for authentication.
            bili_jct (str): BILI_JCT cookie value for authentication.
            buvid3 (str): BUVI3 cookie value for authentication.
        Nr   )ÚvideoúTrequests package not found, please install it with `pip install bilibili-api-python`)r   r   r   )r
   Ú
credentialÚbilibili_apir   ÚImportErrorÚ
Credential)Úselfr
   r   r   r   r   s         úk/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/langchain_community/document_loaders/bilibili.pyÚ__init__zBiliBiliLoader.__init__   s»   € ð$ %ˆŒØˆŒð	Ø*Ð*Ð*Ð*Ð*Ð*Ð*øÝð 	ð 	ð 	Ýð4ñô ð ð	øøøð
 ð 	˜ð 	 Vð 	Ø#×.Ò.Ø!¨H¸Vð /ñ ô ˆDŒOˆOˆOð	ð 	ð 	ð 	ð 	ð 	s   � —1Úreturnc                 óš   — g }| j         D ]@}|                      |¦  «        \  }}t          ||¬¦  «        }|                     |¦  «         ŒA|S )z´
        Load and return a list of documents containing video transcripts.

        Returns:
            List[Document]: List of Document objects transcripts and metadata.
        )Úpage_contentÚmetadata)r
   Ú_get_bilibili_subs_and_infor   Úappend)r   ÚresultsÚurlÚ
transcriptÚ
video_infoÚdocs         r   ÚloadzBiliBiliLoader.load6   s^   € ð ˆØ”?ð 	 ð 	 ˆCØ%)×%EÒ%EÀcÑ%JÔ%JÑ"ˆJ˜
Ý¨
¸ZÐHÑHÔHˆCØ�NŠN˜3ÑÔÐÐàˆó    r   c                 ó`  — t                                |¦  «        }	 ddlm}m} n# t
          $ r t          d¦  «        ‚w xY w|r/|                     |                     ¦   «         | j        ¬¦  «        }nrt                               |¦  «        }|rD|                     t          |                     ¦   «         dd…         ¦  «        | j        ¬¦  «        }nt          d|› �¦  «        ‚ ||                     ¦   «         ¦  «        }|                     d	|i¦  «         | j        sd
|fS d}t                               |¦  «        }	|	r8|d         t          |	                     d¦  «        ¦  «        dz
           d         }n|d         } ||                     |¦  «        ¦  «        }
|
                     dg ¦  «        }|rÜ|d                              dd
¦  «        }|                     d¦  «        sd|z   }t%          j        |¦  «        }|j        dk    rgt)          j        |j        ¦  «                             dg ¦  «        }d                     d„ |D ¦   «         ¦  «        }d|d         › d|d         › d|› �}||fS t1          j        d|› d|j        › �¦  «         nt1          j        d|› d�¦  «         d
|fS )zU
        Retrieve video information and transcript for a given BiliBili URL.
        r   )Úsyncr   r   )Úbvidr   é   N)Úaidr   z(Unable to find a valid video ID in URL: r   r	   Úpagesé   ÚcidÚ	subtitlesÚsubtitle_urlÚhttpzhttps:éÈ   Úbodyú c                 ó   — g | ]
}|d          ‘ŒS )Úcontent© )Ú.0Úcs     r   ú
<listcomp>z>BiliBiliLoader._get_bilibili_subs_and_info.<locals>.<listcomp>u   s   € Ð*PÐ*PÐ*P¸A¨1¨Y¬<Ð*PÐ*PÐ*Pr$   zVideo Title: Útitlez, description: Údescz

Transcript: zFailed to fetch subtitles for z. HTTP Status Code: zNo subtitles found for video: z. Returning empty transcript.)Ú
BV_PATTERNÚsearchr   r&   r   r   ÚVideoÚgroupr   Ú
AV_PATTERNÚintÚ
ValueErrorÚget_infoÚupdateÚPAGE_INDEX_PATTERNÚget_subtitleÚgetÚ
startswithÚrequestsÚstatus_codeÚjsonÚloadsr4   ÚjoinÚwarningsÚwarn)r   r   r'   r&   r   Úvr)   r!   r,   Ú
page_matchÚsubÚsub_listÚsub_urlÚresponseÚraw_sub_titlesÚraw_transcriptÚraw_transcript_with_meta_infos                    r   r   z*BiliBiliLoader._get_bilibili_subs_and_infoE   s"  € õ × Ò  Ñ%Ô%ˆð	Ø0Ð0Ð0Ð0Ð0Ð0Ð0Ð0Ð0øÝð 	ð 	ð 	Ýð4ñô ð ð	øøøð
 ð 	SØ—’ §¢¡¤¸$¼/�ÑJÔJˆAˆAå×#Ò# CÑ(Ô(ˆCØð SØ—K’K¥C¨¯	ª	©¬°A°B°B¬Ñ$8Ô$8ÀTÄ_�KÑUÔU��å Ð!QÈCÐ!QÐ!QÑRÔRÐRà�T˜!Ÿ*š*™,œ,Ñ'Ô'ˆ
Ø×Ò˜5 #˜,Ñ'Ô'Ð'ð Œð 	"Ø�z�>Ð!àˆÝ'×.Ò.¨sÑ3Ô3ˆ
Øð 	$Ø˜WÔ%¥c¨*×*:Ò*:¸1Ñ*=Ô*=Ñ&>Ô&>ÀÑ&BÔCØôˆCˆCð ˜UÔ#ˆCð ˆd�1—>’> #Ñ&Ô&Ñ'Ô'ˆØ—7’7˜;¨Ñ+Ô+ˆØð 	Ø˜q”k—o’o n°bÑ9Ô9ˆGØ×%Ò% fÑ-Ô-ð -Ø" WÑ,�å”| GÑ,Ô,ˆHØÔ# sÒ*Ð*Ý!%¤¨HÔ,<Ñ!=Ô!=×!AÒ!AÀ&È"Ñ!MÔ!M�Ø!$§¢Ð*PÐ*PÀÐ*PÑ*PÔ*PÑ!QÔ!Q�ð4 J¨wÔ$7ð 4ð 4Ø$.¨vÔ$6ð4ð 4à#1ð4ð 4ð .ð
 5°jÐ@Ð@å”ð@°Sð @ð @Ø)1Ô)=ð@ð @ñô ð ð õ
 ŒMØS°ÐSÐSÐSñô ð ð
 �:ˆ~Ðs   œ% ¥?N)r	   r	   r	   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ústrr   r   r#   r   Údictr   r5   r$   r   r   r      s¿   € € € € € ðð ð ØØðð à˜”Iðð ðð ð	ð
 ðð ð ð ð@�d˜8”nð ð ð ð ðC¨sð C°u¸SÀ$¸YÔ7Gð Cð Cð Cð Cð Cð Cr$   r   )rJ   ÚrerM   Útypingr   r   rH   Úlangchain_core.documentsr   Ú)langchain_community.document_loaders.baser   Úcompiler;   r?   rD   r   r5   r$   r   ú<module>rc      sÙ   ðØ €€€Ø 	€	€	€	Ø €€€Ø Ð Ð Ð Ð Ð Ð Ð à €€€Ø -Ð -Ð -Ð -Ð -Ð -à @Ð @Ð @Ð @Ð @Ð @ð ˆRŒZ˜Ñ!Ô!€
ØˆRŒZ˜Ñ$Ô$€
Ø�R”Z 
Ñ+Ô+Ð ðwð wð wð wð w�Zñ wô wð wð wð wr$   