11package org .schabi .newpipe .player .datasource ;
22
3+ import static org .schabi .newpipe .MainActivity .DEBUG ;
4+
35import android .net .Uri ;
46import android .util .Log ;
57
@@ -62,10 +64,15 @@ public int read(@NonNull final byte[] buffer, final int offset, final int length
6264 @ Override
6365 public long open (final DataSpec dataSpec ) throws HttpDataSourceException {
6466 final var url = dataSpec .uri .toString ();
65- Log .d (TAG , "called open(" + url + ")" );
67+ if (DEBUG ) {
68+ Log .d (TAG , "called open(" + url + ")" );
69+ }
70+
6671 if (!url .contains (refreshableStream .playlistId ())) {
6772 // TODO: throw error or no?
68- Log .e (TAG , "Playlist id does not match" );
73+ if (DEBUG ) {
74+ Log .e (TAG , "Playlist id does not match" );
75+ }
6976 }
7077 return chunkUrlMap .isEmpty ()
7178 ? openInternal (dataSpec )
@@ -75,7 +82,9 @@ public long open(final DataSpec dataSpec) throws HttpDataSourceException {
7582 private long openInternal (final DataSpec dataSpec ) throws HttpDataSourceException {
7683 try {
7784 final var bytesToRead = super .open (dataSpec );
78- Log .d (TAG , "Bytes to read: " + bytesToRead );
85+ if (DEBUG ) {
86+ Log .d (TAG , "Bytes to read: " + bytesToRead );
87+ }
7988 isError = false ; // if we got to this line there was no error
8089 return bytesToRead ;
8190 } catch (final InvalidResponseCodeException e ) {
@@ -108,10 +117,16 @@ private long openInternal(final DataSpec dataSpec) throws HttpDataSourceExceptio
108117 }
109118
110119 private void refreshPlaylist () throws ExtractionException , IOException {
111- Log .d (TAG , "refreshPlaylist() - originalPlaylistUrl " + originalPlaylistUrl );
120+ if (DEBUG ) {
121+ Log .d (TAG , "refreshPlaylist() - originalPlaylistUrl " + originalPlaylistUrl );
122+ }
123+
112124 final var newPlaylistUrl = refreshableStream .fetchLatestUrl ();
113- Log .d (TAG , "New playlist url " + newPlaylistUrl );
114- Log .d (TAG , "Extracting new playlist Chunks" );
125+
126+ if (DEBUG ) {
127+ Log .d (TAG , "New playlist url " + newPlaylistUrl );
128+ Log .d (TAG , "Extracting new playlist Chunks" );
129+ }
115130 final var newChunks = extractChunksFromPlaylist (newPlaylistUrl );
116131
117132 if (!chunkUrlMap .isEmpty ()) {
@@ -151,20 +166,26 @@ private static String getBaseUrl(final String url) {
151166 // TODO: better name
152167 private DataSpec getUpdatedDataSpec (final DataSpec dataSpec ) {
153168 final var currentUrl = dataSpec .uri .toString ();
154- Log .d (TAG , "getUpdatedDataSpec(" + currentUrl + ')' );
169+ if (DEBUG ) {
170+ Log .d (TAG , "getUpdatedDataSpec(" + currentUrl + ')' );
171+ }
155172 // Playlist has expired, so get mapping for new url
156173 final var baseUrl = getBaseUrl (currentUrl );
157174
158175 if (baseUrl .equals (currentUrl )) {
159- Log .e (TAG , "Url has no query parameters" );
176+ if (DEBUG ) {
177+ Log .e (TAG , "Url has no query parameters" );
178+ }
160179 }
161180
162181 final var updatedUrl = chunkUrlMap .get (baseUrl );
163182 if (updatedUrl == null ) {
164183 throw new IllegalStateException ("baseUrl not found in mappings: " + baseUrl );
165184 // TODO: problemo
166185 }
167- Log .d (TAG , "updated url:" + updatedUrl );
186+ if (DEBUG ) {
187+ Log .d (TAG , "updated url:" + updatedUrl );
188+ }
168189 return dataSpec .buildUpon ()
169190 .setUri (Uri .parse (updatedUrl ))
170191 .build ();
@@ -179,7 +200,9 @@ private DataSpec getUpdatedDataSpec(final DataSpec dataSpec) {
179200 */
180201 private List <String > extractChunksFromPlaylist (final String playlistUrl )
181202 throws IOException {
182- Log .d (TAG , "extractChunksFromPlaylist(" + playlistUrl + ')' );
203+ if (DEBUG ) {
204+ Log .d (TAG , "extractChunksFromPlaylist(" + playlistUrl + ')' );
205+ }
183206 final var chunks = new ArrayList <String >();
184207 final var parser = new HlsPlaylistParser ();
185208 final var dataSpec = new DataSpec (Uri .parse (playlistUrl ));
@@ -201,11 +224,16 @@ private List<String> extractChunksFromPlaylist(final String playlistUrl)
201224 throw new IOException ("Expected Hls playlist to be an HlsMediaPlaylist, but was a "
202225 + playlist .getClass ().getSimpleName ());
203226 }
227+
204228 for (final var segment : hlsMediaPlaylist .segments ) {
205229 chunks .add (segment .url );
206230 }
207- Log .d (TAG , "Extracted " + chunks .size () + " chunks" );
208- chunks .stream ().forEach (m -> Log .d (TAG , "Chunk " + m ));
231+
232+ if (DEBUG ) {
233+ Log .d (TAG , "Extracted " + chunks .size () + " chunks" );
234+ chunks .stream ().forEach (m -> Log .d (TAG , "Chunk " + m ));
235+ }
236+
209237 return chunks ;
210238 } finally {
211239 httpDataSource .close ();
0 commit comments