@@ -95,37 +95,32 @@ public CachedPlayerScript getCachedPlayerScript(@NotNull HttpInterface httpInter
9595
9696 public String getTimestamp (HttpInterface httpInterface , String sourceUrl ) throws IOException {
9797 synchronized (this ) {
98- log .debug ("Timestamp from script {}" , sourceUrl );
99- return getTimestampFromScript (httpInterface , sourceUrl );
100- }
101- }
98+ HttpPost request = new HttpPost (getRemoteEndpoint ("get_sts" ));
10299
103- private String getRemoteEndpoint (String path ) {
104- return remoteUrl .endsWith ("/" ) ? remoteUrl + path : remoteUrl + "/" + path ;
105- }
100+ log .debug ("Getting timestamp for script: {}" , sourceUrl );
106101
107- private String getTimestampFromScript (HttpInterface httpInterface , String playerScript ) throws IOException {
108- HttpPost request = new HttpPost (getRemoteEndpoint ("get_sts" ));
102+ String requestBody = JsonWriter .string ()
103+ .object ()
104+ .value ("player_url" , sourceUrl )
105+ .end ()
106+ .done ();
107+ request .setEntity (new StringEntity (requestBody , ContentType .APPLICATION_JSON ));
109108
110- log .debug ("Getting timestamp for script: {}" , playerScript );
109+ try (CloseableHttpResponse response = configureHttpInterface (httpInterface ).execute (request )) {
110+ String responseBody = validateAndGetResponseBody (response );
111111
112- String requestBody = JsonWriter .string ()
113- .object ()
114- .value ("player_url" , playerScript )
115- .end ()
116- .done ();
117- request .setEntity (new StringEntity (requestBody , ContentType .APPLICATION_JSON ));
112+ log .debug ("Received response from remote cipher service: {}" , responseBody );
118113
119- try (CloseableHttpResponse response = configureHttpInterface (httpInterface ).execute (request )) {
120- String responseBody = validateAndGetResponseBody (response );
121-
122- log .debug ("Received response from remote cipher service: {}" , responseBody );
123-
124- JsonBrowser json = JsonBrowser .parse (responseBody );
125- return json .get ("sts" ).text ();
114+ JsonBrowser json = JsonBrowser .parse (responseBody );
115+ return json .get ("sts" ).text ();
116+ }
126117 }
127118 }
128119
120+ private String getRemoteEndpoint (String path ) {
121+ return remoteUrl .endsWith ("/" ) ? remoteUrl + path : remoteUrl + "/" + path ;
122+ }
123+
129124 public HttpInterface configureHttpInterface (HttpInterface httpInterface ) {
130125 httpInterface .getContext ().setAttribute (YoutubeHttpContextFilter .ATTRIBUTE_CIPHER_REQUEST_SPECIFIED , true );
131126 return httpInterface ;
0 commit comments