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
This commit is contained in:
parent
8aba2b47b0
commit
bd7b362040
1 changed files with 67 additions and 58 deletions
|
@ -43,13 +43,13 @@ import java.util.List;
|
||||||
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class DashMpdParser {
|
public final class DashMpdParser {
|
||||||
|
|
||||||
private DashMpdParser() {
|
private DashMpdParser() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class DashMpdParsingException extends ParsingException {
|
public static class DashMpdParsingException extends ParsingException {
|
||||||
DashMpdParsingException(String message, Exception e) {
|
DashMpdParsingException(final String message, final Exception e) {
|
||||||
super(message, e);
|
super(message, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,12 +64,12 @@ public class DashMpdParser {
|
||||||
private final List<VideoStream> segmentedVideoOnlyStreams;
|
private final List<VideoStream> segmentedVideoOnlyStreams;
|
||||||
|
|
||||||
|
|
||||||
public ParserResult(List<VideoStream> videoStreams,
|
public ParserResult(final List<VideoStream> videoStreams,
|
||||||
List<AudioStream> audioStreams,
|
final List<AudioStream> audioStreams,
|
||||||
List<VideoStream> videoOnlyStreams,
|
final List<VideoStream> videoOnlyStreams,
|
||||||
List<VideoStream> segmentedVideoStreams,
|
final List<VideoStream> segmentedVideoStreams,
|
||||||
List<AudioStream> segmentedAudioStreams,
|
final List<AudioStream> segmentedAudioStreams,
|
||||||
List<VideoStream> segmentedVideoOnlyStreams) {
|
final List<VideoStream> segmentedVideoOnlyStreams) {
|
||||||
this.videoStreams = videoStreams;
|
this.videoStreams = videoStreams;
|
||||||
this.audioStreams = audioStreams;
|
this.audioStreams = audioStreams;
|
||||||
this.videoOnlyStreams = videoOnlyStreams;
|
this.videoOnlyStreams = videoOnlyStreams;
|
||||||
|
@ -110,19 +110,20 @@ public class DashMpdParser {
|
||||||
* It has video, video only and audio streams and will only add to the list if it don't
|
* It has video, video only and audio streams and will only add to the list if it don't
|
||||||
* find a similar stream in the respective lists (calling {@link Stream#equalStats}).
|
* find a similar stream in the respective lists (calling {@link Stream#equalStats}).
|
||||||
* <p>
|
* <p>
|
||||||
* Info about dash MPD can be found here
|
* Info about dash MPD can be found
|
||||||
|
* <a href="https://www.brendanlong.com/the-structure-of-an-mpeg-dash-mpd.html">here</a>.
|
||||||
*
|
*
|
||||||
* @param streamInfo where the parsed streams will be added
|
* @param streamInfo where the parsed streams will be added
|
||||||
* @see <a href="https://www.brendanlong.com/the-structure-of-an-mpeg-dash-mpd.html">www.brendanlog.com</a>
|
|
||||||
*/
|
*/
|
||||||
public static ParserResult getStreams(final StreamInfo streamInfo)
|
public static ParserResult getStreams(final StreamInfo streamInfo)
|
||||||
throws DashMpdParsingException, ReCaptchaException {
|
throws DashMpdParsingException, ReCaptchaException {
|
||||||
String dashDoc;
|
final String dashDoc;
|
||||||
Downloader downloader = NewPipe.getDownloader();
|
final Downloader downloader = NewPipe.getDownloader();
|
||||||
try {
|
try {
|
||||||
dashDoc = downloader.get(streamInfo.getDashMpdUrl()).responseBody();
|
dashDoc = downloader.get(streamInfo.getDashMpdUrl()).responseBody();
|
||||||
} catch (IOException ioe) {
|
} catch (final IOException ioe) {
|
||||||
throw new DashMpdParsingException("Could not get dash mpd: " + streamInfo.getDashMpdUrl(), ioe);
|
throw new DashMpdParsingException(
|
||||||
|
"Could not get dash mpd: " + streamInfo.getDashMpdUrl(), ioe);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -144,25 +145,31 @@ public class DashMpdParser {
|
||||||
for (int i = 0; i < representationList.getLength(); i++) {
|
for (int i = 0; i < representationList.getLength(); i++) {
|
||||||
final Element representation = (Element) representationList.item(i);
|
final Element representation = (Element) representationList.item(i);
|
||||||
try {
|
try {
|
||||||
final String mimeType = ((Element) representation.getParentNode()).getAttribute("mimeType");
|
final String mimeType
|
||||||
|
= ((Element) representation.getParentNode()).getAttribute("mimeType");
|
||||||
final String id = representation.getAttribute("id");
|
final String id = representation.getAttribute("id");
|
||||||
final String url = representation.getElementsByTagName("BaseURL").item(0).getTextContent();
|
final String url = representation
|
||||||
|
.getElementsByTagName("BaseURL").item(0).getTextContent();
|
||||||
final ItagItem itag = ItagItem.getItag(Integer.parseInt(id));
|
final ItagItem itag = ItagItem.getItag(Integer.parseInt(id));
|
||||||
final Node segmentationList = representation.getElementsByTagName("SegmentList").item(0);
|
final Node segmentationList
|
||||||
|
= representation.getElementsByTagName("SegmentList").item(0);
|
||||||
|
|
||||||
|
// If SegmentList is not null this means that BaseUrl is not representing the
|
||||||
|
// url to the stream. Instead we need to add the "media=" value from the
|
||||||
|
// <SegementURL/> tags inside the <SegmentList/> tag in order to get a full
|
||||||
|
// working url. However each of these is just pointing to a part of the video,
|
||||||
|
// so we can not return a URL with a working stream here. Instead of putting
|
||||||
|
// those streams into the list of regular stream urls we put them in a for
|
||||||
|
// example "segmentedVideoStreams" list.
|
||||||
|
|
||||||
// if SegmentList is not null this means that BaseUrl is not representing the url to the stream.
|
|
||||||
// instead we need to add the "media=" value from the <SegementURL/> tags inside the <SegmentList/>
|
|
||||||
// tag in order to get a full working url. However each of these is just pointing to a part of the
|
|
||||||
// video, so we can not return a URL with a working stream here.
|
|
||||||
// Instead of putting those streams into the list of regular stream urls wie put them in a
|
|
||||||
// for example "segmentedVideoStreams" list.
|
|
||||||
if (itag != null) {
|
|
||||||
final MediaFormat mediaFormat = MediaFormat.getFromMimeType(mimeType);
|
final MediaFormat mediaFormat = MediaFormat.getFromMimeType(mimeType);
|
||||||
|
|
||||||
if (itag.itagType.equals(ItagItem.ItagType.AUDIO)) {
|
if (itag.itagType.equals(ItagItem.ItagType.AUDIO)) {
|
||||||
if (segmentationList == null) {
|
if (segmentationList == null) {
|
||||||
final AudioStream audioStream = new AudioStream(url, mediaFormat, itag.avgBitrate);
|
final AudioStream audioStream
|
||||||
if (!Stream.containSimilarStream(audioStream, streamInfo.getAudioStreams())) {
|
= new AudioStream(url, mediaFormat, itag.avgBitrate);
|
||||||
|
if (!Stream.containSimilarStream(audioStream,
|
||||||
|
streamInfo.getAudioStreams())) {
|
||||||
audioStreams.add(audioStream);
|
audioStreams.add(audioStream);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -170,7 +177,8 @@ public class DashMpdParser {
|
||||||
new AudioStream(id, mediaFormat, itag.avgBitrate));
|
new AudioStream(id, mediaFormat, itag.avgBitrate));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
boolean isVideoOnly = itag.itagType.equals(ItagItem.ItagType.VIDEO_ONLY);
|
final boolean isVideoOnly
|
||||||
|
= itag.itagType.equals(ItagItem.ItagType.VIDEO_ONLY);
|
||||||
|
|
||||||
if (segmentationList == null) {
|
if (segmentationList == null) {
|
||||||
final VideoStream videoStream = new VideoStream(url,
|
final VideoStream videoStream = new VideoStream(url,
|
||||||
|
@ -179,10 +187,12 @@ public class DashMpdParser {
|
||||||
isVideoOnly);
|
isVideoOnly);
|
||||||
|
|
||||||
if (isVideoOnly) {
|
if (isVideoOnly) {
|
||||||
if (!Stream.containSimilarStream(videoStream, streamInfo.getVideoOnlyStreams())) {
|
if (!Stream.containSimilarStream(videoStream,
|
||||||
|
streamInfo.getVideoOnlyStreams())) {
|
||||||
videoOnlyStreams.add(videoStream);
|
videoOnlyStreams.add(videoStream);
|
||||||
}
|
}
|
||||||
} else if (!Stream.containSimilarStream(videoStream, streamInfo.getVideoStreams())) {
|
} else if (!Stream.containSimilarStream(videoStream,
|
||||||
|
streamInfo.getVideoStreams())) {
|
||||||
videoStreams.add(videoStream);
|
videoStreams.add(videoStream);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -198,8 +208,7 @@ public class DashMpdParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (final Exception ignored) {
|
||||||
} catch (Exception ignored) {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new ParserResult(
|
return new ParserResult(
|
||||||
|
@ -209,7 +218,7 @@ public class DashMpdParser {
|
||||||
segmentedVideoStreams,
|
segmentedVideoStreams,
|
||||||
segmentedAudioStreams,
|
segmentedAudioStreams,
|
||||||
segmentedVideoOnlyStreams);
|
segmentedVideoOnlyStreams);
|
||||||
} catch (Exception e) {
|
} catch (final Exception e) {
|
||||||
throw new DashMpdParsingException("Could not parse Dash mpd", e);
|
throw new DashMpdParsingException("Could not parse Dash mpd", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue