[YouTube] Return a copy of the hardcoded ItagItem instead of returning the reference to the hardcoded one in ItagItem.getItag

To do so, a copy constructor has been added in the class.

This fixes, for instance, an issue in NewPipe, in which the ItagItem values where not the ones corresponsing to a stream but to another, when generating DASH manifests.
This commit is contained in:
TiA4f8R 2022-03-28 19:50:03 +02:00
parent aa4c10e751
commit f61e2092a1
No known key found for this signature in database
GPG Key ID: E6D3E7F5949450DD
1 changed files with 29 additions and 1 deletions

View File

@ -106,7 +106,7 @@ public class ItagItem implements Serializable {
public static ItagItem getItag(final int itagId) throws ParsingException {
for (final ItagItem item : ITAG_LIST) {
if (itagId == item.id) {
return item;
return new ItagItem(item);
}
}
throw new ParsingException("itag " + itagId + " is not supported");
@ -173,6 +173,34 @@ public class ItagItem implements Serializable {
this.avgBitrate = avgBitrate;
}
/**
* Copy constructor of the {@link ItagItem} class.
*
* @param itagItem the {@link ItagItem} to copy its properties into a new {@link ItagItem}
*/
public ItagItem(@Nonnull final ItagItem itagItem) {
this.mediaFormat = itagItem.mediaFormat;
this.id = itagItem.id;
this.itagType = itagItem.itagType;
this.avgBitrate = itagItem.avgBitrate;
this.sampleRate = itagItem.sampleRate;
this.audioChannels = itagItem.audioChannels;
this.resolutionString = itagItem.resolutionString;
this.fps = itagItem.fps;
this.bitrate = itagItem.bitrate;
this.width = itagItem.width;
this.height = itagItem.height;
this.initStart = itagItem.initStart;
this.initEnd = itagItem.initEnd;
this.indexStart = itagItem.indexStart;
this.indexEnd = itagItem.indexEnd;
this.quality = itagItem.quality;
this.codec = itagItem.codec;
this.targetDurationSec = itagItem.targetDurationSec;
this.approxDurationMs = itagItem.approxDurationMs;
this.contentLength = itagItem.contentLength;
}
public MediaFormat getMediaFormat() {
return mediaFormat;
}