Skip to content

Commit bd7b362

Browse files
Stypoxlitetex
authored andcommitted
Fix checkstyle issues & more in DashMpdParser
Also remove useless null check on ItagItem.getItag() as that function already throws an exception if there is no itag
1 parent 8aba2b4 commit bd7b362

1 file changed

Lines changed: 71 additions & 62 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/utils/DashMpdParser.java

Lines changed: 71 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@
4343
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
4444
*/
4545

46-
public class DashMpdParser {
46+
public final class DashMpdParser {
4747

4848
private DashMpdParser() {
4949
}
5050

5151
public static class DashMpdParsingException extends ParsingException {
52-
DashMpdParsingException(String message, Exception e) {
52+
DashMpdParsingException(final String message, final Exception e) {
5353
super(message, e);
5454
}
5555
}
@@ -64,12 +64,12 @@ public static class ParserResult {
6464
private final List<VideoStream> segmentedVideoOnlyStreams;
6565

6666

67-
public ParserResult(List<VideoStream> videoStreams,
68-
List<AudioStream> audioStreams,
69-
List<VideoStream> videoOnlyStreams,
70-
List<VideoStream> segmentedVideoStreams,
71-
List<AudioStream> segmentedAudioStreams,
72-
List<VideoStream> segmentedVideoOnlyStreams) {
67+
public ParserResult(final List<VideoStream> videoStreams,
68+
final List<AudioStream> audioStreams,
69+
final List<VideoStream> videoOnlyStreams,
70+
final List<VideoStream> segmentedVideoStreams,
71+
final List<AudioStream> segmentedAudioStreams,
72+
final List<VideoStream> segmentedVideoOnlyStreams) {
7373
this.videoStreams = videoStreams;
7474
this.audioStreams = audioStreams;
7575
this.videoOnlyStreams = videoOnlyStreams;
@@ -110,19 +110,20 @@ public List<VideoStream> getSegmentedVideoOnlyStreams() {
110110
* It has video, video only and audio streams and will only add to the list if it don't
111111
* find a similar stream in the respective lists (calling {@link Stream#equalStats}).
112112
* <p>
113-
* Info about dash MPD can be found here
113+
* Info about dash MPD can be found
114+
* <a href="https://www.brendanlong.com/the-structure-of-an-mpeg-dash-mpd.html">here</a>.
114115
*
115116
* @param streamInfo where the parsed streams will be added
116-
* @see <a href="https://www.brendanlong.com/the-structure-of-an-mpeg-dash-mpd.html">www.brendanlog.com</a>
117117
*/
118118
public static ParserResult getStreams(final StreamInfo streamInfo)
119119
throws DashMpdParsingException, ReCaptchaException {
120-
String dashDoc;
121-
Downloader downloader = NewPipe.getDownloader();
120+
final String dashDoc;
121+
final Downloader downloader = NewPipe.getDownloader();
122122
try {
123123
dashDoc = downloader.get(streamInfo.getDashMpdUrl()).responseBody();
124-
} catch (IOException ioe) {
125-
throw new DashMpdParsingException("Could not get dash mpd: " + streamInfo.getDashMpdUrl(), ioe);
124+
} catch (final IOException ioe) {
125+
throw new DashMpdParsingException(
126+
"Could not get dash mpd: " + streamInfo.getDashMpdUrl(), ioe);
126127
}
127128

128129
try {
@@ -144,62 +145,70 @@ public static ParserResult getStreams(final StreamInfo streamInfo)
144145
for (int i = 0; i < representationList.getLength(); i++) {
145146
final Element representation = (Element) representationList.item(i);
146147
try {
147-
final String mimeType = ((Element) representation.getParentNode()).getAttribute("mimeType");
148+
final String mimeType
149+
= ((Element) representation.getParentNode()).getAttribute("mimeType");
148150
final String id = representation.getAttribute("id");
149-
final String url = representation.getElementsByTagName("BaseURL").item(0).getTextContent();
151+
final String url = representation
152+
.getElementsByTagName("BaseURL").item(0).getTextContent();
150153
final ItagItem itag = ItagItem.getItag(Integer.parseInt(id));
151-
final Node segmentationList = representation.getElementsByTagName("SegmentList").item(0);
152-
153-
// if SegmentList is not null this means that BaseUrl is not representing the url to the stream.
154-
// instead we need to add the "media=" value from the <SegementURL/> tags inside the <SegmentList/>
155-
// tag in order to get a full working url. However each of these is just pointing to a part of the
156-
// video, so we can not return a URL with a working stream here.
157-
// Instead of putting those streams into the list of regular stream urls wie put them in a
158-
// for example "segmentedVideoStreams" list.
159-
if (itag != null) {
160-
final MediaFormat mediaFormat = MediaFormat.getFromMimeType(mimeType);
161-
162-
if (itag.itagType.equals(ItagItem.ItagType.AUDIO)) {
163-
if (segmentationList == null) {
164-
final AudioStream audioStream = new AudioStream(url, mediaFormat, itag.avgBitrate);
165-
if (!Stream.containSimilarStream(audioStream, streamInfo.getAudioStreams())) {
166-
audioStreams.add(audioStream);
167-
}
168-
} else {
169-
segmentedAudioStreams.add(
170-
new AudioStream(id, mediaFormat, itag.avgBitrate));
154+
final Node segmentationList
155+
= representation.getElementsByTagName("SegmentList").item(0);
156+
157+
// If SegmentList is not null this means that BaseUrl is not representing the
158+
// url to the stream. Instead we need to add the "media=" value from the
159+
// <SegementURL/> tags inside the <SegmentList/> tag in order to get a full
160+
// working url. However each of these is just pointing to a part of the video,
161+
// so we can not return a URL with a working stream here. Instead of putting
162+
// those streams into the list of regular stream urls we put them in a for
163+
// example "segmentedVideoStreams" list.
164+
165+
final MediaFormat mediaFormat = MediaFormat.getFromMimeType(mimeType);
166+
167+
if (itag.itagType.equals(ItagItem.ItagType.AUDIO)) {
168+
if (segmentationList == null) {
169+
final AudioStream audioStream
170+
= new AudioStream(url, mediaFormat, itag.avgBitrate);
171+
if (!Stream.containSimilarStream(audioStream,
172+
streamInfo.getAudioStreams())) {
173+
audioStreams.add(audioStream);
171174
}
172175
} else {
173-
boolean isVideoOnly = itag.itagType.equals(ItagItem.ItagType.VIDEO_ONLY);
174-
175-
if (segmentationList == null) {
176-
final VideoStream videoStream = new VideoStream(url,
177-
mediaFormat,
178-
itag.resolutionString,
179-
isVideoOnly);
180-
181-
if (isVideoOnly) {
182-
if (!Stream.containSimilarStream(videoStream, streamInfo.getVideoOnlyStreams())) {
183-
videoOnlyStreams.add(videoStream);
184-
}
185-
} else if (!Stream.containSimilarStream(videoStream, streamInfo.getVideoStreams())) {
186-
videoStreams.add(videoStream);
176+
segmentedAudioStreams.add(
177+
new AudioStream(id, mediaFormat, itag.avgBitrate));
178+
}
179+
} else {
180+
final boolean isVideoOnly
181+
= itag.itagType.equals(ItagItem.ItagType.VIDEO_ONLY);
182+
183+
if (segmentationList == null) {
184+
final VideoStream videoStream = new VideoStream(url,
185+
mediaFormat,
186+
itag.resolutionString,
187+
isVideoOnly);
188+
189+
if (isVideoOnly) {
190+
if (!Stream.containSimilarStream(videoStream,
191+
streamInfo.getVideoOnlyStreams())) {
192+
videoOnlyStreams.add(videoStream);
187193
}
194+
} else if (!Stream.containSimilarStream(videoStream,
195+
streamInfo.getVideoStreams())) {
196+
videoStreams.add(videoStream);
197+
}
198+
} else {
199+
final VideoStream videoStream = new VideoStream(id,
200+
mediaFormat,
201+
itag.resolutionString,
202+
isVideoOnly);
203+
204+
if (isVideoOnly) {
205+
segmentedVideoOnlyStreams.add(videoStream);
188206
} else {
189-
final VideoStream videoStream = new VideoStream(id,
190-
mediaFormat,
191-
itag.resolutionString,
192-
isVideoOnly);
193-
194-
if (isVideoOnly) {
195-
segmentedVideoOnlyStreams.add(videoStream);
196-
} else {
197-
segmentedVideoStreams.add(videoStream);
198-
}
207+
segmentedVideoStreams.add(videoStream);
199208
}
200209
}
201210
}
202-
} catch (Exception ignored) {
211+
} catch (final Exception ignored) {
203212
}
204213
}
205214
return new ParserResult(
@@ -209,7 +218,7 @@ public static ParserResult getStreams(final StreamInfo streamInfo)
209218
segmentedVideoStreams,
210219
segmentedAudioStreams,
211220
segmentedVideoOnlyStreams);
212-
} catch (Exception e) {
221+
} catch (final Exception e) {
213222
throw new DashMpdParsingException("Could not parse Dash mpd", e);
214223
}
215224
}

0 commit comments

Comments
 (0)