Skip to content

Instantly share code, notes, and snippets.

@PoomSmart
Last active October 23, 2025 12:56
Show Gist options
  • Select an option

  • Save PoomSmart/195e28fd8dda4722da538b0300ab0bd7 to your computer and use it in GitHub Desktop.

Select an option

Save PoomSmart/195e28fd8dda4722da538b0300ab0bd7 to your computer and use it in GitHub Desktop.
Sets the default video quality for videos on iOS YouTube.
#import <YouTubeHeader/MLQuickMenuVideoQualitySettingFormatConstraint.h>
#import <YouTubeHeader/YTSingleVideoController.h>
int targetResolution = 1440;
static NSString *getClosestQualityLabel(NSArray <MLFormat *> *formats) {
int resolution = 0;
int minDiff = INT_MAX;
for (MLFormat *format in formats) {
int height = [format height];
int diff = abs(height - targetResolution);
if (diff < minDiff) {
minDiff = diff;
resolution = height;
}
}
return [NSString stringWithFormat:@"%dp", resolution];
}
static MLQuickMenuVideoQualitySettingFormatConstraint *getConstraint(NSString *qualityLabel) {
MLQuickMenuVideoQualitySettingFormatConstraint *constraint;
@try {
constraint = [[%c(MLQuickMenuVideoQualitySettingFormatConstraint) alloc] initWithVideoQualitySetting:3 formatSelectionReason:2 qualityLabel:qualityLabel];
} @catch (id ex) {
constraint = [[%c(MLQuickMenuVideoQualitySettingFormatConstraint) alloc] initWithVideoQualitySetting:3 formatSelectionReason:2 qualityLabel:qualityLabel resolutionCap:0];
}
return constraint;
}
%hook YTSingleVideoController
- (void)setInitialAudioAndVideoConstraints {
%orig;
NSString *qualityLabel = getClosestQualityLabel([self.playerItem selectableVideoFormats]);
MLQuickMenuVideoQualitySettingFormatConstraint *constraint = getConstraint(qualityLabel);
self.playerItem.videoFormatConstraint = constraint;
}
%end
%hook YTQueuePlayerUtil
+ (void)setInitialFormatConstraintsOnPlayerItem:(MLHAMPlayerItem *)playerItem withMediaStickySettings:(MLPlayerStickySettings *)mediaStickySettings {
%orig;
NSString *qualityLabel = getClosestQualityLabel([playerItem selectableVideoFormats]);
MLQuickMenuVideoQualitySettingFormatConstraint *constraint = getConstraint(qualityLabel);
playerItem.videoFormatConstraint = constraint;
}
%end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment