Skip to content

Commit

Permalink
Fix v.redd.it video downloads (#55)
Browse files Browse the repository at this point in the history
* Use FFmpegKit to convert MPEG-TS AAC audio streams to ADTS to fix video downloads

* Bump version

* Sync to latest

* Update README
  • Loading branch information
JeffreyCA authored Jan 17, 2025
1 parent 8b21ed4 commit 916c4f9
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
path = Tweaks/FLEXing
url = https://github.com/PoomSmart/FLEXing
branch = rootless
[submodule "ffmpeg-kit"]
path = ffmpeg-kit
url = https://github.com/JeffreyCA/ffmpeg-kit-ios
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to this project will be documented in this file.

## [v1.2.2] - 2025-01-16

- Fix video downloads failing on certain v.redd.it videos
- Note that the `.deb` file is significantly larger (several MB) because of new external dependencies needed to fix the issue (FFmpegKit)

## [v1.2.1] - 2024-12-19

- Custom random and trending subreddits - you can now specify an external URL to use as the source for random and trending subreddits (in Settings > General > Custom API)
Expand Down Expand Up @@ -109,6 +114,7 @@ There are currently a few limitations:
## [v1.0.0] - 2023-10-13
- Initial release

[v1.2.2]: https://github.com/JeffreyCA/Apollo-ImprovedCustomApi/compare/v1.2.1...v1.2.2
[v1.2.1]: https://github.com/JeffreyCA/Apollo-ImprovedCustomApi/compare/v1.1.8...v1.2.1
[v1.1.8]: https://github.com/JeffreyCA/Apollo-ImprovedCustomApi/compare/v1.1.7b...v1.1.8
[v1.1.7b]: https://github.com/JeffreyCA/Apollo-ImprovedCustomApi/compare/v1.1.7...v1.1.7b
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ ApolloImprovedCustomApi_FILES = Tweak.xm CustomAPIViewController.m DefaultSubred
ApolloImprovedCustomApi_FRAMEWORKS = UIKit
ApolloImprovedCustomApi_CFLAGS = -fobjc-arc -Wno-unguarded-availability-new -Wno-module-import-in-extern-c

ApolloImprovedCustomApi_OBJ_FILES = $(shell find ffmpeg-kit -name '*.a')

SUBPROJECTS += Tweaks/FLEXing/libflex

CONTROL_FILE = $(THEOS_PROJECT_DIR)/control
Expand Down
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ Apollo for Reddit with in-app configurable API keys and several fixes and improv
- Working Imgur integration (view, delete, and upload single images and multi-image albums)
- Handle x.com links as Twitter links so that they can be opened in the Twitter app
- Suppress unwanted messages on app startup (wallpaper popup, in-app announcements, etc)
- Support new share link format (reddit.com/r/subreddit/s/xxxxxx) so they open like any other post and not in a browser
- Support media share links (reddit.com/media?url=)
- Support /s/ share links (reddit.com/r/subreddit/s/xxxxxx) natively
- Support media share links (reddit.com/media?url=) natively
- **Fully working** "New Comments Highlightifier" Ultra feature
- Use generic user agent for requests to Reddit
- Support FLEX debugging
- Use custom external sources for random and trending subreddits
- FLEX debugging
- Support custom external sources for random and trending subreddits
- Working v.redd.it video downloads

## Known issues
- Apollo Ultra features may cause app to crash
Expand All @@ -38,9 +39,10 @@ Recommended configuration:
### Requirements
- [Theos](https://github.com/theos/theos)

1. `git clone`
2. `git submodule update --init --recursive`
2. `make package` or `make package THEOS_PACKAGE_SCHEME=rootless` for rootless variant
1. `git clone https://github.com/JeffreyCA/Apollo-ImprovedCustomApi`
2. `cd Apollo-ImprovedCustomApi`
3. `git submodule update --init --recursive`
4. `make package` or `make package THEOS_PACKAGE_SCHEME=rootless` for rootless variant

## Credits
- [Apollo-CustomApiCredentials](https://github.com/EthanArbuckle/Apollo-CustomApiCredentials) by [@EthanArbuckle](https://github.com/EthanArbuckle)
Expand Down
46 changes: 45 additions & 1 deletion Tweak.xm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
#import "UserDefaultConstants.h"
#import "DefaultSubreddits.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"

// Sideload fixes
static NSDictionary *stripGroupAccessAttr(CFDictionaryRef attributes) {
NSMutableDictionary *newAttributes = [[NSMutableDictionary alloc] initWithDictionary:(__bridge id)attributes];
Expand Down Expand Up @@ -257,6 +262,46 @@ static void TryResolveShareUrl(NSString *urlString, void (^successHandler)(NSStr
}
%end

%hook _TtC6Apollo17ShareMediaManager
// Fix audio stream format for certain v.redd.it videos - newer AAC audio streams use the MPEG-TS
// container format which Apollo doesn't support, so we need to convert them to the supported ADTS format.
- (void)URLSession:(NSURLSession *)urlSession downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)fileUrl {
NSURL *originalURL = downloadTask.originalRequest.URL;
NSString *path = fileUrl.absoluteString;
NSString *fixedPath = [path stringByAppendingString:@".fixed"];
if (![[originalURL pathExtension] isEqualToString:@"aac"]) {
%orig;
return;
}

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

// Tappable text link in an inbox item (*not* the links in the PM chat bubbles)
%hook _TtC6Apollo13InboxCellNode

Expand All @@ -273,7 +318,6 @@ static void TryResolveShareUrl(NSString *urlString, void (^successHandler)(NSStr
};
TryResolveShareUrl([val absoluteString], successHandler, ignoreHandler);
}

%end

// Text view containing markdown and tappable links, can be in the header of a post or a comment
Expand Down
2 changes: 1 addition & 1 deletion control
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: ca.jeffrey.apollo-improvedcustomapi
Name: Apollo-ImprovedCustomApi
Version: 1.2.1
Version: 1.2.2
Architecture: iphoneos-arm
Description: Apollo for Reddit tweak with in-app configurable API keys
Maintainer: JeffreyCA
Expand Down
1 change: 1 addition & 0 deletions ffmpeg-kit
Submodule ffmpeg-kit added at 532b39

0 comments on commit 916c4f9

Please sign in to comment.