MLMediaLibrary+playlist.m 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*****************************************************************************
  2. * MLMediaLibrary+playlist.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. * Carola Nitz <caro # videolan.org>
  10. * Felix Paul Kühne <fkuehne # videolan.org>
  11. *
  12. * Refer to the COPYING file of the official project for license.
  13. *****************************************************************************/
  14. #import "MLMediaLibrary+playlist.h"
  15. #import <UIKit/UIKit.h>
  16. #import <MediaLibraryKit/MediaLibraryKit.h>
  17. @implementation MLMediaLibrary (playlist)
  18. - (NSArray *)playlistArrayForGroupObject:(id)groupObject
  19. {
  20. if([groupObject isKindOfClass:[MLLabel class]]) {
  21. return [(MLLabel *)groupObject sortedFolderItems];
  22. } else if ([groupObject isKindOfClass:[MLAlbum class]]) {
  23. return [(MLAlbum *)groupObject sortedTracks];
  24. } else if ([groupObject isKindOfClass:[MLShow class]]){
  25. return [(MLShow *)groupObject sortedEpisodes];
  26. } else {
  27. NSAssert(NO, @"this shouldn't have happened check the grouObjects type");
  28. return nil;
  29. }
  30. }
  31. //TODO: this code could use refactoring to be more readable
  32. - (NSArray *)playlistArrayForLibraryMode:(VLCLibraryMode)libraryMode
  33. {
  34. NSMutableArray *objects = [NSMutableArray array];
  35. /* add all albums */
  36. if (libraryMode != VLCLibraryModeAllSeries) {
  37. NSArray *rawAlbums = [MLAlbum allAlbums];
  38. for (MLAlbum *album in rawAlbums) {
  39. if (album.name.length > 0 && album.tracks.count > 1)
  40. [objects addObject:album];
  41. }
  42. }
  43. if (libraryMode == VLCLibraryModeAllAlbums) {
  44. return objects;
  45. }
  46. /* add all shows */
  47. NSArray *rawShows = [MLShow allShows];
  48. for (MLShow *show in rawShows) {
  49. if (show.name.length > 0 && show.episodes.count > 1)
  50. [objects addObject:show];
  51. }
  52. if (libraryMode == VLCLibraryModeAllSeries) {
  53. return objects;
  54. }
  55. /* add all folders*/
  56. NSArray *allFolders = [MLLabel allLabels];
  57. for (MLLabel *folder in allFolders)
  58. [objects addObject:folder];
  59. /* add all remaining files */
  60. NSArray *allFiles = [MLFile allFiles];
  61. for (MLFile *file in allFiles) {
  62. if (file.labels.count > 0) continue;
  63. if (!file.isShowEpisode && !file.isAlbumTrack)
  64. [objects addObject:file];
  65. else if (file.isShowEpisode) {
  66. if (file.showEpisode.show.episodes.count < 2)
  67. [objects addObject:file];
  68. /* older MediaLibraryKit versions don't send a show name in a popular
  69. * corner case. hence, we need to work-around here and force a reload
  70. * afterwards as this could lead to the 'all my shows are gone'
  71. * syndrome (see #10435, #10464, #10432 et al) */
  72. if (file.showEpisode.show.name.length == 0) {
  73. file.showEpisode.show.name = NSLocalizedString(@"UNTITLED_SHOW", nil);
  74. }
  75. } else if (file.isAlbumTrack) {
  76. if (file.albumTrack.album.tracks.count < 2)
  77. [objects addObject:file];
  78. }
  79. }
  80. return objects;
  81. }
  82. @end