VLCNetworkServerBrowserSharedLibrary.m 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*****************************************************************************
  2. * VLCNetworkServerBrowserVLCMedia.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2015 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Tobias Conradi <videolan # tobias-conradi.de>
  9. *
  10. * Refer to the COPYING file of the official project for license.
  11. *****************************************************************************/
  12. #import "VLCNetworkServerBrowserSharedLibrary.h"
  13. #import "VLCSharedLibraryParser.h"
  14. @interface VLCNetworkServerBrowserSharedLibrary () <VLCSharedLibraryParserDelegate>
  15. @property (nonatomic, readonly) NSString *addressOrName;
  16. @property (nonatomic, readonly) NSUInteger port;
  17. @property (nonatomic, readonly) VLCSharedLibraryParser *httpParser;
  18. @end
  19. @implementation VLCNetworkServerBrowserSharedLibrary
  20. @synthesize title = _title, delegate = _delegate, items = _items;
  21. - (instancetype)initWithName:(NSString *)name host:(NSString *)addressOrName portNumber:(NSUInteger)portNumber
  22. {
  23. self = [super init];
  24. if (self) {
  25. _title = name;
  26. _addressOrName = addressOrName;
  27. _port = portNumber;
  28. _items = [NSArray array];
  29. _httpParser = [[VLCSharedLibraryParser alloc] init];
  30. _httpParser.delegate = self;
  31. }
  32. return self;
  33. }
  34. - (void)update {
  35. [self.httpParser fetchDataFromServer:self.addressOrName port:self.port];
  36. }
  37. #pragma mark - Specifics
  38. - (void)sharedLibraryDataProcessings:(NSArray *)result
  39. {
  40. _title = [result.firstObject objectForKey:@"libTitle"];
  41. NSMutableArray *items = [NSMutableArray array];
  42. for (NSDictionary *dict in result) {
  43. [items addObject:[[VLCNetworkServerBrowserItemSharedLibrary alloc] initWithDictionary:dict]];
  44. }
  45. _items = [items copy];
  46. [[NSOperationQueue mainQueue] addOperationWithBlock:^{
  47. [self.delegate networkServerBrowserDidUpdate:self];
  48. }];
  49. }
  50. @end
  51. @implementation VLCNetworkServerBrowserItemSharedLibrary
  52. @synthesize name = _name, URL = _URL, fileSizeBytes = _fileSizeBytes, container = _container;
  53. - (instancetype)initWithDictionary:(NSDictionary *)dictionary
  54. {
  55. self = [super init];
  56. if (self) {
  57. _name = dictionary[@"title"];
  58. NSString *thumbURLString = dictionary[@"thumb"];
  59. _subtitleURL = thumbURLString ? [NSURL URLWithString:thumbURLString] : nil;
  60. _fileSizeBytes = dictionary[@"size"];
  61. _duration = dictionary[@"duration"];
  62. NSString *subtitleURLString = dictionary[@"pathSubtitle"];
  63. if ([subtitleURLString isEqualToString:@"(null)"]) subtitleURLString = nil;
  64. subtitleURLString = [subtitleURLString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  65. _subtitleURL = subtitleURLString ? [NSURL URLWithString:subtitleURLString] : nil;
  66. _URL = [NSURL URLWithString:dictionary[@"pathfile"]];
  67. _container = NO;
  68. }
  69. return self;
  70. }
  71. - (id<VLCNetworkServerBrowser>)containerBrowser {
  72. return nil;
  73. }
  74. @end