forked from Apollo-Reborn/Apollo-Reborn
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApolloMedia.xm
More file actions
528 lines (438 loc) · 21.4 KB
/
Copy pathApolloMedia.xm
File metadata and controls
528 lines (438 loc) · 21.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
#import <objc/runtime.h>
#import <objc/message.h>
#import "ApolloCommon.h"
#import "ApolloState.h"
#import "Tweak.h"
#import "ffmpeg-kit/ffmpeg-kit/include/MediaInformationSession.h"
#import "ffmpeg-kit/ffmpeg-kit/include/MediaInformation.h"
#import "ffmpeg-kit/ffmpeg-kit/include/FFmpegKit.h"
#import "ffmpeg-kit/ffmpeg-kit/include/FFprobeKit.h"
// Regex patterns for v.redd.it CMAF audio streams (Reddit switched from MPEG-TS to CMAF around November 2025)
static NSString *const HLSAudioRegexPattern = @"#EXT-X-MEDIA:.*?\"(HLS_AUDIO.*?)\\.m3u8";
static NSString *const CMAFAudioRegexPattern = @"#EXT-X-MEDIA:.*?\"((?:HLS|CMAF)_AUDIO.*?)\\.m3u8";
static NSString *const CMAFAudioIdentifier = @"CMAF_AUDIO";
// Regex patterns for Streamable URLs (some Streamable links have new query strings)
static NSString *const StreamableRegexPattern = @"^(?:(?:https?:)?//)?(?:www\\.)?streamable\\.com/(?:edit/)?(\\w+)$";
static NSString *const StreamableRegexPatternWithQueryString = @"^(?:(?:https?:)?//)?(?:www\\.)?streamable\\.com/(?:edit/)?(\\w+)(?:\\?.*)?$";
// Implementation derived from https://github.com/dankrichtofen/apolloliquidglass/blob/main/Tweak.x
// Credits to @dankrichtofen for the original implementation
%hook ASImageNode
+ (UIImage *)createContentsForkey:(id)key drawParameters:(id)parameters isCancelled:(id)cancelled {
@try {
UIImage *result = %orig;
return result;
}
@catch (NSException *exception) {
return nil;
}
}
%end
// Fix GIF looping playback speed on 120Hz ProMotion displays
// Implementation derived from https://github.com/Flipboard/FLAnimatedImage/pull/266
// Credits to @yoshimura-qcul for the original fix
%hook FLAnimatedImageView
- (void)displayDidRefresh:(CADisplayLink *)displayLink {
// Get required ivars
FLAnimatedImage *animatedImage = MSHookIvar<FLAnimatedImage *>(self, "_animatedImage");
if (!animatedImage) {
return;
}
BOOL shouldAnimate = MSHookIvar<BOOL>(self, "_shouldAnimate");
if (!shouldAnimate) {
return;
}
NSDictionary *delayTimesForIndexes = [animatedImage delayTimesForIndexes];
NSUInteger currentFrameIndex = MSHookIvar<NSUInteger>(self, "_currentFrameIndex");
NSNumber *delayTimeNumber = [delayTimesForIndexes objectForKey:@(currentFrameIndex)];
if (delayTimeNumber != nil) {
NSTimeInterval delayTime = [delayTimeNumber doubleValue];
UIImage *image = [animatedImage imageLazilyCachedAtIndex:currentFrameIndex];
if (image) {
MSHookIvar<UIImage *>(self, "_currentFrame") = image;
BOOL needsDisplay = MSHookIvar<BOOL>(self, "_needsDisplayWhenImageBecomesAvailable");
if (needsDisplay) {
[self.layer setNeedsDisplay];
MSHookIvar<BOOL>(self, "_needsDisplayWhenImageBecomesAvailable") = NO;
}
// Fix for 120Hz displays: use preferredFramesPerSecond instead of duration * frameInterval
double *accumulatorPtr = &MSHookIvar<double>(self, "_accumulator");
if (@available(iOS 10.0, *)) {
NSInteger preferredFPS = displayLink.preferredFramesPerSecond;
if (preferredFPS > 0) {
*accumulatorPtr += 1.0 / (double)preferredFPS;
} else {
*accumulatorPtr += displayLink.duration;
}
} else {
*accumulatorPtr += displayLink.duration;
}
NSUInteger frameCount = [animatedImage frameCount];
NSUInteger loopCount = [animatedImage loopCount];
while (*accumulatorPtr >= delayTime) {
*accumulatorPtr -= delayTime;
MSHookIvar<NSUInteger>(self, "_currentFrameIndex")++;
if (MSHookIvar<NSUInteger>(self, "_currentFrameIndex") >= frameCount) {
MSHookIvar<NSUInteger>(self, "_loopCountdown")--;
void (^loopCompletionBlock)(NSUInteger) = MSHookIvar<void (^)(NSUInteger)>(self, "_loopCompletionBlock");
if (loopCompletionBlock) {
loopCompletionBlock(MSHookIvar<NSUInteger>(self, "_loopCountdown"));
}
if (MSHookIvar<NSUInteger>(self, "_loopCountdown") == 0 && loopCount > 0) {
[self stopAnimating];
return;
}
MSHookIvar<NSUInteger>(self, "_currentFrameIndex") = 0;
}
MSHookIvar<BOOL>(self, "_needsDisplayWhenImageBecomesAvailable") = YES;
}
} else {
MSHookIvar<BOOL>(self, "_needsDisplayWhenImageBecomesAvailable") = YES;
}
} else {
MSHookIvar<NSUInteger>(self, "_currentFrameIndex")++;
}
}
%end
// Fix MP4 GIF loop freeze in MediaViewerController fullscreen player
//
// Stock Apollo bug: on every loop boundary, the didPlayToEnd handler
// (sub_10036da80) dispatches two `seekToTime:kCMTimeZero` calls ~1 ms apart
// from sibling DispatchQueue.main.async blocks. The second seek interrupts
// the first mid-flight, double-resetting the decode pipeline and causing a
// ~0.5–1.5s freeze at a random mid-video frame on every loop after the first.
//
// Scoping: `-[AVPlayer setActionAtItemEnd:]` has exactly one xref in Apollo
// (inside createPlayer(withURL:) at sub_100363c90, called with
// AVPlayerActionAtItemEndNone). We use that single call as a tag for the
// MediaViewer non-shareable player; shareable v.redd.it, comments header,
// and feed cell players leave actionAtItemEnd at its default and are not
// touched. Fix: on tagged players, dedupe seek-to-zero calls within a
// 250 ms window — first call goes through to %orig, subsequent ones invoke
// only their completionHandler so caller state machinery still runs.
static const void *kApolloGifLoopFixKey = &kApolloGifLoopFixKey;
static const void *kApolloGifLoopLastSeekKey = &kApolloGifLoopLastSeekKey;
static const void *kApolloGifLoopDedupeLoggedKey = &kApolloGifLoopDedupeLoggedKey;
static const NSTimeInterval kApolloGifLoopSeekDedupeWindow = 0.25;
%hook AVPlayer
- (void)setActionAtItemEnd:(AVPlayerActionAtItemEnd)action {
%orig;
if (action == AVPlayerActionAtItemEndNone) {
if (objc_getAssociatedObject(self, kApolloGifLoopFixKey) != nil) {
return;
}
objc_setAssociatedObject(self, kApolloGifLoopFixKey, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
ApolloLog(@"[GifLoopFix] Marked AVPlayer %p (actionAtItemEnd=None)", self);
}
}
- (void)seekToTime:(CMTime)time toleranceBefore:(CMTime)toleranceBefore toleranceAfter:(CMTime)toleranceAfter completionHandler:(void (^)(BOOL))completionHandler {
BOOL isLoopFixPlayer = (objc_getAssociatedObject(self, kApolloGifLoopFixKey) != nil);
BOOL isZeroSeek = CMTIME_IS_VALID(time) && CMTimeCompare(time, kCMTimeZero) == 0;
if (isLoopFixPlayer && isZeroSeek) {
NSTimeInterval now = CACurrentMediaTime();
NSNumber *lastSeek = objc_getAssociatedObject(self, kApolloGifLoopLastSeekKey);
NSTimeInterval delta = lastSeek ? (now - lastSeek.doubleValue) : INFINITY;
if (delta < kApolloGifLoopSeekDedupeWindow) {
// Sibling seek from same didPlayToEnd handler — skip %orig but
// still invoke completionHandler so caller state logic runs.
if (objc_getAssociatedObject(self, kApolloGifLoopDedupeLoggedKey) == nil) {
objc_setAssociatedObject(self, kApolloGifLoopDedupeLoggedKey, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
ApolloLog(@"[GifLoopFix] Deduping sibling seek-to-zero on %p (%.1fms after first); will suppress further per-loop logs",
self, delta * 1000.0);
}
if (completionHandler) {
void (^handler)(BOOL) = [completionHandler copy];
dispatch_async(dispatch_get_main_queue(), ^{
handler(YES);
});
}
return;
}
objc_setAssociatedObject(self, kApolloGifLoopLastSeekKey, @(now), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
%orig;
}
%end
%hook NSRegularExpression
- (instancetype)initWithPattern:(NSString *)pattern options:(NSRegularExpressionOptions)options error:(NSError **)error {
// Around November 2025, Reddit started using CMAF instead of MPEG-TS for audio streams (v.redd.it).
// Apollo's regex only matches HLS_AUDIO naming pattern, so update to also match CMAF_AUDIO
if ([pattern isEqualToString:HLSAudioRegexPattern]) {
return %orig(CMAFAudioRegexPattern, options, error);
}
// Handle newer Streamable links with query strings like "?src=player-page-share"
if ([pattern isEqualToString:StreamableRegexPattern]) {
return %orig(StreamableRegexPatternWithQueryString, options, error);
}
return %orig;
}
- (NSArray<NSTextCheckingResult *> *)matchesInString:(NSString *)string options:(NSMatchingOptions)options range:(NSRange)range {
NSArray *results = %orig;
// CMAF manifests list audio in descending bitrate order:
// #EXT-X-MEDIA:URI="CMAF_AUDIO_128.m3u8",...
// #EXT-X-MEDIA:URI="CMAF_AUDIO_64.m3u8",...
// but Apollo expects ascending order (how older MPEG-TS streams were ordered),
// so we need to reorder the results so Apollo downloads the highest quality audio.
if (results.count >= 2 && [self.pattern isEqualToString:CMAFAudioRegexPattern]) {
// Sort by extracting bitrate number from captured text
results = [results sortedArrayUsingComparator:^NSComparisonResult(NSTextCheckingResult *result1, NSTextCheckingResult *result2) {
if (result1.numberOfRanges > 1 && result2.numberOfRanges > 1) {
NSString *text1 = [string substringWithRange:[result1 rangeAtIndex:1]];
NSString *text2 = [string substringWithRange:[result2 rangeAtIndex:1]];
// Use NSScanner to extract first integer from each string
NSScanner *scanner1 = [NSScanner scannerWithString:text1];
NSScanner *scanner2 = [NSScanner scannerWithString:text2];
NSInteger bitrate1 = 0, bitrate2 = 0;
[scanner1 scanUpToCharactersFromSet:[NSCharacterSet decimalDigitCharacterSet] intoString:nil];
[scanner1 scanInteger:&bitrate1];
[scanner2 scanUpToCharactersFromSet:[NSCharacterSet decimalDigitCharacterSet] intoString:nil];
[scanner2 scanInteger:&bitrate2];
return [@(bitrate1) compare:@(bitrate2)];
}
return NSOrderedSame;
}];
}
return results;
}
%end
%hook NSURLRequest
+ (instancetype)requestWithURL:(NSURL *)URL {
// Fix CMAF audio URLs: Apollo tries to download .aac but CMAF uses .mp4
if ([URL.pathExtension isEqualToString:@"aac"] && [URL.absoluteString containsString:CMAFAudioIdentifier]) {
NSURL *fixedURL = [[URL URLByDeletingPathExtension] URLByAppendingPathExtension:@"mp4"];
ApolloLog(@"[NSURLRequest] Fixed CMAF audio URL: %@ -> %@", URL.absoluteString, fixedURL.absoluteString);
return %orig(fixedURL);
}
return %orig;
}
%end
%hook _TtC6Apollo17ShareMediaManager
// Patches to fix audio container formats for v.redd.it videos:
// - Some streams use MPEG-TS containers (fix: convert to ADTS)
// - Newer streams use CMAF/MP4 containers (fix: extract AAC and wrap in ADTS)
- (void)URLSession:(NSURLSession *)urlSession downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)fileUrl {
NSURL *originalURL = downloadTask.originalRequest.URL;
NSString *path = fileUrl.absoluteString;
NSString *fixedPath = [path stringByAppendingString:@".fixed"];
BOOL isCMAFAudio = [originalURL.absoluteString containsString:@"CMAF_AUDIO"] && [originalURL.pathExtension isEqualToString:@"mp4"];
BOOL isHLSAudio = [originalURL.pathExtension isEqualToString:@"aac"];
if (!isCMAFAudio && !isHLSAudio) {
%orig;
return;
}
if (isCMAFAudio) {
// CMAF audio is MP4 container with AAC - extract to ADTS format
ApolloLog(@"[-URLSession:downloadTask:didFinishDownloadingToURL:] Converting CMAF MP4 audio to ADTS: %@", originalURL);
NSString *ffmpegCommand = [NSString stringWithFormat:@"-y -loglevel info -i '%@' -vn -acodec copy -f adts '%@.fixed'", path, path];
FFmpegSession *session = [FFmpegKit execute:ffmpegCommand];
ReturnCode *returnCode = [session getReturnCode];
if ([ReturnCode isSuccess:returnCode]) {
// Replace original file with fixed version
NSURL *fixedUrl = [NSURL URLWithString:fixedPath];
NSFileManager *fileManager = [NSFileManager defaultManager];
[fileManager removeItemAtURL:fileUrl error:nil];
[fileManager moveItemAtURL:fixedUrl toURL:fileUrl error:nil];
}
%orig;
return;
}
// MPEG-TS AAC processing
ApolloLog(@"[-URLSession:downloadTask:didFinishDownloadingToURL:] Processing AAC file: %@", originalURL);
MediaInformationSession *probeSession = [FFprobeKit getMediaInformation:path];
ReturnCode *returnCode = [probeSession getReturnCode];
if (![ReturnCode isSuccess:returnCode]) {
%orig;
return;
}
MediaInformation *mediaInformation = [probeSession getMediaInformation];
if (!mediaInformation || ![mediaInformation.getFormat isEqualToString:@"mpegts"]) {
%orig;
return;
}
NSString *ffmpegCommand = [NSString stringWithFormat:@"-y -loglevel info -i '%@' -map 0 -dn -ignore_unknown -c copy -f adts '%@.fixed'", path, path];
FFmpegSession *session = [FFmpegKit execute:ffmpegCommand];
returnCode = [session getReturnCode];
if ([ReturnCode isSuccess:returnCode]) {
// Replace original file with fixed version
NSURL *fixedUrl = [NSURL URLWithString:fixedPath];
NSFileManager *fileManager = [NSFileManager defaultManager];
[fileManager removeItemAtURL:fileUrl error:nil];
[fileManager moveItemAtURL:fixedUrl toURL:fileUrl error:nil];
}
%orig;
}
%end
// MARK: - Giphy Media Metadata Fix
static NSString *ApolloExtractGiphyIDFromToken(NSString *token) {
if (![token isKindOfClass:[NSString class]] || token.length == 0) {
return nil;
}
NSRange prefixRange = [token rangeOfString:@"giphy|"];
if (prefixRange.location == NSNotFound) {
return nil;
}
NSString *suffix = [token substringFromIndex:(prefixRange.location + prefixRange.length)];
if (suffix.length == 0) {
return nil;
}
NSRange nextPipe = [suffix rangeOfString:@"|"];
NSString *giphyID = (nextPipe.location == NSNotFound) ? suffix : [suffix substringToIndex:nextPipe.location];
return giphyID.length > 0 ? giphyID : nil;
}
static BOOL ApolloIsValidGiphyID(NSString *giphyID) {
if (![giphyID isKindOfClass:[NSString class]] || giphyID.length == 0) {
return NO;
}
// Giphy IDs are alphanumeric with possible underscores/dashes
for (NSUInteger i = 0; i < giphyID.length; i++) {
unichar c = [giphyID characterAtIndex:i];
if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '_' || c == '-')) {
return NO;
}
}
return YES;
}
static NSDictionary *ApolloFixInvalidGiphyMetadata(NSDictionary *orig, NSUInteger *outSynthesizedCount) {
if (outSynthesizedCount) {
*outSynthesizedCount = 0;
}
if (![orig isKindOfClass:[NSDictionary class]] || orig.count == 0) {
return orig;
}
NSMutableDictionary *fixed = nil;
NSUInteger synthesizedCount = 0;
for (NSString *key in orig) {
if (![key isKindOfClass:[NSString class]] || ![key hasPrefix:@"giphy|"]) {
continue;
}
NSDictionary *entry = orig[key];
if (![entry isKindOfClass:[NSDictionary class]]) {
continue;
}
NSString *status = entry[@"status"];
if ([status isKindOfClass:[NSString class]] && [status isEqualToString:@"valid"]) {
continue;
}
NSString *giphyID = ApolloExtractGiphyIDFromToken(key);
if (!ApolloIsValidGiphyID(giphyID)) {
continue;
}
if (!fixed) {
fixed = [orig mutableCopy];
}
NSString *extURL = [NSString stringWithFormat:@"https://giphy.com/gifs/%@", giphyID];
NSString *gifURL = [NSString stringWithFormat:@"https://media.giphy.com/media/%@/giphy.gif", giphyID];
NSString *thumbURL = [NSString stringWithFormat:@"https://media.giphy.com/media/%@/200w_s.gif", giphyID];
fixed[key] = @{
@"status": @"valid",
@"e": @"AnimatedImage",
@"m": @"image/gif",
@"ext": extURL,
@"p": @[@{@"y": @200, @"x": @200, @"u": thumbURL}],
// Must use gifURL for 'mp4' or else will open in webview
@"s": @{@"y": @200, @"gif": gifURL, @"mp4": gifURL, @"x": @200},
@"t": @"giphy",
@"id": key,
};
synthesizedCount++;
}
if (outSynthesizedCount) {
*outSynthesizedCount = synthesizedCount;
}
return fixed ?: orig;
}
// MARK: - "Processing img" Placeholder Fix (shared between RDKComment and RDKLink)
// Resolve a single media ID to an image URL from media_metadata.
// Returns nil if the ID is not found or invalid.
static NSString *ApolloResolveMediaURL(NSString *mediaId, NSDictionary *metadata, NSString **outLabel) {
if (outLabel) *outLabel = @"Image";
NSDictionary *entry = metadata[mediaId];
if (![entry isKindOfClass:[NSDictionary class]]) return nil;
if (![[entry objectForKey:@"status"] isEqualToString:@"valid"]) return nil;
NSString *url = nil;
NSDictionary *source = entry[@"s"];
if ([source isKindOfClass:[NSDictionary class]]) {
url = (sPreferredGIFFallbackFormat == 0)
? (source[@"gif"] ?: source[@"mp4"] ?: source[@"u"])
: (source[@"mp4"] ?: source[@"gif"] ?: source[@"u"]);
}
if (!url) {
NSArray *previews = entry[@"p"];
if ([previews isKindOfClass:[NSArray class]] && previews.count > 0) {
url = [previews.lastObject objectForKey:@"u"];
}
}
if (![url isKindOfClass:[NSString class]] || url.length == 0) return nil;
if (outLabel && [[entry objectForKey:@"e"] isEqualToString:@"AnimatedImage"]) *outLabel = @"GIF";
return url;
}
// Replace "*Processing img <id>...*" placeholders with markdown image links.
// Uses media_metadata for URL resolution, with an optional i.redd.it fallback extension
// for when metadata is unavailable (e.g. posts where media_metadata hasn't been populated yet).
static NSString *ApolloFixProcessingImgPlaceholders(NSString *text, NSDictionary *metadata, NSString *fallbackExtension) {
if (!text || ![text containsString:@"Processing img "]) return text;
BOOL hasMetadata = [metadata isKindOfClass:[NSDictionary class]] && metadata.count > 0;
if (!hasMetadata && !fallbackExtension) return text;
static NSRegularExpression *regex;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
regex = [NSRegularExpression regularExpressionWithPattern:@"\\*Processing img ([a-zA-Z0-9_]+)\\.{3}\\*" options:0 error:nil];
});
NSMutableString *fixed = [text mutableCopy];
NSArray *matches = [regex matchesInString:fixed options:0 range:NSMakeRange(0, fixed.length)];
if (matches.count == 0) return text;
NSUInteger replacedCount = 0;
for (NSTextCheckingResult *match in [matches reverseObjectEnumerator]) {
NSString *mediaId = [fixed substringWithRange:[match rangeAtIndex:1]];
NSString *label = nil;
NSString *url = hasMetadata ? ApolloResolveMediaURL(mediaId, metadata, &label) : nil;
// Fallback: construct i.redd.it URL
if (!url && fallbackExtension) {
url = [NSString stringWithFormat:@"https://i.redd.it/%@.%@", mediaId, fallbackExtension];
label = @"Image";
}
if (!url) continue;
NSString *replacement = [NSString stringWithFormat:@"[%@](%@)", label, url];
[fixed replaceCharactersInRange:match.range withString:replacement];
replacedCount++;
}
if (replacedCount > 0) {
ApolloLog(@"[ProcessingImg] Replaced %lu placeholder%@ in text",
(unsigned long)replacedCount, (replacedCount == 1 ? @"" : @"s"));
}
return replacedCount > 0 ? fixed : text;
}
%hook RDKComment
- (void)setMediaMetadata:(NSDictionary *)mediaMetadata {
NSUInteger synthesizedCount = 0;
NSDictionary *fixed = ApolloFixInvalidGiphyMetadata(mediaMetadata, &synthesizedCount);
%orig(fixed);
}
- (NSString *)body {
return ApolloFixProcessingImgPlaceholders(%orig, self.mediaMetadata, nil);
}
%end
%hook RDKLink
- (void)setMediaMetadata:(NSDictionary *)mediaMetadata {
NSUInteger synthesizedCount = 0;
NSDictionary *fixed = ApolloFixInvalidGiphyMetadata(mediaMetadata, &synthesizedCount);
%orig(fixed);
}
- (NSString *)selfText {
// Determine fallback extension from preview source image URL
NSString *fallbackExt = nil;
NSDictionary *metadata = self.mediaMetadata;
if (![metadata isKindOfClass:[NSDictionary class]] || metadata.count == 0) {
RDKLinkPreviewItem *sourceImage = self.previewMedia.sourceImage;
if (sourceImage.URL) {
fallbackExt = sourceImage.URL.path.pathExtension;
}
if (fallbackExt.length == 0) fallbackExt = @"png";
}
return ApolloFixProcessingImgPlaceholders(%orig, metadata, fallbackExt);
}
%end
%ctor {
%init;
}