
    VGh:                         d dl Z ddlmZ ddlmZ ddlmZmZmZm	Z	m
Z
mZmZ  G d de      Z G d	 d
e      Z G d de      Z G d de      Zy)    N   )InfoExtractor   )	HTTPError)ExtractorErrordetermine_extfloat_or_noneint_or_nonesmuggle_urltry_getunsmuggle_urlc                   6    e Zd ZdZed        ZddZddZd Zy)	LimelightBaseIEz<http://production-ps.lvp.llnw.net/r/PlaylistService/%s/%s/%sc                 h   dddd}d }g }t        j                  d|      D ]9  \  }}|j                  | j                   |d||    d|       d	| |             ; t        j                  d
|      D ]c  }|j                  d      |j                  d      }}|j                  | j                   |d| d|       d	|j                          |             e t        j                  d|      D ]?  }|j                  | j                   |d|       t        j                         |             A |S )Nmediachannelchannel_list)MediaChannelChannelListc                     t        | d| i      S )N
source_url)r   )urls    c/var/www/it7/html/youtubeDownloader/venv/lib/python3.12/site-packages/yt_dlp/extractor/limelight.pysmugglez4LimelightBaseIE._extract_embed_urls.<locals>.smuggle   s    s\3$788    zMLimelightPlayer\.doLoad(Media|Channel|ChannelList)\(["\'](?P<id>[a-z0-9]{32})z
limelight::	LimelightaQ  (?sx)
                    <object[^>]+class=(["\'])(?:(?!\1).)*\bLimelightEmbeddedPlayerFlash\b(?:(?!\1).)*\1[^>]*>.*?
                        <param[^>]+
                            name=(["\'])flashVars\2[^>]+
                            value=(["\'])(?:(?!\3).)*(?P<kind>media|channel(?:List)?)Id=(?P<id>[a-z0-9]{32})
                kindidzX(?s)LimelightPlayerUtil\.embed\s*\(\s*{.*?\bmediaId["\']\s*:\s*["\'](?P<id>[a-z0-9]{32})zlimelight:media:)	refindallappend
url_resultfinditergroup
capitalizeLimelightMediaIEie_key)	clsr   webpagelmr   entriesr   video_idmobjs	            r   _extract_embed_urlsz#LimelightBaseIE._extract_embed_urls   s_     )
	9  jj` 	/ND( NN3>>*RXJaz:;D6"H. /	/ KK
  	<D "ZZ/D1A(DNN3>>*TF!H:67DOO-./; <	<" 

k 	6H NN3>>*8*56 '')85 6	6 r   Nc                    i }|r||d<   	 | j                  | j                  | j                  ||fz  |d| d||      S # t        $ r}t	        |j
                  t              r|j
                  j                  dk(  rj| j                  |j
                  j                  j                         j                         |      d   d   }|dk(  r| j                          t        |d	
       d }~ww xY w)NRefererzDownloading PlaylistService z JSON)fatalheadersi  detailcontentAccessPermissionCountryDisabledT)expected)_download_json_PLAYLIST_SERVICE_URL_PLAYLIST_SERVICE_PATHr   
isinstancecauser   status_parse_jsonresponsereaddecoderaise_geo_restricted)selfitem_idmethodr3   refererr4   eerrors           r   _call_playlist_servicez&LimelightBaseIE._call_playlist_service>   s    !(GI	&&**d.I.I7TZ-[[7xuEW ' . .  	!''9-!''..C2G(()9)9)>)>)@)G)G)I7ST\]^wx----/$UT::	s   3? 	C+BC&&C+c                 \    | j                  |||      }| j                  ||d|      }||fS )N)rG   F)r3   rG   )rJ   )rD   rE   	pc_methodmobile_methodrG   pcmobiles          r   _extractzLimelightBaseIE._extractO   sB    (()W(M,,]% - B6zr   c                 *	  "# fd} ||d      # ||d      "#j                  d      xs "d   }#j                  d      xs "d   }g }g }	#j                  dg       D ]~  }
|
j                  d      }|r||	v r| j                  d      s|
j                  d	      r?|	j                  |       t        |      }|d
k(  r%|j	                  | j                  ||dd             |t        |
j                  d            t        |
j                  d            |d}t        |
j                  d            }t        |
j                  d            }t        |
j                  d            }|s|s|r|j                  |||d       nd|d<   t        j                  d|      }|r*d}|
j                  d      r|dt        |
d         z  z  }|j                  dd      }d}|D ]  \  }}||j                  d      j                         vr(dj                  ||j                  d      dd        }|	j                  |       | j                  |||      sq|j!                         }|j                  ||d        |j                  |        n |j                  |j                  d      |j                  d      |j                  d!      d"|d#       |j                  |        "j                  d$g       D ]  }|j                  d%      }|j                  d&      }|r||	v r,|d'v r| j                  dd      sC|	j                  |       t        |      }|d(k(  r'|j	                  | j#                  ||d)d*|d+             |d
k(  r%|j	                  | j                  ||d             |j                  ||d,|d-        i }"j                  d.      D ]  }|d/k(  s	| j%                  |d0d|      xs g }|D ]a  }|j                  d1      }|s|j                  d2      xs | j'                  d3|d4d56      } |j)                  | g       j                  d|i       c  n "#fd7}!|| |!d8      |t         |!d9      d:       |!d;      xs  |!d<      |d=S )>Nc                 8    t        | fdt              xs i S )Nc                     |       S N )xiys    r   <lambda>zALimelightBaseIE._extract_info.<locals>.<lambda>.<locals>.<lambda>V   s    QqT!W r   )r   dict)rV   rX   rW   s    `r   rY   z/LimelightBaseIE._extract_info.<locals>.<lambda>V   s    +<d C Ir r   playlistItems	mediaListmediaIdtitlestreamsr   allow_unplayable_formatsdrmProtectedf4mhdsF)f4m_idr3   audioBitRatevideoFrameRate)r   abrfpsextvideoWidthInPixelsvideoHeightInPixelsvideoBitRate)widthheightvbrnonevcodeczG^(?P<url>rtmpe?://(?P<host>[^/]+)/(?P<app>.+))/(?P<playpath>mp[34]:.+)$rtmpz-%dhttp))zdelvenetworks.comzcpl.delvenetworks.com)zvideo.llnw.netzs2.content.video.llnw.nethostzhttp://{}/{}playpath   )r   	format_idappflv)r   	play_pathrx   ri   rw   
mobileUrls	mobileUrltargetMediaPlatform)WidevineSmoothStreamingm3u8mp4m3u8_native)m3u8_idr3   i)r   rw   qualityri   flagsClosedCaptions!getClosedCaptionsDetailsByMediaIdwebvttFileUrllanguageCodez/([a-z]{2})\.vttlangen)defaultc                 L    j                  |       xs j                  |       S rT   )get)rV   mobile_itempc_items    r   rY   z/LimelightBaseIE._extract_info.<locals>.<lambda>   s    W[[^A{q/A r   descriptiondurationInMillisecondsi  previewImageUrlthumbnailImageUrl)r    r^   r   formatsduration	thumbnail	subtitles)r   	get_paramr#   r   extend_extract_f4m_formatsr	   r
   updater!   searchreplacer&   lowerformat_is_valid_urlcopy_extract_m3u8_formatsrJ   _search_regex
setdefault)$rD   rN   rO   rW   rG   get_itemr.   r^   r   urlsstream
stream_urlri   fmtrm   rn   ro   rr   rw   http_format_id	CDN_HOSTScdn_host	http_hosthttp_urlhttp_fmt
mobile_url	media_urlr   flagclosed_captionscccc_urlr   get_metar   r   s$      `                              @@r   _extract_infozLimelightBaseIE._extract_infoU   s   I2/v{3;;y)C[-CG$<G(<kk)R0 =	$FE*Jt!3>>"<=&**^B\KK
#
+Ce|t88e  9  E F &(N)CD(4D)EF	 $FJJ/C$DE$VZZ0E%FG#FJJ~$>?FcJJ!&"("   %+CMyy!kmwx &Izz.1!U[9O-P%PP	%.%6%6vv%FN!I 09 "+)#4::f+=+C+C+EE$#1#8#8DJJzDZ[\[]D^#_H---h.Q'*xxzH$OO'/-;-  $NN84!" JJ#zz%0%)ZZ
%;#zz%0$%.   s#{=	$~ &//,; 	J"{3I"'<=I	T 1<< NN+EuMKK	"	*Cf}t99x%U  :  4 5 t88%  9  I J $!*"	  %	2 	OOG, 	D''"&"="=A7#$ #*')   * BVVO4F! 66.1zT5G5GH[]cekuy5G5zD((r299v;  	 B #M2%h/G&H$O!"34UAT8U"
 	
r   )TNrT   )	__name__
__module____qualname__r:   classmethodr0   rJ   rP   r   rU   r   r   r   r      s+    Z( (T"{
r   r   c            
       ^    e Zd ZdZdZddddddd	d
ddiddddddddddddddgZdZd Zy)r(   	limelighta  (?x)
                        (?:
                            limelight:media:|
                            https?://
                                (?:
                                    link\.videoplatform\.limelight\.com/media/|
                                    assets\.delvenetworks\.com/player/loader\.swf
                                )
                                \?.*?\bmediaId=
                        )
                        (?P<id>[a-z0-9]{32})
                    zWhttp://link.videoplatform.limelight.com/media/?mediaId=3ffd040b522b4485b6d84effc750cd86 3ffd040b522b4485b6d84effc750cd86r   zHaP and the HB Prince Trailerz$md5:8005b944181778e313d95c1237ddb640zre:^https?://.*\.jpeg$g(\b@)r    ri   r^   r   r   r   skip_downloadT)r   	info_dictparamsz0limelight:media:a3e00274d4564ec4a9b29b9466432335 2fa3bad9ac321e23860ca23bc2c69e3d a3e00274d4564ec4a9b29b9466432335z3Play Media Overview VideogX9vS@z
mincount:1)r    ri   r^   r   r   r   )r   md5r   z[https://assets.delvenetworks.com/player/loader.swf?mediaId=8018a574f08d416e95ceaccae4ba0452r   only_matchingr   c                     t        |i       \  }}| j                  |      }|j                  d      }| j                  d|j                  d      i       | j	                  |dd|      \  }}| j                  ||d|      S )Nr   	countriesgeo_countriesgetPlaylistByMediaIdgetMobilePlaylistByMediaIdr   )r   	_match_idr   _initialize_geo_bypassrP   r   )rD   r   smuggled_datar.   r   rN   rO   s          r   _real_extractzLimelightMediaIE._real_extract  s    *33]>>#&"&&|4
##**?;%
 	 ]],(*6
F !!"fa<<r   Nr   r   r   IE_NAME
_VALID_URL_TESTSr;   r   rU   r   r   r(   r(      s    GJ i44A2
 T
  B1412 &	
	 m9F@ %=r   r(   c                   <    e Zd ZdZdZddddddd	d
ddgZdZd Zy)LimelightChannelIEzlimelight:channela  (?x)
                        (?:
                            limelight:channel:|
                            https?://
                                (?:
                                    link\.videoplatform\.limelight\.com/media/|
                                    assets\.delvenetworks\.com/player/loader\.swf
                                )
                                \?.*?\bchannelId=
                        )
                        (?P<id>[a-z0-9]{32})
                    zYhttp://link.videoplatform.limelight.com/media/?channelId=ab6a524c379342f9b23642917020c082 ab6a524c379342f9b23642917020c082zJavascript Sample CodezVJavascript Sample Code - http://www.delvenetworks.com/sample-code/playerCode-demo.html)r    r^   r      r   r   playlist_mincountz\http://assets.delvenetworks.com/player/loader.swf?channelId=ab6a524c379342f9b23642917020c082Tr   r   c           	      l   t        |i       \  }}| j                  |      }|j                  d      }| j                  |dd|      \  }}t	        t        |d               D cg c]  }| j                  ||||       }}| j                  |||j                  d      |j                  d            S c c}w )Nr   getPlaylistByChannelIdz7getMobilePlaylistWithNItemsByChannelId?begin=0&count=-1r[   r^   r   )r   r   r   rP   rangelenr   playlist_result)	rD   r   r   
channel_idr   rN   rO   rW   r-   s	            r   r   z LimelightChannelIE._real_extract.  s    *33]^^C(
"&&|4
]]0E
F 3r/2346 r61j96 6 ##Z&**]2KM 	M	6s   "B1Nr   rU   r   r   r   r     sO    !GJ k4-s

  nF 'Mr   r   c                   :    e Zd ZdZdZddddddd	d
dgZdZd Zy)LimelightChannelListIEzlimelight:channel_lista  (?x)
                        (?:
                            limelight:channel_list:|
                            https?://
                                (?:
                                    link\.videoplatform\.limelight\.com/media/|
                                    assets\.delvenetworks\.com/player/loader\.swf
                                )
                                \?.*?\bchannelListId=
                        )
                        (?P<id>[a-z0-9]{32})
                    z]http://link.videoplatform.limelight.com/media/?channelListId=301b117890c4465c8179ede21fd92e2b 301b117890c4465c8179ede21fd92e2bzWebsite - Hero Player)r    r^   r   r   zahttps://assets.delvenetworks.com/player/loader.swf?channelListId=301b117890c4465c8179ede21fd92e2bTr   r   c           	          | j                  |      }| j                  |d      }|d   D cg c]&  }| j                  dj                  |d         d      ( }}| j	                  |||d         S c c}w )NgetMobileChannelListByIdchannelListzlimelight:channel:{}r    LimelightChannelr^   )r   rJ   r$   r   r   )rD   r   channel_list_idr   r   r-   s         r   r   z$LimelightChannelListIE._real_extract[  s    ..-2279
 (68 OO299'$-HJ\]8 8 ##_l7&;= 	=	8s   +A.Nr   rU   r   r   r   r   @  sK    &GJ o4,
  s
F ,=r   r   )r!   commonr   networking.exceptionsr   utilsr   r   r	   r
   r   r   r   r   r(   r   r   rU   r   r   <module>r      sT    	 ! -  @
m @
F<= <=~+M +M\&=_ &=r   