Skip to content

Commit f61e209

Browse files
committed
[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.
1 parent aa4c10e commit f61e209

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

  • extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/ItagItem.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public static boolean isSupported(final int itag) {
106106
public static ItagItem getItag(final int itagId) throws ParsingException {
107107
for (final ItagItem item : ITAG_LIST) {
108108
if (itagId == item.id) {
109-
return item;
109+
return new ItagItem(item);
110110
}
111111
}
112112
throw new ParsingException("itag " + itagId + " is not supported");
@@ -173,6 +173,34 @@ public ItagItem(final int id,
173173
this.avgBitrate = avgBitrate;
174174
}
175175

176+
/**
177+
* Copy constructor of the {@link ItagItem} class.
178+
*
179+
* @param itagItem the {@link ItagItem} to copy its properties into a new {@link ItagItem}
180+
*/
181+
public ItagItem(@Nonnull final ItagItem itagItem) {
182+
this.mediaFormat = itagItem.mediaFormat;
183+
this.id = itagItem.id;
184+
this.itagType = itagItem.itagType;
185+
this.avgBitrate = itagItem.avgBitrate;
186+
this.sampleRate = itagItem.sampleRate;
187+
this.audioChannels = itagItem.audioChannels;
188+
this.resolutionString = itagItem.resolutionString;
189+
this.fps = itagItem.fps;
190+
this.bitrate = itagItem.bitrate;
191+
this.width = itagItem.width;
192+
this.height = itagItem.height;
193+
this.initStart = itagItem.initStart;
194+
this.initEnd = itagItem.initEnd;
195+
this.indexStart = itagItem.indexStart;
196+
this.indexEnd = itagItem.indexEnd;
197+
this.quality = itagItem.quality;
198+
this.codec = itagItem.codec;
199+
this.targetDurationSec = itagItem.targetDurationSec;
200+
this.approxDurationMs = itagItem.approxDurationMs;
201+
this.contentLength = itagItem.contentLength;
202+
}
203+
176204
public MediaFormat getMediaFormat() {
177205
return mediaFormat;
178206
}

0 commit comments

Comments
 (0)