Forráskód Böngészése

plex: clean-up the implementation to remove mutable states from APIs, mutable states from iterations, to save ObjC selector dispatches and to never perform network operations on the main thread

(cherry picked from commit 4de4e74e9d18edeea10a5e7b834c6ea646ae9cf9)
Felix Paul Kühne 10 éve
szülő
commit
5610359c4d

+ 6 - 6
Resources/VLCPlexMediaInformationViewController.xib

@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6751" systemVersion="14C1514" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7706" systemVersion="14E26a" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
     <dependencies>
         <deployment identifier="iOS"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6736"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/>
     </dependencies>
     <objects>
         <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="VLCPlexMediaInformationViewController">
@@ -45,8 +45,8 @@
                     <nil key="highlightedColor"/>
                 </label>
                 <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" id="HlH-2P-0eo">
-                    <rect key="frame" x="17" y="9" width="120" height="150"/>
-                    <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
+                    <rect key="frame" x="100" y="9" width="120" height="150"/>
+                    <autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
                 </imageView>
                 <toolbar opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="1CU-w2-CLR">
                     <rect key="frame" x="0.0" y="524" width="320" height="44"/>
@@ -78,8 +78,8 @@
                     <color key="barTintColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
                 </toolbar>
                 <imageView userInteractionEnabled="NO" contentMode="scaleToFill" image="badgeUnread.png" id="ls6-CJ-vRi">
-                    <rect key="frame" x="95" y="8" width="44" height="44"/>
-                    <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
+                    <rect key="frame" x="176" y="8" width="44" height="44"/>
+                    <autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
                 </imageView>
                 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Size &amp; Time" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="7mI-at-CYu">
                     <rect key="frame" x="0.0" y="255" width="320" height="22"/>

+ 99 - 85
Sources/VLCLocalPlexFolderListViewController.m

@@ -24,7 +24,7 @@
 
 @interface VLCLocalPlexFolderListViewController () <UITableViewDataSource, UITableViewDelegate, VLCLocalNetworkListCell, UISearchBarDelegate, UISearchDisplayDelegate>
 {
-    NSMutableArray *_mutableObjectList;
+    NSArray *_globalObjectList;
     NSCache *_imageCache;
 
     NSString *_PlexServerName;
@@ -69,7 +69,7 @@
 
         _PlexAuthentification = auth;
 
-        _mutableObjectList = [[NSMutableArray alloc] init];
+        _globalObjectList = [[NSArray alloc] init];
         _imageCache = [[NSCache alloc] init];
         [_imageCache setCountLimit:50];
 
@@ -82,26 +82,12 @@
 {
     [super viewDidLoad];
 
-    [_mutableObjectList removeAllObjects];
-    _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;
-    else
-        titleValue = [_mutableObjectList[0] objectForKey:@"libTitle"];
-
-    self.title = titleValue;
+    self.title = _PlexServerName;
 
     _searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
     UINavigationBar *navBar = self.navigationController.navigationBar;
@@ -138,8 +124,30 @@
     _menuButton = [UIBarButtonItem themedRevealMenuButtonWithTarget:self andSelector:@selector(menuButtonAction:)];
     self.navigationItem.rightBarButtonItem = _menuButton;
 
+    _globalObjectList = [[NSArray alloc] init];
     _searchData = [[NSMutableArray alloc] init];
-    [_searchData removeAllObjects];
+
+    [self performSelectorInBackground:@selector(loadContents) withObject:nil];
+}
+
+- (void)loadContents
+{
+    _globalObjectList = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:_PlexServerPath authentification:_PlexAuthentification];
+    NSDictionary *firstObject = [_globalObjectList firstObject];
+
+    if (_globalObjectList.count == 0 || firstObject == nil)
+        _PlexAuthentification = @"";
+    else
+        _PlexAuthentification = [firstObject objectForKey:@"authentification"];
+
+    NSString *titleValue;
+    if ([_PlexServerPath isEqualToString:@""] || _globalObjectList.count == 0 || firstObject == nil)
+        titleValue = _PlexServerName;
+    else
+        titleValue = [firstObject objectForKey:@"libTitle"];
+    self.title = titleValue;
+
+    [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
 }
 
 - (BOOL)shouldAutorotate
@@ -170,7 +178,7 @@
     if (tableView == self.searchDisplayController.searchResultsTableView)
         return _searchData.count;
     else
-        return _mutableObjectList.count;
+        return _globalObjectList.count;
 }
 
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
@@ -182,18 +190,17 @@
     if (cell == nil)
         cell = [VLCLocalNetworkListCell cellWithReuseIdentifier:CellIdentifier];
 
-    NSMutableArray *ObjList = [[NSMutableArray alloc] init];
-    [ObjList removeAllObjects];
+    NSDictionary *cellObject;
 
     if (tableView == self.searchDisplayController.searchResultsTableView)
-        [ObjList addObjectsFromArray:_searchData];
+        cellObject = _searchData[indexPath.row];
     else
-        [ObjList addObjectsFromArray:_mutableObjectList];
+        cellObject = _globalObjectList[indexPath.row];
 
-    [cell setTitle:[[ObjList objectAtIndex:indexPath.row] objectForKey:@"title"]];
+    [cell setTitle:cellObject[@"title"]];
     [cell setIcon:[UIImage imageNamed:@"blank"]];
 
-    NSString *thumbPath = [[ObjList objectAtIndex:indexPath.row] objectForKey:@"thumb"];
+    NSString *thumbPath = cellObject[@"thumb"];
     if (thumbPath) {
         dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0);
         dispatch_async(queue, ^{
@@ -207,7 +214,7 @@
         });
     }
 
-    if ([[[ObjList objectAtIndex:indexPath.row] objectForKey:@"container"] isEqualToString:@"item"]) {
+    if ([cellObject[@"container"] isEqualToString:@"item"]) {
         UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRightGestureAction:)];
         [swipeRight setDirection:(UISwipeGestureRecognizerDirectionRight)];
         [cell addGestureRecognizer:swipeRight];
@@ -215,9 +222,9 @@
             UILongPressGestureRecognizer *longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTouchGestureAction:)];
             [cell addGestureRecognizer:longPressGestureRecognizer];
         }
-        NSInteger size = [[[ObjList objectAtIndex:indexPath.row] objectForKey:@"size"] integerValue];
+        NSInteger size = [cellObject[@"size"] integerValue];
         NSString *mediaSize = [NSByteCountFormatter stringFromByteCount:size countStyle:NSByteCountFormatterCountStyleFile];
-        NSString *durationInSeconds = [[ObjList objectAtIndex:indexPath.row] objectForKey:@"duration"];
+        NSString *durationInSeconds = cellObject[@"duration"];
         [cell setIsDirectory:NO];
         [cell setSubtitle:[NSString stringWithFormat:@"%@ (%@)", mediaSize, durationInSeconds]];
         [cell setIsDownloadable:YES];
@@ -255,30 +262,35 @@
 
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {
-    NSMutableArray *ObjList = [[NSMutableArray alloc] init];
-    [ObjList removeAllObjects];
+    NSArray *objectList;
     NSString *newPath = nil;
 
     if (tableView == self.searchDisplayController.searchResultsTableView)
-        [ObjList addObjectsFromArray:_searchData];
+        objectList = [_searchData copy];
     else
-        [ObjList addObjectsFromArray:_mutableObjectList];
+        objectList = _globalObjectList;
+
+    NSDictionary *rowObject = objectList[indexPath.row];
 
-    NSString *keyValue = [[ObjList objectAtIndex:indexPath.row] objectForKey:@"key"];
+    NSString *keyValue = [rowObject objectForKey:@"key"];
 
     if ([keyValue rangeOfString:@"library"].location == NSNotFound)
         newPath = [_PlexServerPath stringByAppendingPathComponent:keyValue];
     else
         newPath = keyValue;
 
-    if ([[[ObjList objectAtIndex:indexPath.row] objectForKey:@"container"] isEqualToString:@"item"]) {
-        [ObjList removeAllObjects];
-        ObjList = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:newPath authentification:_PlexAuthentification];
+    if ([rowObject[@"container"] isEqualToString:@"item"]) {
+        objectList = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:newPath authentification:_PlexAuthentification];
         NSString *URLofSubtitle = nil;
-        if ([[ObjList objectAtIndex:0] objectForKey:@"keySubtitle"])
-            URLofSubtitle = [_PlexWebAPI getFileSubtitleFromPlexServer:ObjList modeStream:YES];
 
-        NSURL *itemURL = [NSURL URLWithString:[self _urlAuth:[[ObjList objectAtIndex:0] objectForKey:@"keyMedia"]]];
+        NSDictionary *firstObject = [objectList firstObject];
+        if (!firstObject)
+            return;
+
+        if ([firstObject objectForKey:@"keySubtitle"])
+            URLofSubtitle = [_PlexWebAPI getFileSubtitleFromPlexServer:firstObject modeStream:YES];
+
+        NSURL *itemURL = [NSURL URLWithString:[self _urlAuth:firstObject[@"keyMedia"]]];
         if (itemURL) {
             VLCAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
             [appDelegate openMovieWithExternalSubtitleFromURL:itemURL externalSubURL:URLofSubtitle];
@@ -297,24 +309,27 @@
     return [_PlexWebAPI urlAuth:url autentification:_PlexAuthentification];
 }
 
-- (void)_playMediaItem:(NSMutableArray *)mutableMediaObject
+- (void)_playMediaItem:(NSDictionary *)mediaObject
 {
     NSString *newPath = nil;
-    NSString *keyValue = [[mutableMediaObject objectAtIndex:0] objectForKey:@"key"];
+    NSString *keyValue = [mediaObject objectForKey:@"key"];
 
     if ([keyValue rangeOfString:@"library"].location == NSNotFound)
         newPath = [_PlexServerPath stringByAppendingPathComponent:keyValue];
     else
         newPath = keyValue;
 
-    if ([[[mutableMediaObject objectAtIndex:0] objectForKey:@"container"] isEqualToString:@"item"]) {
-        [mutableMediaObject removeAllObjects];
-        mutableMediaObject = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:newPath authentification:_PlexAuthentification];
+    if ([[mediaObject objectForKey:@"container"] isEqualToString:@"item"]) {
+        NSArray *mediaList = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:newPath authentification:_PlexAuthentification];
         NSString *URLofSubtitle = nil;
-        if ([[mutableMediaObject objectAtIndex:0] objectForKey:@"keySubtitle"])
-            URLofSubtitle = [_PlexWebAPI getFileSubtitleFromPlexServer:mutableMediaObject modeStream:YES];
+        NSDictionary *firstObject = [mediaList firstObject];
+        if (!firstObject)
+            return;
 
-        NSURL *itemURL = [NSURL URLWithString:[self _urlAuth:[[mutableMediaObject objectAtIndex:0] objectForKey:@"keyMedia"]]];
+        if ([firstObject objectForKey:@"keySubtitle"])
+            URLofSubtitle = [_PlexWebAPI getFileSubtitleFromPlexServer:firstObject modeStream:YES];
+
+        NSURL *itemURL = [NSURL URLWithString:[self _urlAuth:[firstObject objectForKey:@"keyMedia"]]];
         if (itemURL) {
             VLCAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
             [appDelegate openMovieWithExternalSubtitleFromURL:itemURL externalSubURL:URLofSubtitle];
@@ -322,9 +337,12 @@
     }
 }
 
-- (void)_downloadFileFromMediaItem:(NSMutableArray *)mutableMediaObject
+- (void)_downloadFileFromMediaItem:(NSDictionary *)mediaObject
 {
-    NSURL *itemURL = [NSURL URLWithString:[[mutableMediaObject objectAtIndex:0] objectForKey:@"keyMedia"]];
+    if (!mediaObject)
+        return;
+
+    NSURL *itemURL = [NSURL URLWithString:[mediaObject objectForKey:@"keyMedia"]];
 
     if (![[itemURL absoluteString] isSupportedFormat]) {
         VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"FILE_NOT_SUPPORTED", nil)
@@ -334,7 +352,7 @@
                                                 otherButtonTitles:nil];
         [alert show];
     } else if (itemURL) {
-        NSString *fileName = [[mutableMediaObject objectAtIndex:0] objectForKey:@"namefile"];
+        NSString *fileName = [mediaObject objectForKey:@"namefile"];
         [[(VLCAppDelegate *)[UIApplication sharedApplication].delegate downloadViewController] addURLToDownloadList:itemURL fileNameOfMedia:fileName];
     }
 }
@@ -346,13 +364,10 @@
 
     VLCLocalNetworkListCell *cell = (VLCLocalNetworkListCell *)[[self tableView] cellForRowAtIndexPath:swipedIndexPath];
 
-    NSMutableArray *ObjList = [[NSMutableArray alloc] init];
-    [ObjList removeAllObjects];
+    NSDictionary *cellObject = _globalObjectList[[self.tableView indexPathForCell:swipedCell].row];
 
-    [ObjList addObject:_mutableObjectList[[self.tableView indexPathForCell:swipedCell].row]];
-
-    NSString *ratingKey = [[ObjList objectAtIndex:0] objectForKey:@"ratingKey"];
-    NSString *tag = [[ObjList objectAtIndex:0] objectForKey:@"state"];
+    NSString *ratingKey = cellObject[@"ratingKey"];
+    NSString *tag = cellObject[@"state"];
     NSString *cellStatusLbl = nil;
 
     NSInteger status = [_PlexWebAPI MarkWatchedUnwatchedMedia:_PlexServerAddress port:_PlexServerPort videoRatingKey:ratingKey state:tag authentification:_PlexAuthentification];
@@ -370,13 +385,12 @@
 
     [cell.statusLabel showStatusMessage:cellStatusLbl];
 
-    [[_mutableObjectList objectAtIndex:[self.tableView indexPathForCell:swipedCell].row] setObject:tag forKey:@"state"];
+    [_globalObjectList[[self.tableView indexPathForCell:swipedCell].row] setObject:tag forKey:@"state"];
 }
 
 - (void)reloadTableViewPlex
 {
-    [_mutableObjectList removeAllObjects];
-    _mutableObjectList = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:_PlexServerPath authentification:_PlexAuthentification];
+    _globalObjectList = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:_PlexServerPath authentification:_PlexAuthentification];
     [self.tableView reloadData];
 }
 
@@ -384,28 +398,28 @@
 
 - (void)triggerDownloadForCell:(VLCLocalNetworkListCell *)cell
 {
-    NSMutableArray *ObjList = [[NSMutableArray alloc] init];
-    [ObjList removeAllObjects];
+    NSDictionary *cellObject;
 
     if ([self.searchDisplayController isActive])
-        [ObjList addObject:_searchData[[self.searchDisplayController.searchResultsTableView indexPathForCell:cell].row]];
+        cellObject = _searchData[[self.searchDisplayController.searchResultsTableView indexPathForCell:cell].row];
     else
-        [ObjList addObject:_mutableObjectList[[self.tableView indexPathForCell:cell].row]];
+        cellObject = _globalObjectList[[self.tableView indexPathForCell:cell].row];
+
+    NSString *path = cellObject[@"key"];
 
-    NSString *path = [[ObjList objectAtIndex:0] objectForKey:@"key"];
-    [ObjList removeAllObjects];
-    ObjList = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:path authentification:_PlexAuthentification];
+    NSArray *mediaList = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:path authentification:_PlexAuthentification];
+    NSDictionary *firstObject = [mediaList firstObject];
 
-    NSInteger size = [[[ObjList objectAtIndex:0] objectForKey:@"size"] integerValue];
+    NSInteger size = [[firstObject objectForKey:@"size"] integerValue];
     if (size  < [[UIDevice currentDevice] freeDiskspace].longLongValue) {
-        if ([[ObjList objectAtIndex:0] objectForKey:@"keySubtitle"])
-            [_PlexWebAPI getFileSubtitleFromPlexServer:ObjList modeStream:NO];
+        if ([firstObject objectForKey:@"keySubtitle"])
+            [_PlexWebAPI getFileSubtitleFromPlexServer:firstObject modeStream:NO];
 
-        [self _downloadFileFromMediaItem:ObjList];
+        [self _downloadFileFromMediaItem:firstObject];
         [cell.statusLabel showStatusMessage:NSLocalizedString(@"DOWNLOADING", nil)];
     } else {
         VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"DISK_FULL", nil)
-                                                          message:[NSString stringWithFormat:NSLocalizedString(@"DISK_FULL_FORMAT", nil), [[ObjList objectAtIndex:0] objectForKey:@"title"], [[UIDevice currentDevice] model]]
+                                                          message:[NSString stringWithFormat:NSLocalizedString(@"DISK_FULL_FORMAT", nil), [firstObject objectForKey:@"title"], [[UIDevice currentDevice] model]]
                                                          delegate:self
                                                 cancelButtonTitle:NSLocalizedString(@"BUTTON_OK", nil)
                                                 otherButtonTitles:nil];
@@ -419,11 +433,12 @@
 {
     [_searchData removeAllObjects];
 
-    for (int i = 0; i < [_mutableObjectList count]; i++) {
+    NSUInteger count = _globalObjectList.count;
+    for (NSUInteger i = 0; i < count; i++) {
         NSRange nameRange;
-        nameRange = [[[_mutableObjectList objectAtIndex:i] objectForKey:@"title"] rangeOfString:searchString options:NSCaseInsensitiveSearch];
+        nameRange = [[_globalObjectList[i] objectForKey:@"title"] rangeOfString:searchString options:NSCaseInsensitiveSearch];
         if (nameRange.location != NSNotFound)
-            [_searchData addObject:_mutableObjectList[i]];
+            [_searchData addObject:_globalObjectList[i]];
     }
     return YES;
 }
@@ -471,31 +486,30 @@
 - (void)longTouchGestureAction:(UIGestureRecognizer *)recognizer
 {
     if (recognizer.state == UIGestureRecognizerStateBegan) {
-        NSMutableArray *ObjList = [[NSMutableArray alloc] init];
-        [ObjList removeAllObjects];
         NSIndexPath *swipedIndexPath = [self.tableView indexPathForRowAtPoint:[recognizer locationInView:self.tableView]];
         UITableViewCell *swipedCell = [self.tableView cellForRowAtIndexPath:swipedIndexPath];
         VLCLocalNetworkListCell *cell = (VLCLocalNetworkListCell *)[[self tableView] cellForRowAtIndexPath:swipedIndexPath];
-        [ObjList addObject:[_mutableObjectList objectAtIndex:[self.tableView indexPathForCell:swipedCell].row]];
+
+        NSDictionary *cellObject = _globalObjectList[[self.tableView indexPathForCell:swipedCell].row];
 
         if (SYSTEM_RUNS_IOS7_OR_LATER) {
-            VLCPlexMediaInformationViewController *targetViewController = [[VLCPlexMediaInformationViewController alloc] initPlexMediaInformation:ObjList serverAddress:_PlexServerAddress portNumber:_PlexServerPort atPath:_PlexServerPath authentification:_PlexAuthentification];
+            VLCPlexMediaInformationViewController *targetViewController = [[VLCPlexMediaInformationViewController alloc] initPlexMediaInformation:cellObject serverAddress:_PlexServerAddress portNumber:_PlexServerPort atPath:_PlexServerPath authentification:_PlexAuthentification];
             [[self navigationController] pushViewController:targetViewController animated:YES];
         } else {
-            NSString *title = [[ObjList objectAtIndex:0] objectForKey:@"title"];
-            NSInteger size = [[[ObjList objectAtIndex:0] objectForKey:@"size"] integerValue];
+            NSString *title = cellObject[@"title"];
+            NSInteger size = [cellObject[@"size"] integerValue];
             NSString *mediaSize = [NSByteCountFormatter stringFromByteCount:size countStyle:NSByteCountFormatterCountStyleFile];
-            NSString *durationInSeconds = [[ObjList objectAtIndex:0] objectForKey:@"duration"];
-            NSString *audioCodec = [[ObjList objectAtIndex:0] objectForKey:@"audioCodec"];
+            NSString *durationInSeconds = cellObject[@"duration"];
+            NSString *audioCodec = cellObject[@"audioCodec"];
             if (!audioCodec)
                 audioCodec = @"no track";
 
-            NSString *videoCodec = [[ObjList objectAtIndex:0] objectForKey:@"videoCodec"];
+            NSString *videoCodec = cellObject[@"videoCodec"];
             if (!videoCodec)
                 videoCodec = @"no track";
 
             NSString *message = [NSString stringWithFormat:@"%@ (%@)\naudio(%@) video(%@)", mediaSize, durationInSeconds, audioCodec, videoCodec];
-            NSString *summary = [NSString stringWithFormat:@"%@", [[ObjList objectAtIndex:0] objectForKey:@"summary"]];
+            NSString *summary = [NSString stringWithFormat:@"%@", cellObject[@"summary"]];
 
             VLCAlertView *alertView = [[VLCAlertView alloc] initWithTitle:title message:message cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", nil) otherButtonTitles:@[NSLocalizedString(@"PLAY_BUTTON", nil), NSLocalizedString(@"BUTTON_DOWNLOAD", nil)]];
             if (![summary isEqualToString:@""]) {
@@ -509,7 +523,7 @@
                     if (buttonIndex == 2)
                         [self triggerDownloadForCell:cell];
                     else
-                        [self _playMediaItem:ObjList];
+                        [self _playMediaItem:cellObject];
                 }
             };
             [alertView show];

+ 1 - 1
Sources/VLCPlexMediaInformationViewController.h

@@ -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 authentification:(NSString *)auth;
+- (id)initPlexMediaInformation:(NSDictionary *)mediaObject serverAddress:(NSString *)serverAddress portNumber:(NSString *)portNumber atPath:(NSString *)path authentification:(NSString *)auth;
 
 @end

+ 68 - 58
Sources/VLCPlexMediaInformationViewController.m

@@ -18,7 +18,7 @@
 
 @interface VLCPlexMediaInformationViewController ()
 {
-    NSMutableArray *_mutableMediaInformation;
+    NSDictionary *_mediaObject;
     NSString *_PlexServerAddress;
     NSString *_PlexServerPort;
     NSString *_PlexServerPath;
@@ -30,12 +30,15 @@
 
 @implementation VLCPlexMediaInformationViewController
 
-- (id)initPlexMediaInformation:(NSMutableArray *)mediaInformation serverAddress:(NSString *)serverAddress portNumber:(NSString *)portNumber atPath:(NSString *)path authentification:(NSString *)auth
+- (id)initPlexMediaInformation:(NSDictionary *)mediaInformation
+                 serverAddress:(NSString *)serverAddress
+                    portNumber:(NSString *)portNumber
+                        atPath:(NSString *)path
+              authentification:(NSString *)auth
 {
     self = [super init];
     if (self) {
-        _mutableMediaInformation = [[NSMutableArray alloc] init];
-        [_mutableMediaInformation addObjectsFromArray:mediaInformation];
+        _mediaObject = mediaInformation;
         _PlexServerAddress = serverAddress;
         _PlexServerPort = portNumber;
         _PlexServerPath = path;
@@ -54,29 +57,31 @@
     self.automaticallyAdjustsScrollViewInsets = NO;
     self.navigationController.navigationBar.translucent = NO;
 
-    NSString *title = [[_mutableMediaInformation objectAtIndex:0] objectForKey:@"title"];
-    NSString *thumbPath = [_PlexWebAPI urlAuth:[[_mutableMediaInformation objectAtIndex:0] objectForKey:@"thumb"] autentification:_PlexAuthentification];
+    NSString *title = _mediaObject[@"title"];
+    NSString *thumbPath = [_PlexWebAPI urlAuth:_mediaObject[@"thumb"] autentification:_PlexAuthentification];
     UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:thumbPath]]];
-    NSInteger size = [[[_mutableMediaInformation objectAtIndex:0] objectForKey:@"size"] integerValue];
+    NSInteger size = [_mediaObject[@"size"] integerValue];
     NSString *mediaSize = [NSByteCountFormatter stringFromByteCount:size countStyle:NSByteCountFormatterCountStyleFile];
-    NSString *durationInSeconds = [[_mutableMediaInformation objectAtIndex:0] objectForKey:@"duration"];
+    NSString *durationInSeconds = _mediaObject[@"duration"];
     NSString *displaySize = [NSString stringWithFormat:@"%@ (%@)", mediaSize, durationInSeconds];
-    NSString *tag = [[_mutableMediaInformation objectAtIndex:0] objectForKey:@"state"];
-    NSString *displaySummary = [NSString stringWithFormat:@"%@", [[_mutableMediaInformation objectAtIndex:0] objectForKey:@"summary"]];
+    NSString *tag = _mediaObject[@"state"];
+    NSString *displaySummary = [NSString stringWithFormat:@"%@", _mediaObject[@"summary"]];
 
-    NSString *audioCodec = [[_mutableMediaInformation objectAtIndex:0] objectForKey:@"audioCodec"];
+    NSString *audioCodec = _mediaObject[@"audioCodec"];
     if (!audioCodec)
         audioCodec = @"no track";
 
-    NSString *videoCodec = [[_mutableMediaInformation objectAtIndex:0] objectForKey:@"videoCodec"];
+    NSString *videoCodec = _mediaObject[@"videoCodec"];
     if (!videoCodec)
         videoCodec = @"no track";
 
     NSString *displayCodec = [NSString stringWithFormat:@"audio(%@) video(%@)", audioCodec, videoCodec];
 
-    NSString *grandparentTitle = [[_mutableMediaInformation objectAtIndex:0] objectForKey:@"grandparentTitle"];
+    NSString *grandparentTitle = _mediaObject[@"grandparentTitle"];
     if (grandparentTitle)
         self.title = grandparentTitle;
+    else
+        self.title = title;
 
     [self.thumb setContentMode:UIViewContentModeScaleAspectFit];
     [self.thumb setImage:image];
@@ -99,31 +104,32 @@
     [self.badgeUnread setNeedsDisplay];
 }
 
-- (void)viewWillAppear:(BOOL)animated
-{
-    [super viewWillAppear:animated];
-}
-
 #pragma mark - Specifics
 
-- (void)_playMediaItem:(NSMutableArray *)mutableMediaObject
+- (void)_playMediaItem
 {
+    if (_mediaObject == nil)
+        return;
+
     NSString *newPath = nil;
-    NSString *keyValue = [[mutableMediaObject objectAtIndex:0] objectForKey:@"key"];
+    NSString *keyValue = _mediaObject[@"key"];
 
     if ([keyValue rangeOfString:@"library"].location == NSNotFound)
         newPath = [_PlexServerPath stringByAppendingPathComponent:keyValue];
     else
         newPath = keyValue;
 
-    if ([[[mutableMediaObject objectAtIndex:0] objectForKey:@"container"] isEqualToString:@"item"]) {
-        [mutableMediaObject removeAllObjects];
-        mutableMediaObject = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:newPath authentification:@""];
+    if ([_mediaObject[@"container"] isEqualToString:@"item"]) {
+        NSArray *mediaList = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:newPath authentification:@""];
         NSString *URLofSubtitle = nil;
-        if ([[mutableMediaObject objectAtIndex:0] objectForKey:@"keySubtitle"])
-            URLofSubtitle = [_PlexWebAPI getFileSubtitleFromPlexServer:mutableMediaObject modeStream:YES];
+        NSDictionary *firstObject = [mediaList firstObject];
+        if (!firstObject)
+            return;
 
-        NSURL *itemURL = [NSURL URLWithString:[_PlexWebAPI urlAuth:[[mutableMediaObject objectAtIndex:0] objectForKey:@"keyMedia"] autentification:_PlexAuthentification]];
+        if (firstObject[@"keySubtitle"])
+            URLofSubtitle = [_PlexWebAPI getFileSubtitleFromPlexServer:firstObject modeStream:YES];
+
+        NSURL *itemURL = [NSURL URLWithString:[_PlexWebAPI urlAuth:firstObject[@"keyMedia"] autentification:_PlexAuthentification]];
         if (itemURL) {
             VLCAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
             [appDelegate openMovieWithExternalSubtitleFromURL:itemURL externalSubURL:URLofSubtitle];
@@ -131,21 +137,40 @@
     }
 }
 
-- (void)_download:(NSMutableArray *)mutableMediaObject
+- (void)_download
 {
-    NSString *path = [[mutableMediaObject objectAtIndex:0] objectForKey:@"key"];
-    [mutableMediaObject removeAllObjects];
-    mutableMediaObject = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:path authentification:@""];
+    if (_mediaObject == nil)
+        return;
 
-    NSInteger size = [[[mutableMediaObject objectAtIndex:0] objectForKey:@"size"] integerValue];
-    if (size  < [[UIDevice currentDevice] freeDiskspace].longLongValue) {
-        if ([[mutableMediaObject objectAtIndex:0] objectForKey:@"keySubtitle"])
-            [_PlexWebAPI getFileSubtitleFromPlexServer:mutableMediaObject modeStream:NO];
+    NSString *path = _mediaObject[@"key"];
 
-        [self _downloadFileFromMediaItem:mutableMediaObject];
+    NSArray *mediaList = [_PlexParser PlexMediaServerParser:_PlexServerAddress port:_PlexServerPort navigationPath:path authentification:@""];
+    NSDictionary *firstObject = [mediaList firstObject];
+    if (!firstObject)
+        return;
+
+    NSInteger size = [firstObject[@"size"] integerValue];
+    if (size  < [[UIDevice currentDevice] freeDiskspace].longLongValue) {
+        if (firstObject[@"keySubtitle"])
+            [_PlexWebAPI getFileSubtitleFromPlexServer:firstObject modeStream:NO];
+
+
+
+        NSURL *itemURL = [NSURL URLWithString:firstObject[@"keyMedia"]];
+        if (![[itemURL absoluteString] isSupportedFormat]) {
+            VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"FILE_NOT_SUPPORTED", nil)
+                                                              message:[NSString stringWithFormat:NSLocalizedString(@"FILE_NOT_SUPPORTED_LONG", nil), [itemURL absoluteString]]
+                                                             delegate:self
+                                                    cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", nil)
+                                                    otherButtonTitles:nil];
+            [alert show];
+        } else if (itemURL) {
+            NSString *fileName = [firstObject objectForKey:@"namefile"];
+            [[(VLCAppDelegate *)[UIApplication sharedApplication].delegate downloadViewController] addURLToDownloadList:itemURL fileNameOfMedia:fileName];
+        }
     } else {
         VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"DISK_FULL", nil)
-                                                          message:[NSString stringWithFormat:NSLocalizedString(@"DISK_FULL_FORMAT", nil), [[mutableMediaObject objectAtIndex:0] objectForKey:@"title"], [[UIDevice currentDevice] model]]
+                                                          message:[NSString stringWithFormat:NSLocalizedString(@"DISK_FULL_FORMAT", nil), firstObject[@"title"], [[UIDevice currentDevice] model]]
                                                          delegate:self
                                                 cancelButtonTitle:NSLocalizedString(@"BUTTON_OK", nil)
                                                 otherButtonTitles:nil];
@@ -153,41 +178,24 @@
     }
 }
 
-- (void)_downloadFileFromMediaItem:(NSMutableArray *)mutableMediaObject
-{
-    NSURL *itemURL = [NSURL URLWithString:[[mutableMediaObject objectAtIndex:0] objectForKey:@"keyMedia"]];
-
-    if (![[itemURL absoluteString] isSupportedFormat]) {
-        VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"FILE_NOT_SUPPORTED", nil)
-                                                          message:[NSString stringWithFormat:NSLocalizedString(@"FILE_NOT_SUPPORTED_LONG", nil), [itemURL absoluteString]]
-                                                         delegate:self
-                                                cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", nil)
-                                                otherButtonTitles:nil];
-        [alert show];
-    } else if (itemURL) {
-        NSString *fileName = [[mutableMediaObject objectAtIndex:0] objectForKey:@"namefile"];
-        [[(VLCAppDelegate *)[UIApplication sharedApplication].delegate downloadViewController] addURLToDownloadList:itemURL fileNameOfMedia:fileName];
-    }
-}
-
 #pragma mark - Action
 
 - (IBAction)play:(id)sender
 {
-    [self _playMediaItem:_mutableMediaInformation];
+    [self _playMediaItem];
     [[self navigationController] popViewControllerAnimated:YES];
 }
 
 - (IBAction)download:(id)sender
 {
-    [self _download:_mutableMediaInformation];
+    [self _download];
     [[self navigationController] popViewControllerAnimated:YES];
 }
 
 - (IBAction)markMedia:(id)sender
 {
-    NSString *ratingKey = [[_mutableMediaInformation objectAtIndex:0] objectForKey:@"ratingKey"];
-    NSString *tag = [[_mutableMediaInformation objectAtIndex:0] objectForKey:@"state"];
+    NSString *ratingKey = _mediaObject[@"ratingKey"];
+    NSString *tag = _mediaObject[@"state"];
 
     NSInteger status = [_PlexWebAPI MarkWatchedUnwatchedMedia:_PlexServerAddress port:_PlexServerPort videoRatingKey:ratingKey state:tag authentification:_PlexAuthentification];
     if (status == 200) {
@@ -205,7 +213,9 @@
 
     [self.badgeUnread setNeedsDisplay];
 
-    [[_mutableMediaInformation objectAtIndex:0] setObject:tag forKey:@"state"];
+    NSMutableDictionary *mutableMediaObject = [NSMutableDictionary dictionaryWithDictionary:_mediaObject];
+    [mutableMediaObject setObject:tag forKey:@"state"];
+    _mediaObject = [NSDictionary dictionaryWithDictionary:mutableMediaObject];
 }
 
 #pragma mark - UI interaction

+ 2 - 2
Sources/VLCPlexParser.h

@@ -12,7 +12,7 @@
 #import <UIKit/UIKit.h>
 @interface VLCPlexParser : NSObject
 
-- (NSMutableArray *)PlexMediaServerParser:(NSString *)adress port:(NSString *)port navigationPath:(NSString *)navPath authentification:(NSString *)auth;
-- (NSMutableArray *)PlexExtractDeviceInfo:(NSData *)data;
+- (NSArray *)PlexMediaServerParser:(NSString *)adress port:(NSString *)port navigationPath:(NSString *)navPath authentification:(NSString *)auth;
+- (NSArray *)PlexExtractDeviceInfo:(NSData *)data;
 
 @end

+ 5 - 7
Sources/VLCPlexParser.m

@@ -26,12 +26,11 @@
 
 @implementation VLCPlexParser
 
-- (NSMutableArray *)PlexMediaServerParser:(NSString *)adress port:(NSString *)port navigationPath:(NSString *)path authentification:(NSString *)auth
+- (NSArray *)PlexMediaServerParser:(NSString *)address port:(NSString *)port navigationPath:(NSString *)path authentification:(NSString *)auth
 {
     _containerInfo = [[NSMutableArray alloc] init];
-    [_containerInfo removeAllObjects];
     _dicoInfo = [[NSMutableDictionary alloc] init];
-    _PlexMediaServerUrl = [NSString stringWithFormat:@"http://%@%@",adress, port];
+    _PlexMediaServerUrl = [NSString stringWithFormat:@"http://%@%@",address, port];
     NSString *mediaServerUrl;
 
     if ([path isEqualToString:@""])
@@ -88,13 +87,12 @@
 
     [_containerInfo setValue:auth forKey:@"authentification"];
 
-    return _containerInfo;
+    return [NSArray arrayWithArray:_containerInfo];
 }
 
-- (NSMutableArray *)PlexExtractDeviceInfo:(NSData *)data
+- (NSArray *)PlexExtractDeviceInfo:(NSData *)data
 {
     _containerInfo = [[NSMutableArray alloc] init];
-    [_containerInfo removeAllObjects];
     _dicoInfo = [[NSMutableDictionary alloc] init];
     NSXMLParser *xmlparser = [[NSXMLParser alloc] initWithData:data];
     [xmlparser setDelegate:self];
@@ -102,7 +100,7 @@
     if (![xmlparser parse])
         APLog(@"PlexParser data Errors : %@", data);
 
-    return _containerInfo;
+    return [NSArray arrayWithArray:_containerInfo];
 }
 
 #pragma mark - Parser

+ 3 - 3
Sources/VLCPlexWebAPI.h

@@ -17,10 +17,10 @@
 - (NSString *)PlexAuthentification:(NSString *)username password:(NSString *)password;
 - (NSString *)urlAuth:(NSString *)url autentification:(NSString *)auth;
 - (NSData *)HttpRequestWithCookie:(NSURL *)url cookies:(NSArray *)authToken HTTPMethod:(NSString *)method;
-- (NSURL *)CreatePlexStreamingURL:(NSString *)adress port:(NSString *)port videoKey:(NSString *)key username:(NSString *)username deviceInfo:(NSMutableArray *)deviceInfo session:(NSString *)session;
+- (NSURL *)CreatePlexStreamingURL:(NSString *)address port:(NSString *)port videoKey:(NSString *)key username:(NSString *)username deviceInfo:(NSDictionary *)deviceInfo session:(NSString *)session;
 - (void)stopSession:(NSString *)adress port:(NSString *)port session:(NSString *)session;
-- (NSInteger)MarkWatchedUnwatchedMedia:(NSString *)adress port:(NSString *)port videoRatingKey:(NSString *)ratingKey state:(NSString *)state authentification:(NSString *)auth;
-- (NSString *)getFileSubtitleFromPlexServer:(NSMutableArray *)mutableMediaObject modeStream:(BOOL)modeStream;
+- (NSInteger)MarkWatchedUnwatchedMedia:(NSString *)address port:(NSString *)port videoRatingKey:(NSString *)ratingKey state:(NSString *)state authentification:(NSString *)auth;
+- (NSString *)getFileSubtitleFromPlexServer:(NSDictionary *)mediaObject modeStream:(BOOL)modeStream;
 - (NSString *)getSession;
 - (NSData *)PlexDeviceInfo:(NSArray *)cookies;
 

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 43 - 20
Sources/VLCPlexWebAPI.m


+ 30 - 14
VLC for iOS.xcodeproj/project.pbxproj

@@ -1233,24 +1233,12 @@
 		7D31002117B676D500E6516D /* Local Network Connectivity */ = {
 			isa = PBXGroup;
 			children = (
-				265D511A1922746C00E38383 /* VLCPlexParser.h */,
-				265D511B1922746C00E38383 /* VLCPlexParser.m */,
-				2640FAE41B01477A00E359D6 /* VLCPlexWebAPI.h */,
-				2640FAE51B01477A00E359D6 /* VLCPlexWebAPI.m */,
-				26D4AF8B1A78379000D5EC65 /* VLCSharedLibraryParser.h */,
-				26D4AF8C1A78379000D5EC65 /* VLCSharedLibraryParser.m */,
+				7DCA8DA01B25BBAD00946349 /* PLEX */,
+				7DCA8DA11B25BBB700946349 /* Library Sharing */,
 				7D30F3D1183AB2F100FFC021 /* VLCLocalNetworkListCell.h */,
 				7D30F3D2183AB2F100FFC021 /* VLCLocalNetworkListCell.m */,
 				7D30F3D3183AB2F100FFC021 /* VLCLocalServerFolderListViewController.h */,
 				7D30F3D4183AB2F100FFC021 /* VLCLocalServerFolderListViewController.m */,
-				265D51181922746C00E38383 /* VLCLocalPlexFolderListViewController.h */,
-				265D51191922746C00E38383 /* VLCLocalPlexFolderListViewController.m */,
-				262C71571A98FA9200F7ED34 /* VLCPlexMediaInformationViewController.h */,
-				262C71581A98FA9200F7ED34 /* VLCPlexMediaInformationViewController.m */,
-				26E3A6FC1AAB76A100B32450 /* VLCPlexConnectServerViewController.h */,
-				26E3A6FD1AAB76A100B32450 /* VLCPlexConnectServerViewController.m */,
-				26D4AF891A78379000D5EC65 /* VLCSharedLibraryListViewController.h */,
-				26D4AF8A1A78379000D5EC65 /* VLCSharedLibraryListViewController.m */,
 				7D30F3D5183AB2F100FFC021 /* VLCLocalServerListViewController.h */,
 				7D30F3D6183AB2F100FFC021 /* VLCLocalServerListViewController.m */,
 				7D30F3DA183AB2F900FFC021 /* VLCNetworkLoginViewController.h */,
@@ -1641,6 +1629,34 @@
 			name = Reachability;
 			sourceTree = "<group>";
 		};
+		7DCA8DA01B25BBAD00946349 /* PLEX */ = {
+			isa = PBXGroup;
+			children = (
+				265D511A1922746C00E38383 /* VLCPlexParser.h */,
+				265D511B1922746C00E38383 /* VLCPlexParser.m */,
+				2640FAE41B01477A00E359D6 /* VLCPlexWebAPI.h */,
+				2640FAE51B01477A00E359D6 /* VLCPlexWebAPI.m */,
+				265D51181922746C00E38383 /* VLCLocalPlexFolderListViewController.h */,
+				265D51191922746C00E38383 /* VLCLocalPlexFolderListViewController.m */,
+				262C71571A98FA9200F7ED34 /* VLCPlexMediaInformationViewController.h */,
+				262C71581A98FA9200F7ED34 /* VLCPlexMediaInformationViewController.m */,
+				26E3A6FC1AAB76A100B32450 /* VLCPlexConnectServerViewController.h */,
+				26E3A6FD1AAB76A100B32450 /* VLCPlexConnectServerViewController.m */,
+			);
+			name = PLEX;
+			sourceTree = "<group>";
+		};
+		7DCA8DA11B25BBB700946349 /* Library Sharing */ = {
+			isa = PBXGroup;
+			children = (
+				26D4AF8B1A78379000D5EC65 /* VLCSharedLibraryParser.h */,
+				26D4AF8C1A78379000D5EC65 /* VLCSharedLibraryParser.m */,
+				26D4AF891A78379000D5EC65 /* VLCSharedLibraryListViewController.h */,
+				26D4AF8A1A78379000D5EC65 /* VLCSharedLibraryListViewController.m */,
+			);
+			name = "Library Sharing";
+			sourceTree = "<group>";
+		};
 		7DFB1567185CC38A008D49BB /* Dropbox */ = {
 			isa = PBXGroup;
 			children = (