
    VGhM)                         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  G d de      Z G d	 d
e      Z G d de      Zy)    N   )InfoExtractor   )Request)ExtractorError
js_to_jsontraverse_objupdate_url_queryurlencode_postdataurljoinc                   Z    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gZd Zd Zy)FC2IEzB(?:https?://video\.fc2\.com/(?:[^/]+/)*content/|fc2:)(?P<id>[^/]+)fc2z0http://video.fc2.com/en/content/20121103kUan1KHs a6ebe8ebe0396518689d963774a54eb720121103kUan1KHsflvzBoxing again with Puff)idexttitleurlmd5	info_dictz1http://video.fc2.com/en/content/20150125cEva0hDn/20150125cEva0hDnmp4)r   r   zytdl@yt-dl.orgz(snip))usernamepasswordzrequires actual password)r   r   params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           ]/var/www/it7/html/youtubeDownloader/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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   m3u8_native)r   r   r   r   protocoldescription	thumbnail)	_match_idr2   
startswithr)   	cookiejarclear_session_cookies_html_search_regex_og_search_thumbnail_og_search_description_download_jsonr	   r   r   )	r+   r   video_idwebpager   r?   r>   vidplaylistvid_urls	            r1   _real_extractzFC2IE._real_extractI   s&   >>#&~~f%,,S(;GNN002KKM(8%y+++O u , &E 11':I55gt5LK))9(:NPX( * * {,>? !>??2G< %&"
 	
r3   N)	__name__
__module____qualname__
_VALID_URLIE_NAME_NETRC_MACHINE_TESTSr2   rL    r3   r1   r   r      sq    VJGNA1$-
 C$

 ) 
 + D'F0:%
r3   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201403223kCqB3Ezr   u;   プリズン･ブレイク 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_transparentr5   )_typeie_keyr   r   r?   )
_match_valid_urlurllibparseparse_qsgroupgetformatjoinr   re   )r+   r   mobjrZ   rH   r   r^   r?   s           r1   rL   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($"
 	
r3   N)rM   rN   rO   rP   rQ   _TESTrL   rT   r3   r1   rV   rV   q   s2    EJG y1$R1	
	E
r3   rV   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      }| 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d.nd             |st#        d/      g }|d0   j%                         D ]r  \  }}t        |t&              s|D ]W  }|j                  d1      d2k(  sd3|j                  d      v s,|j)                  | j+                  |d   |d4|d"d|d56             Y t |D ]  }|j-                  d7|d8        | j/                  d9|d:d#$      }|s-| j1                  |d;d#$      }|rt3        j4                  d<d|      }d }|r(| j7                  d=|d>d d?@      }|rt9        |      r|\  }}| j7                  dA|dBd#$      xs d }|r2t3        j4                  dCdD|      }| j                  t;        |      |      }||xs t=        |dE      | j/                  dF|dGd#$      xs t=        |dH      ||xs t=        |d%      |t=        |dI      d"dJS )KNzhttps://live.fc2.com/r_   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l_ortknorz_rawr   control_tokenOriginzhttps://live.fc2.com)r   z(Fetching HLS playlist info via WebSocketr9   zSending HLS server requestTFr6   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	argumentsstatusr   master_playlistr   )r   Referer)r   m3u8_idliver   fc2_live)r=   ws)zog:titleztwitter:titlez
live titlez
html titlez
\s+-\s+.+$z^(.+?)\s*\[(.+?)\]$ztitle and uploader)r   r   )r8   rj   z2(?s)liveInfoView\s*:\s*({.+?}),\s*premiumStateViewz	user infoz\$\(.+?\)[^,]+,z"",r   )zog:descriptionztwitter:descriptionzlive descriptioninfothumb)r   r   r>   formatsrs   rt   r?   is_live)r@   r)   _set_cookierG   r   r
   _request_webpager   write_debugrecv_parse_json
isinstancedictrk   sendrl   lenr   itemslistextend_extract_m3u8_formatsupdate_html_search_meta_html_extract_titleresub_search_regexallr   r	   )r+   r   rH   rI   
member_apicontrol_serverws_urlplaylist_datar   r   r|   r   r   	playlistsplfmtr   rs   matchlive_info_views                       r1   rL   zFC2LiveIE._real_extract   s   >>#&((+@
!)LhW)93?((4hEW$	Y F
 . ) /
 ,,;XLl#&#-f#5n#Ei#P"/#+	% 	 ,-=> - @ 	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>
 	
r3   N)rM   rN   rO   rP   rQ   rS   rL   rT   r3   r1   rq   rq      s<    7JG 0,&%/
 
 
Fq
r3   rq   )r   urllib.parserg   commonr   
networkingr   utilsr   r   r	   r
   r   r   r   rV   rq   rT   r3   r1   <module>r      sE    	  !   ^
M ^
B#
 #
LA
 A
r3   