Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Qata/BarMagnet
Browse files Browse the repository at this point in the history
  • Loading branch information
Qata committed Nov 7, 2017
2 parents a8c9c4d + d7ff9da commit f0c5031
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Sources/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ To find out more, tap this message.</string>
</objects>
<point key="canvasLocation" x="4253.6000000000004" y="286.69950738916259"/>
</scene>
<!--Join #barmagnet on irc.krono.net-->
<!--Join gitter.im/BarMagnet_iOS-->
<scene sceneID="M7p-TN-kNE">
<objects>
<tableViewController hidesBottomBarWhenPushed="YES" id="pml-eH-yYW" sceneMemberID="viewController">
Expand Down Expand Up @@ -1367,7 +1367,7 @@ e.g. "http://www.google.com/q=%query%"</string>
<outlet property="delegate" destination="pml-eH-yYW" id="i99-l5-r7j"/>
</connections>
</tableView>
<navigationItem key="navigationItem" title="Join #barmagnet on irc.krono.net" id="EbD-SJ-rsp"/>
<navigationItem key="navigationItem" title="Join gitter.im/BarMagnet_iOS" id="EbD-SJ-rsp"/>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="GuO-ky-5dM" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
Expand Down
2 changes: 1 addition & 1 deletion Sources/Connection Handler/TorrentJobChecker.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ - (void)connectionCheckInvocation {
NSMutableURLRequest *request =
[NSMutableURLRequest requestWithURL:[NSURL URLWithString:[TorrentDelegate.sharedInstance.currentlySelectedClient getAppendedURL]]];
[request setTimeoutInterval:0x20];
if (request) {
if (request && request.URL) {
NSData *receivedData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
if (![receivedData length]) {
[request setURL:[NSURL URLWithString:[TorrentDelegate.sharedInstance.currentlySelectedClient getUserFriendlyAppendedURL]]];
Expand Down
3 changes: 3 additions & 0 deletions Sources/Torrent Interface/Front End/qBittorrent.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@
#import "TorrentClient.h"

@interface qBittorrent : TorrentClient
{
BOOL didLogin;
}
@end
51 changes: 46 additions & 5 deletions Sources/Torrent Interface/Front End/qBittorrent.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,36 @@ - (BOOL)isValidJobsData:(NSData *)data {
return NO;
}

- (NSString *)getBaseURL {
// Access the data and build the µTorrent URL
NSString *urlString;
NSString *port = [[self getWebDataForKey:@"port"] orSome:@"80"];
NSString *url = [[self getWebDataForKey:@"url"] orSome:@"localhost"];

url = [url stringByReplacingOccurrencesOfString:@"http://" withString:@""];
url = [url stringByReplacingOccurrencesOfString:@"https://" withString:@""];

urlString = [NSString stringWithFormat:@"%@%@:%@", [self getHyperTextString], url, port];
NSLog(@"baseURL %@", urlString);

return urlString;
}

- (NSMutableURLRequest *)checkTorrentJobs {
return [NSMutableURLRequest requestWithURL:[[NSURL URLWithString:self.getBaseURL] URLByAppendingPathComponent:@"json/torrents"]];
if (!didLogin) {
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[[NSURL URLWithString:self.getBaseURL] URLByAppendingPathComponent:@"login"]];
NSError *error = nil;
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPMethod:@"POST"];
NSString *username = [[[self getWebDataForKey:@"username"] orSome:@""] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
NSString *password = [[[self getWebDataForKey:@"password"] orSome:@""] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
NSString *body = [NSString stringWithFormat:@"username=%@&password=%@", username, password];
[request setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];
didLogin = TRUE;

[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
}
return [NSMutableURLRequest requestWithURL:[[NSURL URLWithString:self.getBaseURL] URLByAppendingPathComponent:@"query/torrents"]];
}

- (id)getTorrentJobs {
Expand All @@ -44,6 +72,9 @@ - (id)getTorrentJobs {
- (NSDictionary *)virtualHandleTorrentJobs {
NSMutableDictionary *tempJobs = [NSMutableDictionary new];
NSArray *torrentJobs = [self getTorrentJobs];
NSDateFormatter *etaformat = [[NSDateFormatter alloc] init];
[etaformat setDateFormat:@"HH:mm:ss"];
[etaformat setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];

for (NSDictionary *dict in torrentJobs) {
NSString *state = @"Unknown State";
Expand Down Expand Up @@ -89,8 +120,17 @@ - (NSDictionary *)virtualHandleTorrentJobs {
}
}

NSString *eta = @"";
if ([dict[@"eta"] isKindOfClass:NSNumber.class]) {
if ([dict[@"eta"] longValue] == 8640000) {
eta = @"";
} else {
eta = [dict[@"eta"] ETAString];
}
}
if ([dict respondsToSelector:@selector(objectForKey:)]) {
[self insertTorrentJobsDictWithArray:@[ dict[@"hash"], dict[@"name"], dict[@"progress"], state, dict[@"dlspeed"], dict[@"upspeed"], dict[@"eta"] ]
[self insertTorrentJobsDictWithArray:@[ dict[@"hash"], dict[@"name"], dict[@"progress"], state, [dict[@"dlspeed"] transferRateString], [dict[@"upspeed"] transferRateString], eta, @"", @"", dict[@"size"],
dict[@"num_leechs"], dict[@"num_seeds"], dict[@"dlspeed"], dict[@"upspeed"], dict[@"ratio"], dict[@"added_on"], dict[@"completion_on"] ]
intoDict:tempJobs];
}
}
Expand All @@ -115,6 +155,7 @@ - (NSString *)parseTorrentFailure:(NSData *)response {

- (NSMutableURLRequest *)universalPOSTSetting {
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:self.getAppendedURL]];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPMethod:@"POST"];

return request;
Expand All @@ -137,21 +178,21 @@ - (NSURLRequest *)virtualHandleTorrentFile:(NSData *)fileData withURL:(NSURL *)f
- (NSURLRequest *)virtualPauseTorrent:(NSString *)hash {
NSMutableURLRequest *request = [self universalPOSTSetting];
[request setURL:[[request URL] URLByAppendingPathComponent:@"pause"]];
[request setHTTPBody:[[NSString stringWithFormat:@"hash=%@", hash.encodeAmpersands] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:[[NSString stringWithFormat:@"hash=%@", hash.encodeAmpersands.lowercaseString] dataUsingEncoding:NSUTF8StringEncoding]];
return request;
}

- (NSURLRequest *)virtualResumeTorrent:(NSString *)hash {
NSMutableURLRequest *request = [self universalPOSTSetting];
[request setURL:[[request URL] URLByAppendingPathComponent:@"resume"]];
[request setHTTPBody:[[NSString stringWithFormat:@"hash=%@", hash.encodeAmpersands] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:[[NSString stringWithFormat:@"hash=%@", hash.encodeAmpersands.lowercaseString] dataUsingEncoding:NSUTF8StringEncoding]];
return request;
}

- (NSURLRequest *)virtualRemoveTorrent:(NSString *)hash removeData:(BOOL)removeData {
NSMutableURLRequest *request = [self universalPOSTSetting];
[request setURL:[[request URL] URLByAppendingPathComponent:removeData ? @"deletePerm" : @"delete"]];
[request setHTTPBody:[[NSString stringWithFormat:@"hashes=%@", hash.encodeAmpersands] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:[[NSString stringWithFormat:@"hashes=%@", hash.encodeAmpersands.lowercaseString] dataUsingEncoding:NSUTF8StringEncoding]];
return request;
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/View Controllers/TorrentJobsTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ - (nullable UIViewController *)previewingContext:(id<UIViewControllerPreviewing>
currentJob = self.sortedKeys[path.row];

UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:path];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
TorrentDetailViewController *previewController = [storyboard instantiateViewControllerWithIdentifier:@"detail"];
[previewController setHashString:currentJob[@"hash"]];
previewingContext.sourceRect = [self.view convertRect:cell.frame fromView:self.tableView];
Expand Down Expand Up @@ -505,7 +505,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
double completeValue = [TorrentDelegate.sharedInstance.currentlySelectedClient.class completeNumber].doubleValue;
cell.percentBar.progress = completeValue ? [currentJob[@"progress"] doubleValue] / completeValue : 0;

if ([currentJob[@"ETA"] length] &&
if ([currentJob[@"ETA"] isKindOfClass:[NSString class]] && [currentJob[@"ETA"] length] &&
[currentJob[@"progress"] doubleValue] != [[TorrentDelegate.sharedInstance.currentlySelectedClient.class completeNumber] doubleValue]) {
cell.ETA.text = [NSString stringWithFormat:@"ETA: %@", currentJob[@"ETA"]];
} else if (currentJob[@"ratio"]) {
Expand Down
4 changes: 2 additions & 2 deletions Sources/en.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ To find out more, tap this message.</string>
</objects>
<point key="canvasLocation" x="2646" y="320"/>
</scene>
<!--Join #barmagnet on irc.krono.net-->
<!--Join gitter.im/BarMagnet_iOS-->
<scene sceneID="M7p-TN-kNE">
<objects>
<tableViewController hidesBottomBarWhenPushed="YES" id="pml-eH-yYW" sceneMemberID="viewController">
Expand Down Expand Up @@ -1375,7 +1375,7 @@ e.g. "http://www.google.com/q=%query%"</string>
<outlet property="delegate" destination="pml-eH-yYW" id="i99-l5-r7j"/>
</connections>
</tableView>
<navigationItem key="navigationItem" title="Join #barmagnet on irc.krono.net" id="EbD-SJ-rsp"/>
<navigationItem key="navigationItem" title="Join gitter.im/BarMagnet_iOS" id="EbD-SJ-rsp"/>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="GuO-ky-5dM" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
Expand Down

0 comments on commit f0c5031

Please sign in to comment.