
    ukiK                         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 ddlmZ  G d de      Z G d	 d
e      Zy)    N   )InfoExtractor   )ExtractorErrordetermine_extfilter_dictint_or_noneparse_iso8601
update_urlurl_or_none)traverse_objc                      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/gd0d1d2d3dd4d5d6d7d8dd9d:id/gd;d<d=d>dd?d@dAdBdCddDdEid/gd;gZdFdGdHddIdJdKdLdMdNdOdPgZdQdRg dSiiZ e	j                  dT       e	j                  dU       e	j                  dV       e	j                  dW      dXZdYZd`d[Zd\ Zd] Zd^ Zd_ ZyZ)aLoomIEloomz@https?://(?:www\.)?loom\.com/(?:share|embed)/(?P<id>[\da-f]{32})z<iframe[^>]+\bsrc=["\'](?P<url>)z;https://www.loom.com/share/43d05f362f734614a2e81b4694a3a523 bfc2d7e9c2e0eb4813212230794b6f42 43d05f362f734614a2e81b4694a3a523mp4z#A Ruler for Windows - 28 March 2022zwILLIAM PIP20220328i^jAb   )idexttitleuploaderupload_date	timestampduration)urlmd5	info_dictz;https://www.loom.com/share/c43a642f815f4378b6f80a889bb73d8d 70f529317be8cf880fcc2c649a531900 c43a642f815f4378b6f80a889bb73d8dwebmzLilah Nielsen Intro VideozLilah Nielsen20200826iLF_   z;https://www.loom.com/share/9458bcbf79784162aa62ffb8dd66201b 7b6bfdef8181c4ffc376e18919a4dcc2 9458bcbf79784162aa62ffb8dd66201bzSharing screen with gpt-4zUSharing screen with GPT 4 vision model and asking questions to guide through blender.zSuneel Mathamzcount:320231109iLe]   )	r   r   r   descriptionr   chaptersr   r   r   z;https://www.loom.com/share/24351eb8b317420289b158e4b7e96ff2 24351eb8b317420289b158e4b7e96ff2z
OMFG clownz$md5:285c5ee9d62aa087b7e3271b08796815zBrailey Bragg20210924iENa   )r   r   r   r*   r   r   r   r   skip_downloaddashzFailed to parse JSON)r   r    paramsexpected_warningsz;https://www.loom.com/share/50e26e8aeb7940189dff5630f95ce1f4 5cc7655e7d55d281d203f8ffd14771f7 50e26e8aeb7940189dff5630f95ce1f4ziOS Mobile UploadzSimon Curran20200520iy^#   videopasswordseniorinfants2)r   r   r    r1   r2   z;https://www.loom.com/embed/ddcf1c1ad21f451ea7468b1e33917e4e f983a0f02f24331738b2f43aecb05256 ddcf1c1ad21f451ea7468b1e33917e4ezCF Reset User's PasswordzAimee Heintz20220707ib   format	bestvideozBhttps://www.loom.com/community/e1229802a8694a09909e8ba0fbb6d073-pg ec838cd01b576cf0386f32e1ae424609 e1229802a8694a09909e8ba0fbb6d073z.Rexie Jane Cimafranca - Founder's PresentationzRexie Cimafranca20230213   inc)r   r   r   r   r   r   r   z404 Not Found)r   r   r    skipGetVideoSourceacceptableMimes)DASHM3U8MP4WEBMa              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
                    credentials {
                      Policy
                      Signature
                      KeyPairId
                      __typename
                    }
                    __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
              }
            }
)GetVideoSSRrD   FetchVideoTranscriptFetchChapters45a5bd4Nc                 H   | j                  d      }| j                  d||xs d|xs dddd| j                   d| j                  |dd	t        j                  |||d
| j
                  j                  |i       | j                  |   dd      j                         |      S )Nr7   zhttps://www.loom.com/graphqlzDownloading GraphQL JSONzFailed to download GraphQL JSONapplication/json	loom_web_webzhttps://www.loom.com)AcceptContent-Typezx-loom-request-sourcezapollographql-client-namezapollographql-client-versionzgraphql-operation-nameOrigin)videoIdpassword)operationName	variablesquery,:
separators)headersdatafatal)		get_param_download_json_APOLLO_GRAPHQL_VERSIONjsondumps_GRAPHQL_VARIABLESget_GRAPHQL_QUERIESencode)selfoperation_namevideo_idnoteerrnotera   rV   s          P/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/yt_dlp/extractor/loom.py_call_graphql_apizLoomIE._call_graphql_api   s    >>/2""*Hd6X>X88, 2+4T5Q5Q4R)S-2040L0L*80C JJ!/' ( --11."E
 ..~>  %& '-fhe% # = 	=    c                    | j                  d| d| |d| dd| dddddt        j                  t        t	        j
                               d d| j                  d	      d
d      j                               }t        |dt        hf      S )Nz,https://www.loom.com/api/campaigns/sessions//zDownloading z JSONzFailed to download FrO   )rR   rS   r7   )anonIDdeviceIDforce_originalrV   rZ   r]   )ra   r_   r`   r   )
rc   re   rf   struuiduuid4rb   rj   r   r   )rk   endpointrm   responses       rp   _call_url_apizLoomIE._call_url_api  s    &&:8*AhZPRZ8*E*.A(5,QY^1CUVdjjl+ "' NN?;	
 %&
 '-fh ' 	0 Hu{m&<==rr   c                     g }t        |ddt        hfdt        hfdd hfdf       fd} j                  d      }|j                   ||d	d
              j                  d      }|j                   ||dd             t        |ddddt        hf      }||fD 	cg c]  }	|	st        |	d        }
}	|r)t        |d       |
vr|j                   ||dd             |S c c}	w )Nvideo_propertieswidthheightmicrophone_enabledc                     | du rdS d S )NFnone )xs    rp   <lambda>z)LoomIE._extract_formats.<locals>.<lambda>$  s    !u* RV rr   )r   r   acodecc              3     K   | sy t        |       }t        j                  j                  |       j                  }|dk(  rv| j                  dd      } 	j                  | 
dd| d|      }dt        |d	      v }|D ]6  }|r|j                  d
      dk7  rd|d<   i |t        |d   |      |d 8 y |dk(  r+	j                  | 
d| d      }|D ]  }i |||d  y | |d| |d y w)Nm3u8z-split.m3u8z.m3u8r   zhls-F)m3u8_idra   qualityr   ).vcodecr   r   r   rY   )r   extra_param_to_segment_urlmpdzdash-)mpd_idra   )r   r   zhttp-)r   r   	format_idr   )r   urllibparseurlparserY   replace_extract_m3u8_formatsr   rh   r   _extract_mpd_formats)
format_urlr   r   r   rY   m3u8_formatsis_not_premergedfmtdash_formatsrk   rm   r   s            rp   get_formatsz,LoomIE._extract_formats.<locals>.get_formats'  sa    
+CLL))*5;;Ef}'//wG
#99%4	{9KSXbi  :  k $*\,-X#X ' C'CGGH,=,G(.H)#e*EB6;  #8851DE  9  S' C6;#*  &#(!4&	
 ' s   C2C5zraw-urlrawr   )r   ztranscoded-url
transcodedr`   getVideonullableRawCdnUrlr   r   cdnr   )r   r	   r}   extendr   r   )rk   rm   metadata
video_dataformatsr   raw_urltranscoded_urlcdn_urlr   
valid_urlsr   s   ``         @rp   _extract_formatszLoomIE._extract_formats  s
   '3E}-+/+.V-WXH
 3 '	R $$Y9{7E1=>++,<hG{><LMzFJ@SUZ]h\i+jk>E~=V^cZ]jD1^
^z'6jHNN;wqAB	 _s   %C+-C+c                 x    | j                  d|dd      }t        dt        |dddd	t        hif      xs d i      S )
NrK   z"Downloading GraphQL subtitles JSONFra   enr`   fetchVideoTranscript)
source_urlcaptions_source_urlr   )rq   r   r   r   )rk   rm   	subs_datas      rp   _get_subtitleszLoomIE._get_subtitles^  se    **"H.RZ_ + a	,y.5K=8+   
  	rr   c                 j   | j                  |      }t        | j                  d|dd      ddt        hf      xs i }|j	                  d      dk(  r+| j                  d	      st        d
d      t        dd      | j                  d|d      }| j                  d|dd      }t        |ddt        hf      }||| j                  t        |dddt        hf      |      xs d | j                  |||      | j                  |      dt        |dt        hfdt        hfddt        hfdt        hfd      S )NrJ   z!Downloading GraphQL metadata JSONFr   r`   r   
__typenameVideoPasswordMissingOrIncorrectr7   zAThis video is password-protected, use the --video-password optionT)expectedzInvalid video passwordrD   zDownloading GraphQL video JSONrL   z!Downloading GraphQL chapters JSONr   r   fetchVideoChapterscontent)r   r   r+   r   	subtitlesnamer*   ownerdisplay_name	createdAt)r   r*   r   r   )	_match_idr   rq   dictrh   rb   r   r	   "_extract_chapters_from_descriptionrx   r   extract_subtitlesr
   )rk   r   rm   r   r   chapter_datar   s          rp   _real_extractzLoomIE._real_extracti  s   >>#&""=(<_gl"mZ$(* 0-/ 	 <<%)JJ>>/2$Wbfh h !9DII++h(HJ
--X'JRW . Y+=zK=*YZ  ??\F4H)VYUZ+[\^fh pko,,XxL//9
 8 3% -u5$nse<)M?;	& 
 	
rr   )NNT)__name__
__module____qualname__IE_NAME
_VALID_URL_EMBED_REGEX_TESTS_WEBPAGE_TESTSrg   textwrapdedentri   rd   rq   r}   r   r   r   r   rr   rp   r   r      s   GTJ6zl!DEL M14:%%#
	 M140'%#
	 M140r'!%#

	" M4!A'%#	
 #F+45" M14(&%#
 #$4545" M140&%#
 [)45OVFp T14F*%#
   N  	>
 'x 9( 9t *(// + ( !0 1 !" ) * Awp (=,>=~	
rr   r   c                       e Zd 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% Zd)d'Zd( Z	y&)*LoomFolderIEFzloom:folderz=https?://(?:www\.)?loom\.com/share/folder/(?P<id>[\da-f]{32})zBhttps://www.loom.com/share/folder/997db4db046f43e5912f10dc5f817b5c    997db4db046f43e5912f10dc5f817b5czBlending Lessons)r   r   )r   playlist_mincountr    zBhttps://www.loom.com/share/folder/9a8a87f6b6f546d9a400c8e7575ff7f2    9a8a87f6b6f546d9a400c8e7575ff7f2zList A- a, i, ozBhttps://www.loom.com/share/folder/886e534218c24fd292e97e9563078cc4    886e534218c24fd292e97e9563078cc4zMedicare Agent Training videoszBhttps://www.loom.com/share/folder/b72c4ecdf04745da9403926d80a40c38 b72c4ecdf04745da9403926d80a40c38zQuick Altos Q & A TutorialszBhttps://www.loom.com/share/folder/8b458a94e0e4449b8df9ea7a68fafc4e    8b458a94e0e4449b8df9ea7a68fafc4ezSezer Texting Guide)r   playlist_countr    zBhttps://www.loom.com/share/folder/e056a91d290d47ca9b00c9d1df56c463=    e056a91d290d47ca9b00c9d1df56c463zUser VideoszBhttps://www.loom.com/share/folder/c2dde8cc67454f0e99031677279d8954K    c2dde8cc67454f0e99031677279d8954zHonors 1zKhttps://www.loom.com/share/folder/bae17109a68146c7803454f2893c8cf8/EdpuzzleT)r   only_matchingc                 6    | j                  d| |dddi      S )Nz https://www.loom.com/v1/folders/zDownloading folder info JSONlimit10000r   )rc   )rk   	folder_ids     rp   _extract_folder_dataz!LoomFolderIE._extract_folder_data  s2    "".yk:I*7G2D # F 	Frr   Nc           	   #   2  K   |xs | j                        }t        |dd f      D ]3  }|d   }| j                  d| t        ||j	                  d             5 t        |dfddt
        hf      D ]  }| j                  |      E d {     y 7 w)Nvideosc                     |d   S Nr   r   )_vs     rp   r   z6LoomFolderIE._extract_folder_entries.<locals>.<lambda>  s
    qw rr   r   zhttps://www.loom.com/share/r   foldersc                     |d   k7  S r   r   )r   r   r   s     rp   r   z6LoomFolderIE._extract_folder_entries.<locals>.<lambda>  s    $9(< rr   )r   r   
url_resultr   rh   rx   _extract_folder_entries)rk   r   initial_folder_datafolder_datavideorm   subfolder_ids    `     rp   r   z$LoomFolderIE._extract_folder_entries  s     )QT-F-Fy-Q!+:N/OP 	_ET{H//-hZ8&(EIIV\L]_ _	_ )<dSE7K L 	BL33LAAA	BAs   B
BBBc           
          | j                  |      }| j                  |      }| j                  | j                  ||      |t	        |ddt
        j                  hf            S )Nfolderr   )r   r   playlist_resultr   r   rx   strip)rk   r   playlist_idplaylist_datas       rp   r   zLoomFolderIE._real_extract  s^    nnS)11+>##((mDk6CII;(GHJ 	Jrr   )N)
r   r   r   _WORKINGr   r   r   r   r   r   r   rr   rp   r   r     s    HGQJ T4'
	 T4&
	 T45
	 T42
	 T4*
	 T4"
	 T4
	 ]q;FzF
BJrr   r   )re   r   urllib.parser   ry   commonr   utilsr   r   r   r	   r
   r   r   utils.traversalr   r   r   r   rr   rp   <module>r     sG        !   +u
] u
pYJ= YJrr   