a
    DgX                     @   s   d dl Z d dlmZ d dlmZmZ d dlmZ d dl	m
Z
 d dlmZmZ ddlmZ G d	d
 d
eZdg dddg ddgZG dd deZeZdS )    N)request)	HTTPErrorURLError)	urlencode)Request)EmbedExceptionEmbedNotFoundException   )OEmbedFinderc                   @   s   e Zd ZdS )#AccessDeniedFacebookOEmbedExceptionN)__name__
__module____qualname__ r   r   ^/var/www/lab.imftr.de/x/nb_venv/lib/python3.9/site-packages/wagtail/embeds/finders/facebook.pyr      s   r   z-https://graph.facebook.com/v11.0/oembed_video)z/^https://(?:www\.)?facebook\.com/.+?/videos/.+$z9^https://(?:www\.)?facebook\.com/video\.php\?(?:v|id)=.+$z^https://fb.watch/.+$)endpointurlsz,https://graph.facebook.com/v11.0/oembed_post)z;^https://(?:www\.)?facebook\.com/.+?/(?:posts|activity)/.+$z5^https://(?:www\.)?facebook\.com/photo\.php\?fbid=.+$z9^https://(?:www\.)?facebook\.com/(?:photos|questions)/.+$z?^https://(?:www\.)?facebook\.com/permalink\.php\?story_fbid=.+$z5^https://(?:www\.)?facebook\.com/media/set/?\?set=.+$z2^https://(?:www\.)?facebook\.com/notes/.+?/.+?/.+$z/^https://(?:www\.)?facebook\.com/.+?/photos/.+$c                       s,   e Zd ZdZd fdd	Zd	ddZ  ZS )
FacebookOEmbedFinderz
    An embed finder that supports the authenticated Facebook oEmbed Endpoint.
    https://developers.facebook.com/docs/plugins/oembed
    FNc                    s$   || _ || _|| _t jtd d S )N)	providers)app_id
app_secret
omitscriptsuper__init__FACEBOOK_PROVIDERS)selfr   r   r   	__class__r   r   r   2   s    zFacebookOEmbedFinder.__init__c           
   
   C   sb  |  |}|d u rt|dd}|r,||d< |r8||d< | jrFd|d< t|d t| }|dd	| j d
| j  zt	|}W n` t
tfy } zDt|t
r|jdkrtnt|t
r|jdv rtntW Y d }~n
d }~0 0 t| d}	d|	v r|	d ndd|	v r |	d ndd|	v r4|	d nd|	d |	d|	d|	d|	ddS )Njson)urlformatZmaxwidthZ	maxheighttruer   ?AuthorizationzBearer |i  )i  i  i  zutf-8title author_nameprovider_nameZFacebooktypethumbnail_urlwidthheighthtml)r%   r'   r(   r)   r*   r+   r,   r-   )Z_get_endpointr   r   r   r   
add_headerr   r   urllib_requesturlopenr   r   
isinstancecoder   r   loadsreaddecodeget)
r   r   	max_widthZ
max_heightr   paramsr   reoembedr   r   r   
find_embed:   s@    

zFacebookOEmbedFinder.find_embed)FNN)NN)r   r   r   __doc__r   r<   __classcell__r   r   r   r   r   ,   s   r   )r   urllibr   r/   urllib.errorr   r   urllib.parser   urllib.requestr   Zwagtail.embeds.exceptionsr   r   r;   r
   r   r   r   Zembed_finder_classr   r   r   r   <module>   s    
;