MLMediaLibrary+playlist.m 3.2 KB

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