Skip to content
This repository was archived by the owner on May 21, 2025. It is now read-only.

Commit 364cb09

Browse files
authored
Initial Upload
1 parent c505770 commit 364cb09

File tree

6 files changed

+146
-0
lines changed

6 files changed

+146
-0
lines changed

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
TARGET := iphone:clang:latest:7.0
2+
INSTALL_TARGET_PROCESSES = YouTube
3+
4+
5+
include $(THEOS)/makefiles/common.mk
6+
7+
TWEAK_NAME = YoutubeSpeed
8+
9+
YoutubeSpeed_FILES = Tweak.xm
10+
YoutubeSpeed_CFLAGS = -fobjc-arc
11+
12+
include $(THEOS_MAKE_PATH)/tweak.mk

Tweak.xm

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#define DEFAULT_RATE 2.0f
2+
3+
4+
@interface YTVarispeedSwitchControllerOption : NSObject
5+
- (id)initWithTitle:(id)title rate:(float)rate;
6+
@end
7+
8+
9+
@interface YTPlayerViewController : NSObject
10+
@property id activeVideo;
11+
@property float playbackRate;
12+
- (void)singleVideo:(id)video playbackRateDidChange:(float)rate;
13+
@end
14+
15+
16+
@interface MLHAMQueuePlayer : NSObject
17+
@property id delegate;
18+
- (void)setRate:(float)rate;
19+
- (void)internalSetRate;
20+
@end
21+
22+
23+
@interface MLPlayerStickySettings : NSObject
24+
- (void)setRate:(float)rate;
25+
@end
26+
27+
28+
@interface MLPlayerEventCenter : NSObject
29+
- (void)broadcastRateChange:(float)rate;
30+
@end
31+
32+
33+
@interface YTSingleVideoController : NSObject
34+
- (void)playerRateDidChange:(float)rate;
35+
@end
36+
37+
38+
@interface HAMPlayerInternal : NSObject
39+
- (void)setRate:(float)rate;
40+
@end
41+
42+
43+
%hook YTVarispeedSwitchController
44+
45+
- (id)init {
46+
id result = %orig;
47+
48+
const int size = 10;
49+
float speeds[] = {0.5, 1.0, 1.25, 1.5, 1.75, 2.0, 2.5, 3.0, 3.5, 4.0};
50+
id varispeedSwitchControllerOptions[size];
51+
52+
for (int i = 0; i < size; ++i) {
53+
id title = [NSString stringWithFormat:@"%.2fx", speeds[i]];
54+
varispeedSwitchControllerOptions[i] = [[%c(YTVarispeedSwitchControllerOption) alloc] initWithTitle:title rate:speeds[i]];
55+
}
56+
57+
NSUInteger count = sizeof(varispeedSwitchControllerOptions) / sizeof(id);
58+
NSArray *varispeedArray = [NSArray arrayWithObjects:varispeedSwitchControllerOptions count:count];
59+
MSHookIvar<NSArray *>(self, "_options") = varispeedArray;
60+
61+
return result;
62+
}
63+
64+
%end
65+
66+
67+
%hook YTPlayerViewController
68+
69+
%property float playbackRate;
70+
71+
- (id)initWithServiceRegistryScope:(id)serviceRegistryScope parentResponder:(id)parentResponder overlayFactory:(id)overlayFactory {
72+
float savedRate = [[NSUserDefaults standardUserDefaults] floatForKey:@"YoutubeSpeed_PlaybackRate"];
73+
self.playbackRate = savedRate == 0 ? DEFAULT_RATE : savedRate;
74+
return %orig;
75+
}
76+
77+
- (void)singleVideo:(id)video playbackRateDidChange:(float)rate {
78+
%orig;
79+
}
80+
81+
- (float)currentPlaybackRateForVarispeedSwitchController:(id)varispeedSwitchController {
82+
return self.playbackRate;
83+
}
84+
85+
- (void)varispeedSwitchController:(id)varispeedSwitchController didSelectRate:(float)rate {
86+
self.playbackRate = rate;
87+
[[NSUserDefaults standardUserDefaults] setFloat: rate forKey:@"YoutubeSpeed_PlaybackRate"];
88+
if (rate > 2.0f) {
89+
[self singleVideo:self.activeVideo playbackRateDidChange: rate];
90+
}
91+
%orig;
92+
}
93+
94+
%end
95+
96+
97+
%hook MLHAMQueuePlayer
98+
99+
- (id)initWithStickySettings:(id)stickySettings playerViewProvider:(id)playerViewProvider {
100+
id result = %orig;
101+
float savedRate = [[NSUserDefaults standardUserDefaults] floatForKey:@"YoutubeSpeed_PlaybackRate"];
102+
[self setRate: savedRate == 0 ? DEFAULT_RATE : savedRate];
103+
return result;
104+
}
105+
106+
- (void)setRate:(float)rate {
107+
MSHookIvar<float>(self, "_rate") = rate;
108+
MSHookIvar<float>(self, "_preferredRate") = rate;
109+
110+
id player = MSHookIvar<HAMPlayerInternal *>(self, "_player");
111+
[player setRate: rate];
112+
113+
id stickySettings = MSHookIvar<MLPlayerStickySettings *>(self, "_stickySettings");
114+
[stickySettings setRate: rate];
115+
116+
id playerEventCenter = MSHookIvar<MLPlayerEventCenter *>(self, "_playerEventCenter");
117+
[playerEventCenter broadcastRateChange: rate];
118+
119+
YTSingleVideoController *singleVideoController = self.delegate;
120+
[singleVideoController playerRateDidChange: rate];
121+
}
122+
123+
%end
124+

YoutubeSpeed.plist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ Filter = { Bundles = ( "com.google.ios.youtube" ); }; }
8.83 KB
Binary file not shown.
9.69 KB
Binary file not shown.

control

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Package: com.lyvendia.ytspeed
2+
Name: YTSpeed
3+
Version: 1.0.1
4+
Architecture: iphoneos-arm
5+
Description: Makes YouTube Videos speedy.
6+
Maintainer: lyvendia
7+
Author: lyvendia
8+
Section: Tweaks
9+
Depends: mobilesubstrate (>= 0.9.5000)

0 commit comments

Comments
 (0)