-updated getStreams, fixes language stream selection

-refs #89518

git-svn-id: svn://svn.jdownloader.org/jdownloader/trunk@49874 ebf7c1c2-ba36-0410-9fe8-c592906822b4

Former-commit-id: c175e908f373df1a1da903d35051f66f4f4633c8
This commit is contained in:
jiaz 2024-09-26 14:50:35 +00:00
parent 04785f13d6
commit e333aff13a
2 changed files with 40 additions and 37 deletions

View File

@ -8,9 +8,12 @@ import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import jd.plugins.DownloadLink;
import org.appwork.utils.StringUtils;
import org.jdownloader.plugins.components.youtube.itag.YoutubeITAG;
import org.jdownloader.plugins.components.youtube.variants.AbstractVariant;
import org.jdownloader.plugins.components.youtube.variants.AudioInterface;
import org.jdownloader.plugins.components.youtube.variants.DescriptionVariantInfo;
import org.jdownloader.plugins.components.youtube.variants.SubtitleVariant;
import org.jdownloader.plugins.components.youtube.variants.SubtitleVariantInfo;
@ -20,8 +23,6 @@ import org.jdownloader.plugins.components.youtube.variants.VideoVariant;
import org.jdownloader.plugins.components.youtube.variants.YoutubeSubtitleStorable;
import org.jdownloader.settings.staticreferences.CFG_YOUTUBE;
import jd.plugins.DownloadLink;
public class YoutubeClipData {
/**
*
@ -261,7 +262,7 @@ public class YoutubeClipData {
}
}
public StreamCollection getStreams(YoutubeITAG itag) {
public StreamCollection getStreams(final YoutubeITAG itag, AbstractVariant variant) {
if (itag == null) {
return null;
}
@ -278,6 +279,10 @@ public class YoutubeClipData {
}
}
}
if (ret != null && itag.getAudioCodec() != null && variant instanceof AudioInterface) {
final String audioId = ((AudioInterface) variant).getAudioId();
ret = splitByLngId(ret).get(audioId);
}
return ret;
}
@ -300,24 +305,18 @@ public class YoutubeClipData {
return descriptions;
}
private List<StreamCollection> splitByLngId(StreamCollection collection) {
final ArrayList<StreamCollection> ret = new ArrayList<StreamCollection>();
if (collection.size() <= 1) {
ret.add(collection);
} else {
final Map<String, StreamCollection> map = new HashMap<String, StreamCollection>();
for (final YoutubeStreamData stream : collection) {
final String lng = stream.getLngId();
StreamCollection col = map.get(lng);
if (col == null) {
col = new StreamCollection();
map.put(lng, col);
}
col.add(stream);
private Map<String, StreamCollection> splitByLngId(StreamCollection collection) {
final Map<String, StreamCollection> map = new HashMap<String, StreamCollection>();
for (final YoutubeStreamData stream : collection) {
final String lng = stream.getLngId();
StreamCollection col = map.get(lng);
if (col == null) {
col = new StreamCollection();
map.put(lng, col);
}
ret.addAll(map.values());
col.add(stream);
}
return ret;
return map;
}
public List<VariantInfo> findVariants() {
@ -354,7 +353,7 @@ public class YoutubeClipData {
}
if (valid) {
if (audios != null) {
for (StreamCollection audio : splitByLngId(audios)) {
for (StreamCollection audio : splitByLngId(audios).values()) {
final AbstractVariant abstractVariant = AbstractVariant.get(v, this, audio, video, data);
if (abstractVariant != null) {
final VariantInfo vi = new VariantInfo(abstractVariant, audio, video, data);

View File

@ -265,25 +265,25 @@ public abstract class AbstractVariant<Data extends AbstractGenericVariantInfo> i
}
private static final SimpleMapper MAPPER = new SimpleMapper() {
@Override
protected JSonFactory newJsonFactory(String jsonString) {
return new JSonFactory(jsonString) {
@Override
protected String dedupeString(String string) {
return string;
}
};
}
@Override
protected JSonFactory newJsonFactory(String jsonString) {
return new JSonFactory(jsonString) {
@Override
protected String dedupeString(String string) {
return string;
}
};
}
@Override
protected void initMapper() {
}
@Override
protected void initMapper() {
}
@Override
public boolean isPrettyPrintEnabled() {
return false;
}
};
@Override
public boolean isPrettyPrintEnabled() {
return false;
}
};
public String getStorableString() {
String ret = storableString;
@ -410,6 +410,10 @@ public abstract class AbstractVariant<Data extends AbstractGenericVariantInfo> i
AudioInterface avar = (AudioInterface) var;
sb.append(avar.getAudioBitrate().name()).append("_");
sb.append(avar.getAudioCodec().name()).append("_");
final String audioid = avar.getAudioId();
if (audioid != null) {
sb.append(avar).append("_");
}
}
if (var instanceof ImageVariant) {
sb.append(var.getBaseVariant().name()).append("_");