U
    {hX                  	   @   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dddgdddddddddg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   g/var/www/dating/data/www/fatepal.com/env/lib/python3.8/site-packages/wagtail/embeds/finders/facebook.pyr      s   r   z-https://graph.facebook.com/v11.0/oembed_videoz/^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_postz;^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   s`  |  |}|d k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k
r } z<t|t
r|jdkrtnt|t
r|jdkrtntW 5 d }~X Y nX t| d}	d|	kr
|	d ndd|	kr|	d ndd|	kr2|	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_width
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>   s4   
;