
    yfX)                         d dl Z ddlm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   )compat_parse_qs)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)FC2IEzC^(?: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           6/usr/lib/python3/dist-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|z  |d	
      }t        |d      }|st        d      t        d|      }|||dd||dS )Nz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)defaultz7https://video.fc2.com/api/v3/videoplaylist/%s?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_idr3   
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	            r2   _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))EPRZ( * * {,>? !>??2G< %&"
 	
r4   N)	__name__
__module____qualname__
_VALID_URLIE_NAME_NETRC_MACHINE_TESTSr3   rL    r4   r2   r   r      sq    WJGNA1$-
 C$

 ) 
 + D'F0:%
r4   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           
      Z   | j                  |      }t        |j                  d            }|d   d   }|j                  dd|z  g      d   }|j                  dd g      d   }d }|r)d|d	d
j	                  |d d |dd |d   |d   |f      d}dt
        j                         d|z  ||dS )NqueryitlzFC2 video %sr   sjzhttp://videoz-thumbnail.fc2.com/up/pic//      z.jpgurl_transparentzfc2:%s)_typeie_keyr   r   r?   )_match_valid_urlr   groupgetjoinr   re   )r,   r   mobjrZ   rH   r   r^   r?   s           r2   rL   zFC2EmbedIE._real_extract   s    $$S)

7 34:b>		$(!: ;<Q?YYtdV$Q'	 CHHhrlHQqM8B<RTW_`acI 'llnh&"
 	
r4   N)rM   rN   rO   rP   rQ   _TESTrL   rT   r4   r2   rV   rV   q   s2    EJG y1$R1	
	E
r4   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                 d   | j                  |      }| j                  d|z  |      }| 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*       |
}n*| j                  d+|	d d, t        |	      d,kD  rd-nd       |st!        d.      g }|d/   j#                         D ]r  \  }}t        |t$              s|D ]W  }|j                  d0      d1k(  sd2|j                  d      v s,|j'                  | j)                  |d   |d3|d!d|d45             Y t |D ]  }|j+                  d6|d7        | j-                  d8|d9d"#      }|s-| j/                  |d:d"#      }|rt1        j2                  d;d|      }d }|r(| j5                  d<|d=d d>?      }|rt7        |      r|\  }}| j5                  d@|dAd"#      xs d }|r2t1        j2                  dBdC|      }| j                  t9        |      |      }||xs t;        |dD      | j-                  dE|dFd"#      xs t;        |dG      ||xs t;        |d$      |t;        |dH      d!dIS )JNzhttps://live.fc2.com/%s/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 rx   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'   rx   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   rg   z2(?s)liveInfoView\s*:\s*({.+?}),\s*premiumStateViewz	user infoz\$\(.+?\)[^,]+,z"",r   )zog:descriptionztwitter:descriptionzlive descriptioninfothumb)r   r   r>   formatsro   rp   r?   is_live)r@   r*   _set_cookierG   r   r   _request_webpager   write_debugrecv_parse_json
isinstancedictrh   send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   rx   r   r   	playlistsplfmtr   ro   matchlive_info_views                       r2   rL   zFC2LiveIE._real_extract   sx   >>#&(()Ch)NPXY)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  + $D#JTUX^`@`ab   !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>
 	
r4   N)rM   rN   rO   rP   rQ   rS   rL   rT   r4   r2   rm   rm      s<    7JG 0,&%/
 
 
Fq
r4   rm   )r   commonr   compatr   
networkingr   utilsr   r	   r
   r   r   r   r   rV   rm   rT   r4   r2   <module>r      sE    	 ! $   ^
M ^
B#
 #
LA
 A
r4   