
    VGh2H                         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e      Z G d	 d
e      Zy)    N   )InfoExtractor   )	ExtractorErrordetermine_extfilter_dict	get_firstint_or_noneparse_iso8601
update_urlurl_or_nonevariadic)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/d0d1d2dd3d4d5d6d7dd8d9id:d;d<d=dd>d?d@dAdBddCdDidEgdFgZdGdHdIddJdKdLdMdNdOdgZdPdQg dRiiZ e	j                  dS       e	j                  dT       e	j                  dU       e	j                  dV      dWZdXZd^dZZd[ Zd\ Zd] ZyY)_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 51737ec002969dd28344db4d60b9cbbb 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
MrPumkin B20210924iENa   )r   r   r   r,   r   r   r   r   skip_downloaddash)r    r"   paramsz;https://www.loom.com/share/50e26e8aeb7940189dff5630f95ce1f4 5cc7655e7d55d281d203f8ffd14771f7 50e26e8aeb7940189dff5630f95ce1f4ziOS Mobile UploadzSimon Curran20200520iy^#   videopasswordseniorinfants2)r    r!   r"   r3   z;https://www.loom.com/embed/ddcf1c1ad21f451ea7468b1e33917e4e b321d261656848c184a94e3b93eae28d ddcf1c1ad21f451ea7468b1e33917e4ezCF Reset User's PasswordzAimee Heintz20220707ib   format	bestvideozFailed to parse JSON)r    r!   r"   r3   expected_warningszBhttps://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   GetVideoSourceacceptableMimes)DASHM3U8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
              }
            }
)GetVideoSSRrE   FetchVideoTranscriptFetchChapters0a1856cNc                 z   | j                  d      }| j                  d||xs d|xs dddd| j                   d| j                  dt        j                  t        |      D cg c]4  }|||d	| j                  j                  |i       | j                  |   d
6 c}d      j                               S c c}w )Nr8   zhttps://www.loom.com/graphqlzDownloading GraphQL JSONzFailed to download GraphQL JSONapplication/json	loom_web_web)AcceptContent-Typezx-loom-request-sourcezapollographql-client-namezapollographql-client-version)videoIdpassword)operationName	variablesquery,:
separators)headersdata)
	get_param_download_json_APOLLO_GRAPHQL_VERSIONjsondumpsr   _GRAPHQL_VARIABLESget_GRAPHQL_QUERIESencode)self
operationsvideo_idnoteerrnoterU   operation_names          ^/var/www/it7/html/youtubeDownloader/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C JJ %-Z$8 : ! "0' ( --11."E
 ..~>!  : GQR SYRXRZ! # \ 	\ :s   #9B8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   r8   )anonIDdeviceIDforce_originalrU   rY   r\   )fatalr^   r_   r    )
ra   rc   rd   struuiduuid4r`   rh   r   r   )ri   endpointrk   responses       ro   _call_url_apizLoomIE._call_url_api	  s    &&:8*AhZPRZ8*E*.A(5,QY^1CUVdjjl+ "' NN?;	
 %&
 '-fh ' 	0 Hu{m&<==    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    ro   <lambda>z)LoomIE._extract_formats.<locals>.<lambda>  s    !u* RV r}   )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_idrv   qualityr   ).vcodecr   r   r    rX   )r    extra_param_to_segment_urlmpdzdash-)mpd_idrv   )r   r   zhttp-)r    r   	format_idr   )r   urllibparseurlparserX   replace_extract_m3u8_formatsr   rf   r   _extract_mpd_formats)
format_urlr   r   r   rX   m3u8_formatsis_not_premergedfmtdash_formatsri   rk   r   s            ro   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   r   )ri   rk   metadatagql_dataformatsr   raw_urltranscoded_urlcdn_urlr    
valid_urlsr   s   ``         @ro   _extract_formatszLoomIE._extract_formats  s
   '3E}-+/+.V-WXH
 3 '	R $$Y9{7E1=>++,<hG{><LMHvz;NPUXcWd&ef>E~=V^cZ]jD1^
^z'6jHNN;wqAB	 _s   %C+-C+c                 j   | j                  |      }t        | j                  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                  g d|      }t        |ddt        hf      }||| j                  t        |dddt        hf      |      xs d | j                  |||      t        dt        |dddddt        hif      xs d i      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 JSONr_   r   
__typenameVideoPasswordMissingOrIncorrectr8   zAThis video is password-protected, use the --video-password optionT)expectedzInvalid video password)rL   rK   rE   r   r   fetchVideoChapterscontenten.fetchVideoTranscript)
source_urlcaptions_source_urlr    )r   r   r-   r   	subtitlesnamer,   ownerdisplay_name	createdAt)r   r,   r   r   )	_match_idr	   rp   dictrf   r`   r   r   r
   "_extract_chapters_from_descriptionrw   r   r   r   r   )ri   r    rk   r   r   r   s         ro   _real_extractzLoomIE._real_extractU  s   >>#&""=(<_`Z$(* 0-/ 	 <<%)JJ>>/2$Wbfh h !9DII))*egop+=zK=*YZ  ??(V-A9se$TUW_a idh,,XxJ$l8!79}<.     & 
 8 3% -u5$nse<)M?;	& 
 	
r}   )NN)__name__
__module____qualname__IE_NAME
_VALID_URL_EMBED_REGEX_TESTS_WEBPAGE_TESTSre   textwrapdedentrg   rb   rp   r|   r   r   r   r}   ro   r   r      s   GTJ6zl!DEL M14:%%#
	 M140'%#
	 M140r'!%#

	" M4!A$%#	
 #F+  M14(&%#
 #$45  M140&%#
 [)45KTFl T14F*%#
 N 	6
 'x 9( 9t *(// +  !0 1 !" ) * uqd (\(>=~"
r}   r   c                       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$ Zd(d&Zd' Zy%))LoomFolderIEz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   )ra   )ri   	folder_ids     ro   _extract_folder_dataz!LoomFolderIE._extract_folder_data  s2    "".yk:I*7G2D # F 	Fr}   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     ro   r   z6LoomFolderIE._extract_folder_entries.<locals>.<lambda>  s
    qw r}   r   zhttps://www.loom.com/share/r   foldersc                     |d   k7  S r   r   )r   r   r   s     ro   r   z6LoomFolderIE._extract_folder_entries.<locals>.<lambda>  s    $9(< r}   )r   r   
url_resultr   rf   rw   _extract_folder_entries)ri   r   initial_folder_datafolder_datavideork   subfolder_ids    `     ro   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   rw   strip)ri   r    playlist_idplaylist_datas       ro   r   zLoomFolderIE._real_extract  s^    nnS)11+>##((mDk6CII;(GHJ 	Jr}   )N)	r   r   r   r   r   r   r   r   r   r   r}   ro   r   r   z  s    GQJ T4'
	 T4&
	 T45
	 T42
	 T4*
	 T4"
	 T4
	 ]q;FzF
BJr}   r   )rc   r   urllib.parser   rx   commonr   utilsr   r   r   r	   r
   r   r   r   r   utils.traversalr   r   r   r   r}   ro   <module>r      sG        !
 
 
 +b
] b
JXJ= XJr}   