Commit 74c5e9e2 authored by Pierre SAGASPE's avatar Pierre SAGASPE Committed by Felix Paul Kühne

plex: add access to the Plex Server with an authentication if required

Signed-off-by: Felix Paul Kühne's avatarFelix Paul Kühne <fkuehne@videolan.org>
parent a71fd6b8
......@@ -16,6 +16,6 @@
@property (nonatomic, strong) UITableView *tableView;
- (id)initWithPlexServer:(NSString *)serverName serverAddress:(NSString *)serverAddress portNumber:(NSString *)portNumber atPath:(NSString *)path;
- (id)initWithPlexServer:(NSString *)serverName serverAddress:(NSString *)serverAddress portNumber:(NSString *)portNumber atPath:(NSString *)path authentification:(NSString *)auth;
@end
......@@ -13,6 +13,7 @@
#import "VLCLocalPlexFolderListViewController.h"
#import "VLCPlexMediaInformationViewController.h"
#import "VLCPlexParser.h"
#import "VLCPlexWebAPI.h"
#import "VLCLocalNetworkListCell.h"
#import "VLCAppDelegate.h"
#import "VLCPlaylistViewController.h"
......@@ -31,7 +32,10 @@
NSString *_PlexServerAddress;
NSString *_PlexServerPort;
NSString *_PlexServerPath;
NSString *_PlexAuthentification;
VLCPlexParser *_PlexParser;
VLCPlexWebAPI *_PlexWebAPI;
NSMutableArray *_searchData;
UISearchBar *_searchBar;
......@@ -55,7 +59,7 @@
self.view = _tableView;
}
- (id)initWithPlexServer:(NSString *)serverName serverAddress:(NSString *)serverAddress portNumber:(NSString *)portNumber atPath:(NSString *)path
- (id)initWithPlexServer:(NSString *)serverName serverAddress:(NSString *)serverAddress portNumber:(NSString *)portNumber atPath:(NSString *)path authentification:(NSString *)auth
{
self = [super init];
if (self) {
......@@ -64,6 +68,8 @@
_PlexServerPort = portNumber;
_PlexServerPath = path;
_PlexAuthentification = auth;
_mutableObjectList = [[NSMutableArray alloc] init];
_imageCache = [[NSCache alloc] init];
[_imageCache setCountLimit:50];
......@@ -78,11 +84,18 @@
[super viewDidLoad];
[_mutableObjectList removeAllObjects];
_mutableObjectList = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:_PlexServerPath];
_mutableObjectList = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:_PlexServerPath authentification:_PlexAuthentification];
if (_mutableObjectList.count == 0)
_PlexAuthentification = @"";
else
_PlexAuthentification = [[_mutableObjectList objectAtIndex:0] objectForKey:@"authentification"];
self.tableView.separatorColor = [UIColor VLCDarkBackgroundColor];
self.view.backgroundColor = [UIColor VLCDarkBackgroundColor];
_PlexWebAPI = [[VLCPlexWebAPI alloc] init];
NSString *titleValue;
if ([_PlexServerPath isEqualToString:@""] || _mutableObjectList.count == 0)
titleValue = _PlexServerName;
......@@ -185,7 +198,7 @@
if (thumbPath) {
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0);
dispatch_async(queue, ^{
UIImage *img = [self getCachedImage:thumbPath];
UIImage *img = [self getCachedImage:[self _urlAuth:thumbPath]];
dispatch_async(dispatch_get_main_queue(), ^{
if (!img)
[cell setIcon:[UIImage imageNamed:@"blank"]];
......@@ -261,18 +274,18 @@
if ([[[ObjList objectAtIndex:indexPath.row] objectForKey:@"container"] isEqualToString:@"item"]) {
[ObjList removeAllObjects];
ObjList = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:newPath];
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];
NSURL *itemURL = [NSURL URLWithString:[[ObjList objectAtIndex:0] objectForKey:@"keyMedia"]];
NSURL *itemURL = [NSURL URLWithString:[self _urlAuth:[[ObjList objectAtIndex:0] objectForKey:@"keyMedia"]]];
if (itemURL) {
VLCAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate openMovieWithExternalSubtitleFromURL:itemURL externalSubURL:URLofSubtitle];
}
} else {
VLCLocalPlexFolderListViewController *targetViewController = [[VLCLocalPlexFolderListViewController alloc] initWithPlexServer:_PlexServerName serverAddress:_PlexServerAddress portNumber:_PlexServerPort atPath:newPath];
VLCLocalPlexFolderListViewController *targetViewController = [[VLCLocalPlexFolderListViewController alloc] initWithPlexServer:_PlexServerName serverAddress:_PlexServerAddress portNumber:_PlexServerPort atPath:newPath authentification:_PlexAuthentification];
[[self navigationController] pushViewController:targetViewController animated:YES];
}
[tableView deselectRowAtIndexPath:indexPath animated:NO];
......@@ -280,6 +293,11 @@
#pragma mark - Specifics
- (NSString *)_urlAuth:(NSString *)url
{
return [_PlexWebAPI urlAuth:url autentification:_PlexAuthentification];
}
- (void)_playMediaItem:(NSMutableArray *)mutableMediaObject
{
NSString *newPath = nil;
......@@ -292,12 +310,12 @@
if ([[[mutableMediaObject objectAtIndex:0] objectForKey:@"container"] isEqualToString:@"item"]) {
[mutableMediaObject removeAllObjects];
mutableMediaObject = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:newPath];
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];
NSURL *itemURL = [NSURL URLWithString:[[mutableMediaObject objectAtIndex:0] objectForKey:@"keyMedia"]];
NSURL *itemURL = [NSURL URLWithString:[self _urlAuth:[[mutableMediaObject objectAtIndex:0] objectForKey:@"keyMedia"]]];
if (itemURL) {
VLCAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate openMovieWithExternalSubtitleFromURL:itemURL externalSubURL:URLofSubtitle];
......@@ -334,7 +352,7 @@
NSString *tag = [[ObjList objectAtIndex:0] objectForKey:@"state"];
NSString *cellStatusLbl = nil;
NSInteger status = [_PlexParser MarkWatchedUnwatchedMedia:_PlexServerAddress port:_PlexServerPort videoRatingKey:ratingKey state:tag];
NSInteger status = [_PlexParser MarkWatchedUnwatchedMedia:_PlexServerAddress port:_PlexServerPort videoRatingKey:ratingKey state:tag authentification:_PlexAuthentification];
if (status == 200) {
if ([tag isEqualToString:@"watched"]) {
......@@ -355,7 +373,7 @@
- (void)reloadTableViewPlex
{
[_mutableObjectList removeAllObjects];
_mutableObjectList = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:_PlexServerPath];
_mutableObjectList = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:_PlexServerPath authentification:_PlexAuthentification];
[self.tableView reloadData];
}
......@@ -373,7 +391,7 @@
NSString *path = [[ObjList objectAtIndex:0] objectForKey:@"key"];
[ObjList removeAllObjects];
ObjList = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:path];
ObjList = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:path authentification:_PlexAuthentification];
NSInteger size = [[[ObjList objectAtIndex:0] objectForKey:@"size"] integerValue];
if (size < [[UIDevice currentDevice] freeDiskspace].longLongValue) {
......@@ -454,7 +472,7 @@
[ObjList addObject:[_mutableObjectList objectAtIndex:[self.tableView indexPathForCell:swipedCell].row]];
if (SYSTEM_RUNS_IOS7_OR_LATER) {
VLCPlexMediaInformationViewController *targetViewController = [[VLCPlexMediaInformationViewController alloc] initPlexMediaInformation:ObjList serverAddress:_PlexServerAddress portNumber:_PlexServerPort atPath:_PlexServerPath];
VLCPlexMediaInformationViewController *targetViewController = [[VLCPlexMediaInformationViewController alloc] initPlexMediaInformation:ObjList serverAddress:_PlexServerAddress portNumber:_PlexServerPort atPath:_PlexServerPath authentification:_PlexAuthentification];
[[self navigationController] pushViewController:targetViewController animated:YES];
} else {
NSString *title = [[ObjList objectAtIndex:0] objectForKey:@"title"];
......
......@@ -392,7 +392,7 @@
NSString *name = [_PlexServicesInfo[row] objectForKey:@"name"];
NSString *hostName = [_PlexServicesInfo[row] objectForKey:@"hostName"];
NSString *portNum = [_PlexServicesInfo[row] objectForKey:@"port"];
VLCLocalPlexFolderListViewController *targetViewController = [[VLCLocalPlexFolderListViewController alloc] initWithPlexServer:name serverAddress:hostName portNumber:portNum atPath:@""];
VLCLocalPlexFolderListViewController *targetViewController = [[VLCLocalPlexFolderListViewController alloc] initWithPlexServer:name serverAddress:hostName portNumber:portNum atPath:@"" authentification:@""];
[[self navigationController] pushViewController:targetViewController animated:YES];
}
} else if (section == 2) {
......
......@@ -122,7 +122,7 @@
if ([self isValidPort:port] && [self isValidAddress:server]) {
if ([self isValidURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@:%@", server, port]]]) {
VLCLocalPlexFolderListViewController *targetViewController = [[VLCLocalPlexFolderListViewController alloc] initWithPlexServer:server serverAddress:server portNumber:[NSString stringWithFormat:@":%@", port] atPath:@""];
VLCLocalPlexFolderListViewController *targetViewController = [[VLCLocalPlexFolderListViewController alloc] initWithPlexServer:server serverAddress:server portNumber:[NSString stringWithFormat:@":%@", port] atPath:@"" authentification:@""];
[[self navigationController] pushViewController:targetViewController animated:YES];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:NSLocalizedString(@"HTTP_UPLOAD_SERVER_OFF", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"BUTTON_OK", nil) otherButtonTitles:nil];
......@@ -255,11 +255,12 @@
- (BOOL)isValidURL:(NSURL*)url
{
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:5.0];
[request setHTTPMethod:@"HEAD"];
//[request setHTTPMethod:@"HEAD"];
NSHTTPURLResponse *response = nil;
NSError *error = nil;
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if ([response statusCode] == 200)
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
if (([response statusCode] == 200) || ([responseString rangeOfString:@"Unauthorized"].location != NSNotFound))
return YES;
else
return NO;
......
......@@ -25,6 +25,6 @@
- (IBAction)download:(id)sender;
- (IBAction)markMedia:(id)sender;
- (id)initPlexMediaInformation:(NSMutableArray *)mediaInformation serverAddress:(NSString *)serverAddress portNumber:(NSString *)portNumber atPath:(NSString *)path;
- (id)initPlexMediaInformation:(NSMutableArray *)mediaInformation serverAddress:(NSString *)serverAddress portNumber:(NSString *)portNumber atPath:(NSString *)path authentification:(NSString *)auth;
@end
......@@ -11,6 +11,7 @@
#import "VLCPlexMediaInformationViewController.h"
#import "VLCPlexParser.h"
#import "VLCPlexWebAPI.h"
#import "VLCAppDelegate.h"
#import "NSString+SupportedMedia.h"
#import "UIDevice+VLC.h"
......@@ -21,13 +22,15 @@
NSString *_PlexServerAddress;
NSString *_PlexServerPort;
NSString *_PlexServerPath;
NSString *_PlexAuthentification;
VLCPlexParser *_PlexParser;
VLCPlexWebAPI *_PlexWebAPI;
}
@end
@implementation VLCPlexMediaInformationViewController
- (id)initPlexMediaInformation:(NSMutableArray *)mediaInformation serverAddress:(NSString *)serverAddress portNumber:(NSString *)portNumber atPath:(NSString *)path
- (id)initPlexMediaInformation:(NSMutableArray *)mediaInformation serverAddress:(NSString *)serverAddress portNumber:(NSString *)portNumber atPath:(NSString *)path authentification:(NSString *)auth
{
self = [super init];
if (self) {
......@@ -36,7 +39,9 @@
_PlexServerAddress = serverAddress;
_PlexServerPort = portNumber;
_PlexServerPath = path;
_PlexAuthentification = auth;
_PlexParser = [[VLCPlexParser alloc] init];
_PlexWebAPI = [[VLCPlexWebAPI alloc] init];
}
return self;
}
......@@ -50,7 +55,7 @@
self.navigationController.navigationBar.translucent = NO;
NSString *title = [[_mutableMediaInformation objectAtIndex:0] objectForKey:@"title"];
NSString *thumbPath = [[_mutableMediaInformation objectAtIndex:0] objectForKey:@"thumb"];
NSString *thumbPath = [_PlexWebAPI urlAuth:[[_mutableMediaInformation objectAtIndex:0] objectForKey:@"thumb"] autentification:_PlexAuthentification];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:thumbPath]]];
NSInteger size = [[[_mutableMediaInformation objectAtIndex:0] objectForKey:@"size"] integerValue];
NSString *mediaSize = [NSByteCountFormatter stringFromByteCount:size countStyle:NSByteCountFormatterCountStyleFile];
......@@ -113,12 +118,12 @@
if ([[[mutableMediaObject objectAtIndex:0] objectForKey:@"container"] isEqualToString:@"item"]) {
[mutableMediaObject removeAllObjects];
mutableMediaObject = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:newPath];
mutableMediaObject = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:newPath authentification:@""];
NSString *URLofSubtitle = nil;
if ([[mutableMediaObject objectAtIndex:0] objectForKey:@"keySubtitle"])
URLofSubtitle = [_PlexParser getFileSubtitleFromPlexServer:mutableMediaObject modeStream:YES];
NSURL *itemURL = [NSURL URLWithString:[[mutableMediaObject objectAtIndex:0] objectForKey:@"keyMedia"]];
NSURL *itemURL = [NSURL URLWithString:[_PlexWebAPI urlAuth:[[mutableMediaObject objectAtIndex:0] objectForKey:@"keyMedia"] autentification:_PlexAuthentification]];
if (itemURL) {
VLCAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate openMovieWithExternalSubtitleFromURL:itemURL externalSubURL:URLofSubtitle];
......@@ -130,7 +135,7 @@
{
NSString *path = [[mutableMediaObject objectAtIndex:0] objectForKey:@"key"];
[mutableMediaObject removeAllObjects];
mutableMediaObject = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:path];
mutableMediaObject = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:path authentification:@""];
NSInteger size = [[[mutableMediaObject objectAtIndex:0] objectForKey:@"size"] integerValue];
if (size < [[UIDevice currentDevice] freeDiskspace].longLongValue) {
......@@ -176,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];
NSInteger status = [_PlexParser MarkWatchedUnwatchedMedia:_PlexServerAddress port:_PlexServerPort videoRatingKey:ratingKey state:tag authentification:_PlexAuthentification];
if (status == 200) {
if ([tag isEqualToString:@"watched"]) {
tag = @"unwatched";
......
......@@ -12,8 +12,9 @@
#import <UIKit/UIKit.h>
@interface VLCPlexParser : NSObject
- (NSMutableArray *)PlexMediaServerParser:(NSString *)adress port:(NSString *)port navigationPath:(NSString *)navPath;
- (NSInteger)MarkWatchedUnwatchedMedia:(NSString *)adress port:(NSString *)port videoRatingKey:(NSString *)ratingKey state:(NSString *)state;
- (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
......@@ -10,9 +10,13 @@
*****************************************************************************/
#import "VLCPlexParser.h"
#import "VLCPlexWebAPI.h"
#import "UIDevice+VLC.h"
#import "VLCAlertView.h"
#import "VLCConstants.h"
#define kPlexMediaServerDirInit @"library/sections"
#define kPlexVLCDeviceName @"VLC for iOS"
@interface VLCPlexParser () <NSXMLParserDelegate>
{
......@@ -24,7 +28,7 @@
@implementation VLCPlexParser
- (NSMutableArray *)PlexMediaServerParser:(NSString *)adress port:(NSString *)port navigationPath:(NSString *)path
- (NSMutableArray *)PlexMediaServerParser:(NSString *)adress port:(NSString *)port navigationPath:(NSString *)path authentification:(NSString *)auth
{
_containerInfo = [[NSMutableArray alloc] init];
[_containerInfo removeAllObjects];
......@@ -41,16 +45,70 @@
mediaServerUrl = [NSString stringWithFormat:@"%@/%@/%@",_PlexMediaServerUrl, kPlexMediaServerDirInit, path];
}
NSURL *url = [[NSURL alloc] initWithString:mediaServerUrl];
NSXMLParser *xmlparser = [[NSXMLParser alloc] initWithContentsOfURL:url];
VLCPlexWebAPI *PlexWebAPI = [[VLCPlexWebAPI alloc] init];
NSURL *url = [[NSURL alloc] initWithString:[PlexWebAPI urlAuth:mediaServerUrl autentification:auth]];
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:5.0];
NSHTTPURLResponse *response = nil;
NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if ([response statusCode] != 200) {
NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
if([responseString rangeOfString:@"Unauthorized"].location != NSNotFound) {
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *username = [prefs stringForKey:kVLCPLEXLogin];
NSString *password = [prefs stringForKey:kVLCPLEXPassword];
if ((username && password) && ((![username isEqualToString:@""]) && (![password isEqualToString:@""]))) {
auth = [PlexWebAPI PlexAuthentification:username password:password];
url = [NSURL URLWithString:[PlexWebAPI urlAuth:mediaServerUrl autentification:auth]];
request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:5.0];
response = nil;
error = nil;
data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if ([response statusCode] != 200) {
VLCAlertView *alertView = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"PLEX_ERROR_ACCOUNT", nil) message:NSLocalizedString(@"PLEX_CHECK_ACCOUNT", nil) cancelButtonTitle:NSLocalizedString(@"BUTTON_OK", nil) otherButtonTitles:nil];
[alertView show];
}
[_containerInfo removeAllObjects];
[_dicoInfo removeAllObjects];
} else {
VLCAlertView *alertView = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"UNAUTHORIZED", nil) message:NSLocalizedString(@"PLEX_CHECK_ACCOUNT", nil) cancelButtonTitle:NSLocalizedString(@"BUTTON_OK", nil) otherButtonTitles:nil];
[alertView show];
}
} else
APLog(@"PlexParser url Errors : %ld", (long)[response statusCode]);
}
NSXMLParser *xmlparser = [[NSXMLParser alloc] initWithData:data];
[xmlparser setDelegate:self];
if (![xmlparser parse])
APLog(@"PlexParser url Errors : %@", url);
[_containerInfo setValue:auth forKey:@"authentification"];
return _containerInfo;
}
- (NSMutableArray *)PlexExtractDeviceInfo:(NSData *)data
{
_containerInfo = [[NSMutableArray alloc] init];
[_containerInfo removeAllObjects];
_dicoInfo = [[NSMutableDictionary alloc] init];
NSXMLParser *xmlparser = [[NSXMLParser alloc] initWithData:data];
[xmlparser setDelegate:self];
if (![xmlparser parse])
NSLog(@"PlexParser data Errors : %@", data);
return _containerInfo;
}
#pragma mark - Parser
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
{
if ([elementName isEqualToString:@"MediaContainer"]) {
......@@ -62,10 +120,12 @@
[_dicoInfo setObject:[attributeDict objectForKey:@"title2"] forKey:@"libTitle"];
if ([attributeDict objectForKey:@"grandparentTitle"])
[_dicoInfo setObject:[attributeDict objectForKey:@"grandparentTitle"] forKey:@"grandparentTitle"];
} else if ([elementName isEqualToString:@"Directory"]) {
[_dicoInfo setObject:@"directory" forKey:@"container"];
[_dicoInfo setObject:[attributeDict objectForKey:@"key"] forKey:@"key"];
[_dicoInfo setObject:[attributeDict objectForKey:@"title"] forKey:@"title"];
} else if ([elementName isEqualToString:@"Video"] || [elementName isEqualToString:@"Track"]) {
[_dicoInfo setObject:@"item" forKey:@"container"];
[_dicoInfo setObject:[attributeDict objectForKey:@"key"] forKey:@"key"];
......@@ -83,6 +143,7 @@
[_dicoInfo setObject:[attributeDict objectForKey:@"audioCodec"] forKey:@"audioCodec"];
if ([attributeDict objectForKey:@"videoCodec"])
[_dicoInfo setObject:[attributeDict objectForKey:@"videoCodec"] forKey:@"videoCodec"];
} else if ([elementName isEqualToString:@"Part"]) {
[_dicoInfo setObject:[NSString stringWithFormat:@"%@%@",_PlexMediaServerUrl, [attributeDict objectForKey:@"key"]] forKey:@"keyMedia"];
if([attributeDict objectForKey:@"file"])
......@@ -102,6 +163,22 @@
[_dicoInfo setObject:[attributeDict objectForKey:@"language"] forKey:@"languageSubtitle"];
if ([attributeDict objectForKey:@"languageCode"])
[_dicoInfo setObject:[attributeDict objectForKey:@"languageCode"] forKey:@"languageCode"];
} else if ([elementName isEqualToString:@"Device"] && [[attributeDict objectForKey:@"name"] isEqualToString:kPlexVLCDeviceName]) {
if ([attributeDict objectForKey:@"name"])
[_dicoInfo setObject:[attributeDict objectForKey:@"name"] forKey:@"name"];
if ([attributeDict objectForKey:@"product"])
[_dicoInfo setObject:[attributeDict objectForKey:@"product"] forKey:@"product"];
if ([attributeDict objectForKey:@"productVersion"])
[_dicoInfo setObject:[attributeDict objectForKey:@"productVersion"] forKey:@"productVersion"];
if ([attributeDict objectForKey:@"platformVersion"])
[_dicoInfo setObject:[attributeDict objectForKey:@"platformVersion"] forKey:@"platformVersion"];
if ([attributeDict objectForKey:@"token"])
[_dicoInfo setObject:[attributeDict objectForKey:@"token"] forKey:@"token"];
if ([attributeDict objectForKey:@"clientIdentifier"])
[_dicoInfo setObject:[attributeDict objectForKey:@"clientIdentifier"] forKey:@"clientIdentifier"];
if ([attributeDict objectForKey:@"id"])
[_dicoInfo setObject:[attributeDict objectForKey:@"id"] forKey:@"id"];
}
if ([attributeDict objectForKey:@"thumb"] && ([elementName isEqualToString:@"Video"] || [elementName isEqualToString:@"Directory"] || [elementName isEqualToString:@"Part"] || [elementName isEqualToString:@"Track"]))
......@@ -111,13 +188,15 @@
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if (([elementName isEqualToString:@"Video"] || [elementName isEqualToString:@"Track"] || [elementName isEqualToString:@"Directory"] || [elementName isEqualToString:@"MediaContainer"]) && [_dicoInfo count] > 0) {
if (([elementName isEqualToString:@"Video"] || [elementName isEqualToString:@"Track"] || [elementName isEqualToString:@"Directory"] || [elementName isEqualToString:@"MediaContainer"] || [elementName isEqualToString:@"Device"]) && [_dicoInfo count] > 0) {
[_containerInfo addObject:_dicoInfo];
_dicoInfo = [[NSMutableDictionary alloc] init];
}
}
- (NSInteger)MarkWatchedUnwatchedMedia:(NSString *)adress port:(NSString *)port videoRatingKey:(NSString *)ratingKey state:(NSString *)state
#pragma mark - API
- (NSInteger)MarkWatchedUnwatchedMedia:(NSString *)adress port:(NSString *)port videoRatingKey:(NSString *)ratingKey state:(NSString *)state authentification:(NSString *)auth
{
NSString *url = nil;
......@@ -126,7 +205,7 @@
else
url = [NSString stringWithFormat:@"http://%@%@/:/scrobble?identifier=com.plexapp.plugins.library&key=%@", adress, port, ratingKey];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:20];
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];
......@@ -144,7 +223,9 @@
NSString *FileSubtitlePath = nil;
NSString *fileName = [[[[mutableMediaObject objectAtIndex:0] objectForKey:@"namefile"] stringByDeletingPathExtension] stringByAppendingPathExtension:[[mutableMediaObject objectAtIndex:0] objectForKey:@"codecSubtitle"]];
NSURL *url = [NSURL URLWithString:[[mutableMediaObject objectAtIndex:0] objectForKey:@"keySubtitle"]];
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) {
......
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