U
    g                     @   sd   d dl Z ddlmZ ddlmZmZmZmZmZm	Z	m
Z
mZmZ G dd deZG dd	 d	eZdS )
    N   )InfoExtractor   )	ExtractorError
clean_htmlfloat_or_noneget_element_by_attributeget_element_by_classint_or_none
js_to_jsontraverse_objurl_or_nonec                
   @   s   e Zd ZdZddedddddd	d
ddigdgdddedddgdddedddgdddedddgdgZdd ZdS )AmazonStoreIEzghttps?://(?:www\.)?amazon\.(?:[a-z]{2,3})(?:\.[a-z]{2})?/(?:[^/]+/)?(?:dp|gp/product)/(?P<id>[^/&#$?]+)z'https://www.amazon.co.uk/dp/B098XNCHLD/Z
B098XNCHLD)idtitler   	info_dictZA1F83G8C2ARO7Pmp4zmcdodo usb c cable 100W 5are:^https?://.*\.jpg$"   )r   extr   	thumbnaildurationzUnable to extract data)urlr   playlist_mincountZplaylistexpected_warningszShttps://www.amazon.in/Sony-WH-1000XM4-Cancelling-Headphones-Bluetooth/dp/B0863TXGM3Z
B0863TXGM3   )r   r   r   r   z%https://www.amazon.com/dp/B0845NXCXF/Z
B0845NXCXF)r   r   zplaylist-mincountr   z^https://www.amazon.es/Samsung-Smartphone-s-AMOLED-Quad-c%C3%A1mara-espa%C3%B1ola/dp/B08WX337PQZ
B08WX337PQc                 C   s   |  |}|  D ]R}| ||}z| jd|d|td}W q tk
rb } z
||_W 5 d }~X Y qX qdd |dpxg D }| j|||ddS )	Nz%var\s?obj\s?=\s?jQuery\.parseJSON\(\'data)Ztransform_sourcec                 S   sl   g | ]d}| d r| dr|d |d | d| dpB| d| dt| dt| dd	qS )
ZisVideor   ZmarketPlaceIDr   ZthumbUrlZthumbZdurationSecondsZvideoHeightZ
videoWidth)r   r   r   r   r   heightwidth)getr
   ).0video r"   ;/tmp/pip-unpacked-wheel-q5ljy6pj/yt_dlp/extractor/amazon.py
<listcomp>K   s    
 
z/AmazonStoreIE._real_extract.<locals>.<listcomp>Zvideosr   )playlist_idZplaylist_title)		_match_idRetryManager_download_webpageZ_search_jsonr   r   errorr   Zplaylist_result)selfr   r%   retrywebpageZ	data_jsoneentriesr"   r"   r#   _real_extract?   s"    
   
	zAmazonStoreIE._real_extractN)__name__
__module____qualname__
_VALID_URLstr_TESTSr/   r"   r"   r"   r#   r      sN   			+r   c                   @   sp   e Zd ZdZdddddddd	d
dgddddddddd	d
dgddddddddd	d
dgdgZdd ZdS )AmazonReviewsIEz^https?://(?:www\.)?amazon\.(?:[a-z]{2,3})(?:\.[a-z]{2})?/gp/customer-reviews/(?P<id>[^/&#$?]+)zQhttps://www.amazon.com/gp/customer-reviews/R10VE9VUSY19L3/ref=cm_cr_arp_d_rvw_ttlZR10VE9VUSY19L3r   zGet squad #Suspiciousz$md5:7012695052f440a1e064e402d87e0afbzKimberly Cronkrightg      ?r   )r   r   r   descriptionuploaderaverage_ratingr   $Review body was not found in webpage)r   r   r   z`https://www.amazon.com/gp/customer-reviews/R10VE9VUSY19L3/ref=cm_cr_arp_d_rvw_ttl?language=es_USz8https://www.amazon.in/gp/customer-reviews/RV1CO8JN5VGXV/ZRV1CO8JN5VGXVzNot sure about its durabilityz$md5:1a252c106357f0a3109ebf37d2e87494zShoaib Gulzarg       @c                 C   s:  |  |}|  D ].}| ||}tdd|}|stddd|_qg i  }}| jd|dd d}t|r| j||d	d
d\}	}|	|	 | jd|dd d}
t|
r|
|
d	dd |s| jddd |ttdd|p| |tttd|dttd|tttdd|pddd | jd|dd d||dS )Nz	data-hookzreview-bodyr:   T)expectedzdata-video-url="([^"]+)"zm3u8 url)defaultr   F)fatalz4<input[^>]+\bvalue="([^"]+)"[^>]+\bclass="video-url"zmp4 urlzhttp-mp4)r   r   Z	format_idz'No video found for this customer reviewzreview-titlez<<span(?:\s+class="cr-original-review-content")?>(.+?)</span>za-profile-namezreview-star-rating  r   zdata-thumbnail-url="([^"]+)"r   )r   r   r7   r8   r9   r   formats	subtitles)r&   r'   r(   r   r   r)   Z_search_regexr   Z#_extract_m3u8_formats_and_subtitlesextendappendZraise_no_formatsr   Z_html_extract_titler   refindallr	   r   	partition)r*   r   Zvideo_idr+   r,   Zreview_bodyrA   rB   Zmanifest_urlZfmtsZ	video_urlr"   r"   r#   r/      s    

      

         zAmazonReviewsIE._real_extractN)r0   r1   r2   r3   r5   r/   r"   r"   r"   r#   r6   W   sH   			&r6   )rE   commonr   utilsr   r   r   r   r	   r
   r   r   r   r   r6   r"   r"   r"   r#   <module>   s   ,F