fix: dash roles, stream type regex
This commit is contained in:
parent
3fb356a706
commit
1aa232475e
|
@ -32,6 +32,7 @@ import java.util.Map;
|
|||
import java.util.Objects;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
@ -279,7 +280,8 @@ public final class YoutubeDashManifestCreatorsUtils {
|
|||
*
|
||||
* <p>
|
||||
* {@code <Role schemeIdUri="urn:mpeg:DASH:role:2011" value="VALUE"/>}, where {@code VALUE} is
|
||||
* {@code main} for videos and audios and {@code alternate} for descriptive audio
|
||||
* {@code main} for videos and audios, {@code description} for descriptive audio and
|
||||
* {@code dub} for dubbed audio.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
|
@ -299,10 +301,7 @@ public final class YoutubeDashManifestCreatorsUtils {
|
|||
final Element roleElement = doc.createElement(ROLE);
|
||||
|
||||
setAttribute(roleElement, doc, "schemeIdUri", "urn:mpeg:DASH:role:2011");
|
||||
setAttribute(roleElement, doc, "value",
|
||||
itagItem.getAudioTrackType() == null
|
||||
|| itagItem.getAudioTrackType() == AudioTrackType.ORIGINAL
|
||||
? "main" : "alternate");
|
||||
setAttribute(roleElement, doc, "value", getRoleValue(itagItem.getAudioTrackType()));
|
||||
|
||||
adaptationSetElement.appendChild(roleElement);
|
||||
} catch (final DOMException e) {
|
||||
|
@ -310,6 +309,27 @@ public final class YoutubeDashManifestCreatorsUtils {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of the {@code <Role>} element based on the {@link AudioTrackType} attribute
|
||||
* of a stream.
|
||||
* @param trackType audio track type
|
||||
* @return role value
|
||||
*/
|
||||
private static String getRoleValue(@Nullable final AudioTrackType trackType) {
|
||||
if (trackType != null) {
|
||||
switch (trackType) {
|
||||
case ORIGINAL:
|
||||
return "main";
|
||||
case DUBBED:
|
||||
return "dub";
|
||||
case DESCRIPTIVE:
|
||||
return "description";
|
||||
}
|
||||
return "alternate";
|
||||
}
|
||||
return "main";
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the {@code <Representation>} element, appended as a child of the
|
||||
* {@code <AdaptationSet>} element.
|
||||
|
|
|
@ -100,6 +100,7 @@ import java.util.List;
|
|||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
@ -811,8 +812,8 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||
"\\bc\\s*&&\\s*d\\.set\\([^,]+\\s*,\\s*(:encodeURIComponent\\s*\\()([a-zA-Z0-9$]+)\\("
|
||||
};
|
||||
private static final String STS_REGEX = "signatureTimestamp[=:](\\d+)";
|
||||
private static final String AUDIO_STREAM_TYPE_REGEX =
|
||||
"&xtags=[\\w\\d%]*acont(?:=|%3D)([a-z]+)(?:=|%3D|:|%3A|&|$)";
|
||||
private static final Pattern AUDIO_STREAM_TYPE_REGEX =
|
||||
Pattern.compile("&xtags=[\\w%]*acont(?:=|%3D)([a-z]+)(?:=|%3D|:|%3A|&|$)");
|
||||
|
||||
@Override
|
||||
public void onFetchPage(@Nonnull final Downloader downloader)
|
||||
|
@ -1499,7 +1500,6 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||
break;
|
||||
case "descriptive":
|
||||
itagItem.setAudioTrackType(AudioTrackType.DESCRIPTIVE);
|
||||
break;
|
||||
}
|
||||
} catch (final Parser.RegexException ignored) { }
|
||||
}
|
||||
|
|
|
@ -29,5 +29,5 @@ public enum AudioTrackType {
|
|||
* @see <a href="https://en.wikipedia.org/wiki/Audio_description">
|
||||
* https://en.wikipedia.org/wiki/Audio_description</a>
|
||||
*/
|
||||
DESCRIPTIVE,
|
||||
DESCRIPTIVE
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ public class DownloaderFactory {
|
|||
|
||||
public static final String RESOURCE_PATH = "src/test/resources/org/schabi/newpipe/extractor/";
|
||||
|
||||
private static final DownloaderType DEFAULT_DOWNLOADER = DownloaderType.RECORDING;
|
||||
private static final DownloaderType DEFAULT_DOWNLOADER = DownloaderType.REAL;
|
||||
|
||||
public static DownloaderType getDownloaderType() {
|
||||
try {
|
||||
|
|
|
@ -234,8 +234,27 @@ class YoutubeDashManifestCreatorsTest {
|
|||
private void assertRoleElement(@Nonnull final Document document,
|
||||
@Nonnull final ItagItem itagItem) {
|
||||
final Element element = assertGetElement(document, ROLE, ADAPTATION_SET);
|
||||
assertAttrEquals(itagItem.getAudioTrackType() == null || itagItem.getAudioTrackType() == AudioTrackType.ORIGINAL
|
||||
? "main" : "alternate", element, "value");
|
||||
|
||||
final String expect;
|
||||
if (itagItem.getAudioTrackType() == null) {
|
||||
expect = "main";
|
||||
} else {
|
||||
switch (itagItem.getAudioTrackType()) {
|
||||
case ORIGINAL:
|
||||
expect = "main";
|
||||
break;
|
||||
case DUBBED:
|
||||
expect = "dub";
|
||||
break;
|
||||
case DESCRIPTIVE:
|
||||
expect = "description";
|
||||
break;
|
||||
default:
|
||||
expect = "alternate";
|
||||
}
|
||||
}
|
||||
|
||||
assertAttrEquals(expect, element, "value");
|
||||
}
|
||||
|
||||
private void assertRepresentationElement(@Nonnull final Document document,
|
||||
|
|
Loading…
Reference in New Issue