MLMediaLibrary+playlist.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. - (nonnull NSArray *)playlistArrayForGroupObject:(nonnull 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. - (nonnull NSArray *)playlistArrayForLibraryMode:(VLCLibraryMode)libraryMode
  33. {
  34. NSMutableArray *objects = [NSMutableArray array];
  35. if (libraryMode == VLCLibraryModeFolder) {
  36. return objects;
  37. }
  38. /* add all albums */
  39. if (libraryMode != VLCLibraryModeAllSeries) {
  40. NSArray *rawAlbums = [MLAlbum allAlbums];
  41. for (MLAlbum *album in rawAlbums) {
  42. if (album.name.length > 0 && album.tracks.count > 1)
  43. [objects addObject:album];
  44. }
  45. }
  46. if (libraryMode == VLCLibraryModeAllAlbums) {
  47. return objects;
  48. }
  49. /* add all shows */
  50. NSArray *rawShows = [MLShow allShows];
  51. for (MLShow *show in rawShows) {
  52. if (show.name.length > 0 && show.episodes.count > 1)
  53. [objects addObject:show];
  54. }
  55. if (libraryMode == VLCLibraryModeAllSeries) {
  56. return objects;
  57. }
  58. /* add all folders*/
  59. NSArray *allFolders = [MLLabel allLabels];
  60. for (MLLabel *folder in allFolders)
  61. [objects addObject:folder];
  62. /* add all remaining files */
  63. NSArray *allFiles = [MLFile allFiles];
  64. for (MLFile *file in allFiles) {
  65. if (file.labels.count > 0) continue;
  66. if (!file.isShowEpisode && !file.isAlbumTrack)
  67. [objects addObject:file];
  68. else if (file.isShowEpisode) {
  69. if (file.showEpisode.show.episodes.count < 2)
  70. [objects addObject:file];
  71. /* older MediaLibraryKit versions don't send a show name in a popular
  72. * corner case. hence, we need to work-around here and force a reload
  73. * afterwards as this could lead to the 'all my shows are gone'
  74. * syndrome (see #10435, #10464, #10432 et al) */
  75. if (file.showEpisode.show.name.length == 0) {
  76. file.showEpisode.show.name = NSLocalizedString(@"UNTITLED_SHOW", nil);
  77. }
  78. } else if (file.isAlbumTrack) {
  79. if (file.albumTrack.album.tracks.count < 2)
  80. [objects addObject:file];
  81. }
  82. }
  83. return objects;
  84. }
  85. @end