VLCSharedLibraryParser.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*****************************************************************************
  2. * VLCSharedLibraryParser.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2015 VideoLAN. All rights reserved.
  6. *
  7. * Authors: Pierre Sagaspe <pierre.sagaspe # me.com>
  8. *
  9. * Refer to the COPYING file of the official project for license.
  10. *****************************************************************************/
  11. #import "VLCSharedLibraryParser.h"
  12. #define kLibraryXmlFile @"libMediaVLC.xml"
  13. @interface VLCSharedLibraryParser () <NSXMLParserDelegate>
  14. {
  15. NSMutableArray *_containerInfo;
  16. NSMutableDictionary *_dicoInfo;
  17. NSString *_libraryServerUrl;
  18. }
  19. @end
  20. @implementation VLCSharedLibraryParser
  21. - (NSMutableArray *)VLCLibraryServerParser:(NSString *)adress port:(NSString *)port
  22. {
  23. _containerInfo = [[NSMutableArray alloc] init];
  24. [_containerInfo removeAllObjects];
  25. _dicoInfo = [[NSMutableDictionary alloc] init];
  26. _libraryServerUrl = [NSString stringWithFormat:@"http://%@%@", adress, port];
  27. NSString *mediaServerUrl = [NSString stringWithFormat:@"%@/%@", _libraryServerUrl, kLibraryXmlFile];
  28. NSURL *url = [[NSURL alloc] initWithString:mediaServerUrl];
  29. NSXMLParser *xmlparser = [[NSXMLParser alloc] initWithContentsOfURL:url];
  30. [xmlparser setDelegate:self];
  31. if (![xmlparser parse])
  32. APLog(@"VLC Library Parser url Errors : %@", url);
  33. return _containerInfo;
  34. }
  35. - (BOOL)isVLCMediaServer:(NSString *)adress port:(NSString *)port
  36. {
  37. NSMutableArray *mutableObjectList = [self VLCLibraryServerParser:adress port:port];
  38. if (mutableObjectList.count > 0) {
  39. NSString *identifier = [[mutableObjectList objectAtIndex:0] objectForKey:@"identifier"];
  40. if ([identifier isEqualToString:@"org.videolan.vlc-ios"])
  41. return YES;
  42. }
  43. return NO;
  44. }
  45. - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
  46. {
  47. if([elementName isEqualToString:@"MediaContainer"]) {
  48. if ([attributeDict objectForKey:@"size"])
  49. [_dicoInfo setObject:[attributeDict objectForKey:@"size"] forKey:@"size"];
  50. if ([attributeDict objectForKey:@"identifier"])
  51. [_dicoInfo setObject:[attributeDict objectForKey:@"identifier"] forKey:@"identifier"];
  52. if ([attributeDict objectForKey:@"libraryTitle"])
  53. [_dicoInfo setObject:[attributeDict objectForKey:@"libraryTitle"] forKey:@"libTitle"];
  54. } else if([elementName isEqualToString:@"Media"]) {
  55. if([attributeDict objectForKey:@"title"])
  56. [_dicoInfo setObject:[attributeDict objectForKey:@"title"] forKey:@"title"];
  57. if([attributeDict objectForKey:@"thumb"])
  58. [_dicoInfo setObject:[attributeDict objectForKey:@"thumb"] forKey:@"thumb"];
  59. if([attributeDict objectForKey:@"duration"])
  60. [_dicoInfo setObject:[attributeDict objectForKey:@"duration"] forKey:@"duration"];
  61. if([attributeDict objectForKey:@"size"])
  62. [_dicoInfo setObject:[attributeDict objectForKey:@"size"] forKey:@"size"];
  63. if([attributeDict objectForKey:@"pathfile"])
  64. [_dicoInfo setObject:[attributeDict objectForKey:@"pathfile"] forKey:@"pathfile"];
  65. if([attributeDict objectForKey:@"pathSubtitle"])
  66. [_dicoInfo setObject:[attributeDict objectForKey:@"pathSubtitle"] forKey:@"pathSubtitle"];
  67. }
  68. }
  69. - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
  70. {
  71. if(([elementName isEqualToString:@"Media"] || [elementName isEqualToString:@"MediaContainer"]) && [_dicoInfo count] > 0) {
  72. [_containerInfo addObject:_dicoInfo];
  73. _dicoInfo = [[NSMutableDictionary alloc] init];
  74. }
  75. }
  76. @end