U
    g2H                     @   s   d dl Z d dlZd dlZ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 ddlmZ G dd deZG d	d
 d
eZdS )    N   )InfoExtractor   )	ExtractorErrordetermine_extfilter_dict	get_firstint_or_noneparse_iso8601
update_urlurl_or_nonevariadic)traverse_objc                   @   sX  e Zd ZdZdZde dgZddddd	d
ddddddddddddddddddddddddd d!d"d#	dd$d%dd&d'd(d)d*d+d,d-d.id/d0d1d2dd3d4d5d6d7dd8d9id:d;d<d=dd>d?d@dAdBddCdDidEgdFgZdGdHdIddJdKdLdMdNdOdgZdPdQdRdSdTgiiZe	
dUe	
dVe	
dWe	
dXdYZdZZddd\d]Zd^d_ Zd`da Zdbdc Zd[S )eLoomIEZloomz@https?://(?:www\.)?loom\.com/(?:share|embed)/(?P<id>[\da-f]{32})z<iframe[^>]+\bsrc=["\'](?P<url>)z;https://www.loom.com/share/43d05f362f734614a2e81b4694a3a523Z bfc2d7e9c2e0eb4813212230794b6f42Z 43d05f362f734614a2e81b4694a3a523mp4z#A Ruler for Windows - 28 March 2022zwILLIAM PIPZ20220328i^jAb   )idexttitleuploaderupload_date	timestampduration)urlmd5	info_dictz;https://www.loom.com/share/c43a642f815f4378b6f80a889bb73d8dZ 70f529317be8cf880fcc2c649a531900Z c43a642f815f4378b6f80a889bb73d8dZwebmzLilah Nielsen Intro VideozLilah NielsenZ20200826iLF_   z;https://www.loom.com/share/9458bcbf79784162aa62ffb8dd66201bZ 51737ec002969dd28344db4d60b9cbbbZ 9458bcbf79784162aa62ffb8dd66201bzSharing screen with gpt-4zUSharing screen with GPT 4 vision model and asking questions to guide through blender.zSuneel Mathamzcount:3Z20231109iLe]   )	r   r   r   descriptionr   chaptersr   r   r   z;https://www.loom.com/share/24351eb8b317420289b158e4b7e96ff2Z 24351eb8b317420289b158e4b7e96ff2z
OMFG clownz$md5:285c5ee9d62aa087b7e3271b08796815z
MrPumkin BZ20210924iENa   )r   r   r   r   r   r   r   r   Zskip_downloadZdash)r   r   paramsz;https://www.loom.com/share/50e26e8aeb7940189dff5630f95ce1f4Z 5cc7655e7d55d281d203f8ffd14771f7Z 50e26e8aeb7940189dff5630f95ce1f4ziOS Mobile UploadzSimon CurranZ20200520iy^#   videopasswordZseniorinfants2)r   r   r   r"   z;https://www.loom.com/embed/ddcf1c1ad21f451ea7468b1e33917e4eZ b321d261656848c184a94e3b93eae28dZ ddcf1c1ad21f451ea7468b1e33917e4ezCF Reset User's PasswordzAimee HeintzZ20220707ib   formatZ	bestvideozFailed to parse JSON)r   r   r   r"   Zexpected_warningszBhttps://www.loom.com/community/e1229802a8694a09909e8ba0fbb6d073-pgZ ec838cd01b576cf0386f32e1ae424609Z e1229802a8694a09909e8ba0fbb6d073z.Rexie Jane Cimafranca - Founder's PresentationzRexie CimafrancaZ20230213   inc)r   r   r   r   r   r   r   GetVideoSourceZacceptableMimesZDASHZM3U8ZMP4a              query GetVideoSSR($videoId: ID!, $password: String) {
              getVideo(id: $videoId, password: $password) {
                __typename
                ... on PrivateVideo {
                  id
                  status
                  message
                  __typename
                }
                ... on VideoPasswordMissingOrIncorrect {
                  id
                  message
                  __typename
                }
                ... on RegularUserVideo {
                  id
                  __typename
                  createdAt
                  description
                  download_enabled
                  folder_id
                  is_protected
                  needs_password
                  owner {
                    display_name
                    __typename
                  }
                  privacy
                  s3_id
                  name
                  video_properties {
                    avgBitRate
                    client
                    camera_enabled
                    client_version
                    duration
                    durationMs
                    format
                    height
                    microphone_enabled
                    os
                    os_version
                    recordingClient
                    recording_type
                    recording_version
                    screen_type
                    tab_audio
                    trim_duration
                    width
                    __typename
                  }
                  playable_duration
                  source_duration
                  visibility
                }
              }
            }
a              query GetVideoSource($videoId: ID!, $password: String, $acceptableMimes: [CloudfrontVideoAcceptableMime]) {
              getVideo(id: $videoId, password: $password) {
                ... on RegularUserVideo {
                  id
                  nullableRawCdnUrl(acceptableMimes: $acceptableMimes, password: $password) {
                    url
                    __typename
                  }
                  __typename
                }
                __typename
              }
            }
a              query FetchVideoTranscript($videoId: ID!, $password: String) {
              fetchVideoTranscript(videoId: $videoId, password: $password) {
                ... on VideoTranscriptDetails {
                  id
                  video_id
                  source_url
                  captions_source_url
                  __typename
                }
                ... on GenericError {
                  message
                  __typename
                }
                __typename
              }
            }
a              query FetchChapters($videoId: ID!, $password: String) {
              fetchVideoChapters(videoId: $videoId, password: $password) {
                ... on VideoChapters {
                  video_id
                  content
                  __typename
                }
                ... on EmptyChaptersPayload {
                  content
                  __typename
                }
                ... on InvalidRequestWarning {
                  message
                  __typename
                }
                ... on Error {
                  message
                  __typename
                }
                __typename
              }
            }
)GetVideoSSRr(   FetchVideoTranscriptFetchChaptersZ0a1856cNc                    sb    d jd|pd|pddddj djdtj fd	d
t|D dd dS )Nr$   zhttps://www.loom.com/graphqlzDownloading GraphQL JSONzFailed to download GraphQL JSONapplication/jsonZ	loom_web_Zweb)AcceptContent-Typezx-loom-request-sourcezapollographql-client-namezapollographql-client-versionc                    s2   g | ]*}| d j |i j| dqS ))ZvideoIdpassword)ZoperationName	variablesquery)_GRAPHQL_VARIABLESget_GRAPHQL_QUERIES).0Zoperation_namer/   selfvideo_id 9/tmp/pip-unpacked-wheel-q5ljy6pj/yt_dlp/extractor/loom.py
<listcomp>   s   z,LoomIE._call_graphql_api.<locals>.<listcomp>,:
separators)headersdata)	get_param_download_json_APOLLO_GRAPHQL_VERSIONjsondumpsr   encode)r7   
operationsr8   ZnoteZerrnoter9   r6   r:   _call_graphql_api   s$    
  
zLoomIE._call_graphql_apic                 C   sp   | j d| d| |d| dd| dddddtjtt d d| d	d
dd d}t|dt	hfS )Nz,https://www.loom.com/api/campaigns/sessions//zDownloading z JSONzFailed to download Fr,   )r-   r.   r$   )ZanonIDZdeviceIDZforce_originalr/   r<   r?   )fatalrA   rB   r   )
rD   rF   rG   struuidZuuid4rC   rH   r   r   )r7   Zendpointr8   responser9   r9   r:   _call_url_api	  s"     
 
 

zLoomIE._call_url_apic           
         s   g }t |ddthfdthfddd hfdf fdd	} d
}|||ddd  d}|||ddd t|ddddthf}dd ||fD }	|rt|d d|	kr|||ddd |S )Nvideo_propertieswidthheightZmicrophone_enabledc                 S   s   | dkrdS d S )NFnoner9   )xr9   r9   r:   <lambda>      z)LoomIE._extract_formats.<locals>.<lambda>)rR   rS   acodecc           	      3   s   | sd S t | }tj| j}|dkr| dd}  j| dd| d|d}dt|d	k}|D ]:}|r~|d
dkr~d|d< |t	|d |d|dV  q`nV|dkrڈ j
| d| dd}|D ]}|||dV  qn| |d| |dV  d S )NZm3u8z-split.m3u8z.m3u8r   zhls-F)Zm3u8_idrL   qualityrT   ).vcodecrZ   rX   r   r1   )r   extra_param_to_segment_urlZmpdzdash-)Zmpd_idrL   )r\   rY   zhttp-)r   r   	format_idrY   )r   urllibparseurlparser1   replaceZ_extract_m3u8_formatsr   r3   r   Z_extract_mpd_formats)	Z
format_urlr]   rY   r   r1   Zm3u8_formatsZis_not_premergedfmtZdash_formatsr7   r8   rQ   r9   r:   get_formats  sR            z,LoomIE._extract_formats.<locals>.get_formatszraw-urlrawr   )rY   ztranscoded-urlZ
transcodedrB   getVideoZnullableRawCdnUrlr   c                 S   s   g | ]}|rt |d dqS )Nr[   )r   )r5   r   r9   r9   r:   r;   O  s      z+LoomIE._extract_formats.<locals>.<listcomp>r[   Zcdnr   )r   r	   rP   extendr   r   r   )
r7   r8   metadatagql_dataformatsrd   Zraw_urlZtranscoded_urlZcdn_urlZ
valid_urlsr9   rc   r:   _extract_formats  s     
)zLoomIE._extract_formatsc                 C   s  |  |}t| d|dddthfp(i }|ddkrZ| dsNtdd	d
tdd	d
| dddg|}t|ddthf}||| 	t|dddt
hf|pd | |||tdt|dddddthifpd idt|dt
hfdt
hfddt
hfdthfdS )Nr)   z!Downloading GraphQL metadata JSONrB   rg   Z
__typenameZVideoPasswordMissingOrIncorrectr$   zAThis video is password-protected, use the --video-password optionT)expectedzInvalid video passwordr+   r*   r(   rQ   r   ZfetchVideoChapterscontenten.ZfetchVideoTranscript)
source_urlZcaptions_source_urlr   )r   r   r    rk   Z	subtitlesnamer   ownerZdisplay_nameZ	createdAt)r   r   r   r   )	_match_idr   rJ   dictr3   rC   r   r   r	   Z"_extract_chapters_from_descriptionrM   rl   r   r   r
   )r7   r   r8   ri   rj   r   r9   r9   r:   _real_extractU  sZ    


      
zLoomIE._real_extract)NN)__name__
__module____qualname__IE_NAME
_VALID_URLZ_EMBED_REGEX_TESTSZ_WEBPAGE_TESTSr2   textwrapdedentr4   rE   rJ   rP   rl   ru   r9   r9   r9   r:   r      s   
		V :r
?r   c                   @   s   e Zd ZdZdZddddddd	d
dddddddddddddddddddddddddddddddd ddd!d"d#gZd$d% Zd+d'd(Zd)d* Zd&S ),LoomFolderIEzloom:folderz=https?://(?:www\.)?loom\.com/share/folder/(?P<id>[\da-f]{32})zBhttps://www.loom.com/share/folder/997db4db046f43e5912f10dc5f817b5c   Z 997db4db046f43e5912f10dc5f817b5czBlending Lessons)r   r   )r   Zplaylist_mincountr   zBhttps://www.loom.com/share/folder/9a8a87f6b6f546d9a400c8e7575ff7f2   Z 9a8a87f6b6f546d9a400c8e7575ff7f2zList A- a, i, ozBhttps://www.loom.com/share/folder/886e534218c24fd292e97e9563078cc4   Z 886e534218c24fd292e97e9563078cc4zMedicare Agent Training videoszBhttps://www.loom.com/share/folder/b72c4ecdf04745da9403926d80a40c38Z b72c4ecdf04745da9403926d80a40c38zQuick Altos Q & A TutorialszBhttps://www.loom.com/share/folder/8b458a94e0e4449b8df9ea7a68fafc4e   Z 8b458a94e0e4449b8df9ea7a68fafc4ezSezer Texting Guide)r   Zplaylist_countr   zBhttps://www.loom.com/share/folder/e056a91d290d47ca9b00c9d1df56c463=   Z e056a91d290d47ca9b00c9d1df56c463zUser VideoszBhttps://www.loom.com/share/folder/c2dde8cc67454f0e99031677279d8954K   Z c2dde8cc67454f0e99031677279d8954zHonors 1zKhttps://www.loom.com/share/folder/bae17109a68146c7803454f2893c8cf8/EdpuzzleT)r   Zonly_matchingc                 C   s   | j d| |dddidS )Nz https://www.loom.com/v1/folders/zDownloading folder info JSONlimitZ10000r[   )rD   )r7   	folder_idr9   r9   r:   _extract_folder_data  s      z!LoomFolderIE._extract_folder_dataNc              	   #   s   |p|   }t|ddd fD ]*}|d }| d| t||dV  q t|d fdddthfD ]}| |E d H  qhd S )	NZvideosc                 S   s   |d S Nr   r9   _vr9   r9   r:   rV     rW   z6LoomFolderIE._extract_folder_entries.<locals>.<lambda>r   zhttps://www.loom.com/share/rq   foldersc                    s   |d  kS r   r9   r   r   r9   r:   rV     rW   )r   r   Z
url_resultr   r3   rM   _extract_folder_entries)r7   r   Zinitial_folder_dataZfolder_datavideor8   Zsubfolder_idr9   r   r:   r     s         
  
z$LoomFolderIE._extract_folder_entriesc              	   C   s:   |  |}| |}| | |||t|ddtjhfS )Nfolderrq   )rs   r   Zplaylist_resultr   r   rM   strip)r7   r   Zplaylist_idZplaylist_datar9   r9   r:   ru     s    


 zLoomFolderIE._real_extract)N)	rv   rw   rx   ry   rz   r{   r   r   ru   r9   r9   r9   r:   r~   z  sf   





	=
r~   )rF   r|   urllib.parser^   rN   commonr   utilsr   r   r   r   r	   r
   r   r   r   Zutils.traversalr   r   r~   r9   r9   r9   r:   <module>   s   ,  g