
    uki,                         d dl Z 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y)    N   )InfoExtractor   )Request)ExtractorErrorUserNotLive
js_to_jsontraverse_objupdate_url_queryurlencode_postdataurljoinc            	       x    e Zd ZdZdZdZddddddd	d
di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  Zy!)"FC2IEzB(?:https?://video\.fc2\.com/(?:[^/]+/)*content/|fc2:)(?P<id>[^/]+)fc2z0http://video.fc2.com/en/content/20121103kUan1KHs a6ebe8ebe0396518689d963774a54eb720121103kUan1KHszBoxing again with Puffmp4zre:https?://.+\.jpe?g)idtitleext	thumbnailskip_downloadm3u8)urlmd5	info_dictparamsz.https://video.fc2.com/content/20121209FP73fxDx 066bdb9b3a56a97f49cbf0d0b8a75a1f20121209FP73fxDxz1Farewelling The Wiggles Live in Sydney Dec 8 2012zbSaying goodbye to the Wiggles at their Celebration Concert in Sydney, and what a concert that was!)r   r   r   r   descriptionr   r   r   z1http://video.fc2.com/en/content/20150125cEva0hDn/20150125cEva0hDn)r   r   zytdl@yt-dl.orgz(snip))usernamepasswordzrequires actual password)r   r   r   skipz2http://video.fc2.com/en/a/content/20130926eZpARwsFT)r   only_matchingc                    | j                         \  }}||y||ddd}t        |      }t        d|      }| j                  |d dd      }d	|vr| j	                  d
       yt        d      }| j                  |d dd       y)NFvideoz Login )emailr$   doneSubmitzAhttps://secure.id.fc2.com/index.php?mode=login&switch_language=enz
Logging inzUnable to log in)noteerrnotezmode=redirect&login=donez*unable to log in: bad username or passwordz+http://id.fc2.com/?mode=redirect&login=donezLogin redirectzLogin redirect failedT)_get_login_infor   r   _download_webpagereport_warning)selfr#   r$   login_form_strs
login_datarequestlogin_resultslogin_redirs           O/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/yt_dlp/extractor/fc2.py_loginzFC2IE._login<   s    !113(x/  	
 (8
OQ[] ..w<Yk.l%]: LM KL$4>U 	 	W     c                    | j                  |      }| j                          d }|j                  d      s<| j                  ||      }| j                  j                          | j                          d\  }}}|9| j                  d|dd      }| j                  |      }| j                  |d       }| j                  d| d	|d
      }t        |d      }|st        d      t        d|      }|||d|j                  d      dk(  rdnd||dS )Nfc2:)NNN)z*<h2\s+class="videoCnt_title">([^<]+?)</h2>z;\s+href="[^"]+"\s*title="([^"]+?)"\s*rel="nofollow">\s*<imgz9\s+href="[^"]+"\s*title="([^"]+?)"\s*rel="nofollow">\s*\1r   Ffatal)defaultz+https://video.fc2.com/api/v3/videoplaylist/z
?sh=1&fs=0zDownloading info pager,   )playlistnqzUnable to extract video URLzhttps://video.fc2.com/r   typer   m3u8_nativehttps)r   r   r   r   protocolr    r   )	_match_idr8   
startswithr/   	cookiejarclear_session_cookies_html_search_regex_og_search_thumbnail_og_search_description_download_jsonr
   r   r   get)	r1   r   video_idwebpager   r   r    vidplaylistvid_urls	            r7   _real_extractzFC2IE._real_extractY   s8   >>#&~~f%,,S(;GNN002KKM(8%y+++O u , &E 11':I55gt5LK))9(:NPX( * * {,>? !>??2G< )4)@A)E7&"
 	
r9   N)	__name__
__module____qualname__
_VALID_URLIE_NAME_NETRC_MACHINE_TESTSr8   rS    r9   r7   r   r      s    VJGNA1$-1	
 V
 @1$H1
	 C$

 ) 
 + DE%FN:%
r9   r   c                   0    e Zd ZdZdZddddddd	d
Zd Zy)
FC2EmbedIEz1https?://video\.fc2\.com/flv2\.swf\?(?P<query>.+)z	fc2:embedu'  http://video.fc2.com/flv2.swf?t=201404182936758512407645&i=20130316kwishtfitaknmcgd76kjd864hso93htfjcnaogz629mcgfs6rbfk0hsycma7shkf85937cbchfygd74&i=201403223kCqB3Ez&d=2625&sj=11&lang=ja&rel=1&from=11&cmt=1&tk=TlRBM09EQTNNekU9&tl=プリズン･ブレイク%20S1-01%20マイケル%20【吹替】 b8aae5334cb691bdb1193a88a6ab5d5a201403223kCqB3Ezflvu;   プリズン･ブレイク S1-01 マイケル 【吹替】zre:^https?://.*\.jpg$)r   r   r   r   r!   c           
         | j                  |      }t        j                  j                  |j	                  d            }|d   d   }|j                  dd| g      d   }|j                  dd g      d   }d }|r2dj                  |d	j                  |d d
 |d
d |d   |d   |f            }dt        j                         d| ||dS )Nqueryitlz
FC2 video r   sjz.http://video{}-thumbnail.fc2.com/up/pic/{}.jpg/      url_transparentr;   )_typeie_keyr   r   r   )
_match_valid_urlurllibparseparse_qsgrouprN   formatjoinr   rm   )r1   r   mobjrb   rO   r   rf   r   s           r7   rS   zFC2EmbedIE._real_extract   s    $$S)%%djj&9::b>		$:hZ!8 9:1=YYtdV$Q'	HOOCHHhrlHQqM8B<RTW_`acI 'lln($"
 	
r9   N)rT   rU   rV   rW   rX   _TESTrS   r[   r9   r7   r]   r]      s2    EJG y1$R1	
	E
r9   r]   c                   4    e Zd ZdZdZdddddddd	d
gZd Zy)	FC2LiveIEz#https?://live\.fc2\.com/(?P<id>\d+)zfc2:livezhttps://live.fc2.com/57892267/57892267u   どこまで・・・u   あつあげzre:https?://.+fc2.+)r   r   uploaderuploader_idr   
livestream)r   r   r%   c                    | j                  |      }| j                  d| d|      }| j                  ddd       | j                  d|t	        ddd|d      d	      }| j                  d
|dt	        |dd|d   d   d   ddddd      ddi      }t        |dt        hf      rd|vrt        |      | j                  dd|d          t        |d   d|d   i      }d }| j                  t        |ddi       |d!"      }| j                  d#       	 |j                         }	|	s| j                  |	|d%&      }
|
rt        |
t              s;|
j!                  d'      d(k(  rnP|j#                  d)       	 |j                         }	|	s| j                  |	|d%&      }
|
rt        |
t              s;|
j!                  d'      d*k(  r(|
j!                  d+      d,k(  r| j                  d-       |
}n5| j                  d.j%                  |	d d/ t'        |	      d/kD  rd0nd             |st)        d1      g }|d2   j+                         D ]r  \  }}t        |t,              s|D ]W  }|j!                  d      d3k(  sd4|j!                  d      v s,|j/                  | j1                  |d   |d5|d$d|d67             Y t |D ]  }|j3                  d8|d9        | j5                  d:|d;d%&      }|s-| j7                  |d<d%&      }|rt9        j:                  d=d|      }d }|r(| j=                  d>|d?d d@A      }|rt?        |      r|\  }}| j=                  dB|dCd%&      xs d }|r2t9        j:                  dDdE|      }| j                  tA        |      |      }||xs t        |dF      | j5                  dG|dHd%&      xs t        |dI      ||xs t        |d'      |t        |dJ      d$dKS )LNzhttps://live.fc2.com/rg   zlive.fc2.comzjs-player_size1z&https://live.fc2.com/api/memberApi.php)channelprofileuserstreamidzRequesting member info)datar,   z-https://live.fc2.com/api/getControlServer.phpzDownloading ControlServer dataplay r   channel_dataversionz
2.1.0
 [1]pcbrowser_hls)
channel_idmodeorzchannel_versionclient_versionclient_type
client_appipv6zX-Requested-WithXMLHttpRequest)r,   r   headersstatuscontrol_token)rO   l_ortknorz_rawr   Originzhttps://live.fc2.com)r   z(Fetching HLS playlist info via WebSocketr?   zSending HLS server requestTFr<   nameconnect_completez4{"name":"get_hls_information","arguments":{},"id":1}
_response_r   r   GoodbyezServer said: {}{}d   z...z/Unable to fetch HLS playlist info via WebSocket	argumentsr   master_playlistr   )r   Referer)r   m3u8_idliver   fc2_live)rE   ws)zog:titleztwitter:titlez
live titlez
html titlez
\s+-\s+.+$z^(.+?)\s*\[(.+?)\]$ztitle and uploader)r   r   )r>   rr   z2(?s)liveInfoView\s*:\s*({.+?}),\s*premiumStateViewz	user infoz\$\(.+?\)[^,]+,z"",r   )zog:descriptionztwitter:descriptionzlive descriptioninfothumb)r   r   r    formatsrz   r{   r   is_live)!rF   r/   _set_cookierM   r   r
   intr   r   _request_webpager   write_debugrecv_parse_json
isinstancedictrN   sendrs   lenr   itemslistextend_extract_m3u8_formatsupdate_html_search_meta_html_extract_titleresub_search_regexallr	   )r1   r   rO   rP   
member_apicontrol_serverws_urlplaylist_datar   r   r   r   r   	playlistsplfmtr   rz   matchlive_info_views                       r7   rS   zFC2LiveIE._real_extract   s   >>#&((+@
!)LhW)93?((4hEW$	Y F
 . ) /
 ,,;XLl#&#-f#5n#Ei#P"/#+	% 	 ,-=> - @ C5(9:Vd?dx00N94MN!."7/>ZiKj9kl""76,<
 $E # G 	56779D##D(%#@Dz$5xx#55  	GH779D##D(%#@Dz$5xx</DHHTNa4G  + $077Tc
SQUYY\_Ebdef   !RSS,[9??A 
	OD)i. 66(#q(->"&&--ONN4#=#=5	84&<'*! $> $ 
	  	CJJ& 	 &&'Dg|ch&i,,Wl%,PE}b%8&&'=uFZdhpv&wEU"'x++,acjlw  @E+  F  N  JNVV$6~NN!--j.H(SN Cl>7C119+5 2 : b=I.Z`=a HL$H#%ng>
 	
r9   N)rT   rU   rV   rW   rX   rZ   rS   r[   r9   r7   rx   rx      s<    7JG 0,&%/
 
 
Ft
r9   rx   )r   urllib.parsero   commonr   
networkingr   utilsr   r   r	   r
   r   r   r   r   r]   rx   r[   r9   r7   <module>r      sJ    	  !    m
M m
`#
 #
LD
 D
r9   