1919
2020import androidx .annotation .NonNull ;
2121
22+ import android .util .Log ;
23+
2224import org .schabi .newpipe .extractor .services .youtube .YoutubeParsingHelper ;
2325import org .schabi .newpipe .extractor .MediaFormat ;
2426import org .schabi .newpipe .extractor .NewPipe ;
@@ -154,7 +156,7 @@ private static void printCacheDirNotInitialized() {
154156 + "Fallback to original subtitle without deduplication. "
155157 + "setCacheDirPath() should be called before using this class." ;
156158
157- System . err . println (TAG + ": " + errorMessage );
159+ Log . w (TAG , errorMessage );
158160 }
159161
160162 private static String downloadRemoteSubtitleContent (final String urlStr ,
@@ -163,7 +165,7 @@ private static String downloadRemoteSubtitleContent(final String urlStr,
163165 final int initialDelayMillis ) {
164166 final Downloader downloader = NewPipe .getDownloader ();
165167 if (downloader == null ) {
166- System . err . println (TAG + ": Downloader not initialized" );
168+ Log . w (TAG , " Downloader not initialized- cannot download subtitles " );
167169 return null ;
168170 }
169171 // if auto-translate language subtitle, use the bigger data.
@@ -177,18 +179,14 @@ private static String downloadRemoteSubtitleContent(final String urlStr,
177179 if (response .responseCode () == 200 ) {
178180 return response .responseBody ();
179181 } else {
180- System .err .println (TAG + ": Attempt " + attempt
181- + " failed with status: "
182- + response .responseCode ()
183- + " URL: " + urlStr );
182+ Log .w (TAG , "Attempt " + attempt + " failed with status: "
183+ + response .responseCode () + " URL: " + urlStr );
184184 if (response .responseCode () != 503 && response .responseCode () != 429 ) {
185185 return null ;
186186 }
187187 }
188188 } catch (IOException | ReCaptchaException e ) {
189- System .err .println (TAG + ": Attempt " + attempt
190- + " failed: " + e .getMessage ()
191- + " URL: " + urlStr );
189+ Log .w (TAG , "Attempt " + attempt + " failed for URL: " + urlStr , e );
192190 }
193191 if (attempt < maxRetries ) {
194192 try {
@@ -200,8 +198,8 @@ private static String downloadRemoteSubtitleContent(final String urlStr,
200198 }
201199 }
202200 }
203- System . err . println (TAG + ": Failed to download subtitle after "
204- + maxRetries + " URL: " + urlStr );
201+ Log . e (TAG , " Failed to download subtitle after " + maxRetries
202+ + " attempts. URL: " + urlStr );
205203 return null ;
206204 }
207205
@@ -392,8 +390,7 @@ private static String storeItToCacheDir(final String subtitleContent,
392390 if (null == writeDeduplicatedContentToCachefile (subtitleContent , cacheFile )) {
393391 return cacheFilePathForExoplayer ;
394392 } else {
395- System .err .println (TAG + ": Failed to write cache file: "
396- + cacheFile .getAbsolutePath ());
393+ Log .e (TAG , "Failed to write cache file: " + cacheFile .getAbsolutePath ());
397394 return null ;
398395 }
399396 }
@@ -579,9 +576,8 @@ private static String writeContentToFile(final String content,
579576 //ok
580577 return null ;
581578 } catch (final IOException e ) {
582- final String errorMessage = e .getMessage ();
583- System .err .println (TAG + ": Failed to write cache file: " + errorMessage );
584- return errorMessage ;
579+ Log .e (TAG , "Failed to write cache file" , e );
580+ return e .getMessage ();
585581 }
586582 }
587583
0 commit comments