Skip to content

Commit

Permalink
[YouTube] Return a copy of the hardcoded ItagItem instead of returnin…
Browse files Browse the repository at this point in the history
…g 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.
  • Loading branch information
AudricV committed Mar 28, 2022
1 parent b27a1d4 commit 1fb74eb
Showing 1 changed file with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static boolean isSupported(final int itag) {
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");
Expand Down Expand Up @@ -173,6 +173,34 @@ public ItagItem(final int id,
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;
}
Expand Down

0 comments on commit 1fb74eb

Please sign in to comment.