Commit 86c8d1ca authored by Pierre SAGASPE's avatar Pierre SAGASPE Committed by Felix Paul Kühne

plex: clean and remove of duplicate functions

Signed-off-by: Felix Paul Kühne's avatarFelix Paul Kühne <fkuehne@videolan.org>
parent 74c5e9e2
......@@ -277,7 +277,7 @@
ObjList = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:newPath authentification:_PlexAuthentification];
NSString *URLofSubtitle = nil;
if ([[ObjList objectAtIndex:0] objectForKey:@"keySubtitle"])
URLofSubtitle = [_PlexParser getFileSubtitleFromPlexServer:ObjList modeStream:YES];
URLofSubtitle = [_PlexWebAPI getFileSubtitleFromPlexServer:ObjList modeStream:YES];
NSURL *itemURL = [NSURL URLWithString:[self _urlAuth:[[ObjList objectAtIndex:0] objectForKey:@"keyMedia"]]];
if (itemURL) {
......@@ -313,7 +313,7 @@
mutableMediaObject = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:newPath authentification:_PlexAuthentification];
NSString *URLofSubtitle = nil;
if ([[mutableMediaObject objectAtIndex:0] objectForKey:@"keySubtitle"])
URLofSubtitle = [_PlexParser getFileSubtitleFromPlexServer:mutableMediaObject modeStream:YES];
URLofSubtitle = [_PlexWebAPI getFileSubtitleFromPlexServer:mutableMediaObject modeStream:YES];
NSURL *itemURL = [NSURL URLWithString:[self _urlAuth:[[mutableMediaObject objectAtIndex:0] objectForKey:@"keyMedia"]]];
if (itemURL) {
......@@ -352,7 +352,7 @@
NSString *tag = [[ObjList objectAtIndex:0] objectForKey:@"state"];
NSString *cellStatusLbl = nil;
NSInteger status = [_PlexParser MarkWatchedUnwatchedMedia:_PlexServerAddress port:_PlexServerPort videoRatingKey:ratingKey state:tag authentification:_PlexAuthentification];
NSInteger status = [_PlexWebAPI MarkWatchedUnwatchedMedia:_PlexServerAddress port:_PlexServerPort videoRatingKey:ratingKey state:tag authentification:_PlexAuthentification];
if (status == 200) {
if ([tag isEqualToString:@"watched"]) {
......@@ -396,7 +396,7 @@
NSInteger size = [[[ObjList objectAtIndex:0] objectForKey:@"size"] integerValue];
if (size < [[UIDevice currentDevice] freeDiskspace].longLongValue) {
if ([[ObjList objectAtIndex:0] objectForKey:@"keySubtitle"])
[_PlexParser getFileSubtitleFromPlexServer:ObjList modeStream:NO];
[_PlexWebAPI getFileSubtitleFromPlexServer:ObjList modeStream:NO];
[self _downloadFileFromMediaItem:ObjList];
[cell.statusLabel showStatusMessage:NSLocalizedString(@"DOWNLOADING", nil)];
......
......@@ -121,7 +121,7 @@
mutableMediaObject = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:newPath authentification:@""];
NSString *URLofSubtitle = nil;
if ([[mutableMediaObject objectAtIndex:0] objectForKey:@"keySubtitle"])
URLofSubtitle = [_PlexParser getFileSubtitleFromPlexServer:mutableMediaObject modeStream:YES];
URLofSubtitle = [_PlexWebAPI getFileSubtitleFromPlexServer:mutableMediaObject modeStream:YES];
NSURL *itemURL = [NSURL URLWithString:[_PlexWebAPI urlAuth:[[mutableMediaObject objectAtIndex:0] objectForKey:@"keyMedia"] autentification:_PlexAuthentification]];
if (itemURL) {
......@@ -140,7 +140,7 @@
NSInteger size = [[[mutableMediaObject objectAtIndex:0] objectForKey:@"size"] integerValue];
if (size < [[UIDevice currentDevice] freeDiskspace].longLongValue) {
if ([[mutableMediaObject objectAtIndex:0] objectForKey:@"keySubtitle"])
[_PlexParser getFileSubtitleFromPlexServer:mutableMediaObject modeStream:NO];
[_PlexWebAPI getFileSubtitleFromPlexServer:mutableMediaObject modeStream:NO];
[self _downloadFileFromMediaItem:mutableMediaObject];
} else {
......@@ -181,7 +181,7 @@
NSString *ratingKey = [[_mutableMediaInformation objectAtIndex:0] objectForKey:@"ratingKey"];
NSString *tag = [[_mutableMediaInformation objectAtIndex:0] objectForKey:@"state"];
NSInteger status = [_PlexParser MarkWatchedUnwatchedMedia:_PlexServerAddress port:_PlexServerPort videoRatingKey:ratingKey state:tag authentification:_PlexAuthentification];
NSInteger status = [_PlexWebAPI MarkWatchedUnwatchedMedia:_PlexServerAddress port:_PlexServerPort videoRatingKey:ratingKey state:tag authentification:_PlexAuthentification];
if (status == 200) {
if ([tag isEqualToString:@"watched"]) {
tag = @"unwatched";
......
......@@ -14,7 +14,5 @@
- (NSMutableArray *)PlexMediaServerParser:(NSString *)adress port:(NSString *)port navigationPath:(NSString *)navPath authentification:(NSString *)auth;
- (NSMutableArray *)PlexExtractDeviceInfo:(NSData *)data;
- (NSInteger)MarkWatchedUnwatchedMedia:(NSString *)adress port:(NSString *)port videoRatingKey:(NSString *)ratingKey state:(NSString *)state authentification:(NSString *)auth;
- (NSString *)getFileSubtitleFromPlexServer:(NSMutableArray *)mutableMediaObject modeStream:(BOOL)modeStream;
@end
\ No newline at end of file
......@@ -11,7 +11,6 @@
#import "VLCPlexParser.h"
#import "VLCPlexWebAPI.h"
#import "UIDevice+VLC.h"
#import "VLCAlertView.h"
#import "VLCConstants.h"
......@@ -194,62 +193,4 @@
}
}
#pragma mark - API
- (NSInteger)MarkWatchedUnwatchedMedia:(NSString *)adress port:(NSString *)port videoRatingKey:(NSString *)ratingKey state:(NSString *)state authentification:(NSString *)auth
{
NSString *url = nil;
if ([state isEqualToString:@"watched"])
url = [NSString stringWithFormat:@"http://%@%@/:/unscrobble?identifier=com.plexapp.plugins.library&key=%@", adress, port, ratingKey];
else
url = [NSString stringWithFormat:@"http://%@%@/:/scrobble?identifier=com.plexapp.plugins.library&key=%@", adress, port, ratingKey];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:[[[VLCPlexWebAPI alloc] init] urlAuth:url autentification:auth]] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:20];
NSURLResponse *response = nil;
NSError *error = nil;
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSInteger httpStatus = [(NSHTTPURLResponse *)response statusCode];
if (httpStatus != 200)
APLog(@"Mark Watched Unwatched Media Error status: %ld at URL : %@", (long)httpStatus, url);
return httpStatus;
}
- (NSString *)getFileSubtitleFromPlexServer:(NSMutableArray *)mutableMediaObject modeStream:(BOOL)modeStream
{
NSString *FileSubtitlePath = nil;
NSString *fileName = [[[[mutableMediaObject objectAtIndex:0] objectForKey:@"namefile"] stringByDeletingPathExtension] stringByAppendingPathExtension:[[mutableMediaObject objectAtIndex:0] objectForKey:@"codecSubtitle"]];
VLCPlexWebAPI *PlexWebAPI = [[VLCPlexWebAPI alloc] init];
NSURL *url = [[NSURL alloc] initWithString:[PlexWebAPI urlAuth:[[mutableMediaObject objectAtIndex:0] objectForKey:@"keySubtitle"] autentification:[[mutableMediaObject objectAtIndex:0] objectForKey:@"authentification"]]];
NSData *receivedSub = [NSData dataWithContentsOfURL:url];
if (receivedSub.length < [[UIDevice currentDevice] freeDiskspace].longLongValue) {
NSArray *searchPaths = nil;
if (modeStream)
searchPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
else
searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *directoryPath = [searchPaths objectAtIndex:0];
FileSubtitlePath = [directoryPath stringByAppendingPathComponent:fileName];
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:FileSubtitlePath]) {
[fileManager createFileAtPath:FileSubtitlePath contents:nil attributes:nil];
if (![fileManager fileExistsAtPath:FileSubtitlePath])
APLog(@"file creation failed, no data was saved");
}
[receivedSub writeToFile:FileSubtitlePath atomically:YES];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"DISK_FULL", nil) message:[NSString stringWithFormat:NSLocalizedString(@"DISK_FULL_FORMAT", nil), fileName, [[UIDevice currentDevice] model]] delegate:self cancelButtonTitle:NSLocalizedString(@"BUTTON_OK", nil) otherButtonTitles:nil];
[alert show];
}
return FileSubtitlePath;
}
@end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment