Commit e3624777 authored by Soomin Lee's avatar Soomin Lee

MediaLibraryService: Cosmetic: General tidy up

parent cde486e2
......@@ -10,6 +10,8 @@
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
// MARK: - Notification names
extension Notification.Name {
static let VLCNewFileAddedNotification = Notification.Name("NewFileAddedNotification")
}
......@@ -19,6 +21,8 @@ extension NSNotification {
@objc static let VLCNewFileAddedNotification = Notification.Name.VLCNewFileAddedNotification
}
// MARK: -
@objc protocol MediaLibraryObserver: class {
// Video
@objc optional func medialibrary(_ medialibrary: MediaLibraryService,
......@@ -66,6 +70,8 @@ extension NSNotification {
didDeletePlaylistsWithIds playlistsIds: [NSNumber])
}
// MARK: -
protocol MediaLibraryMigrationDelegate: class {
func medialibraryDidStartMigration(_ medialibrary: MediaLibraryService)
......@@ -74,6 +80,8 @@ protocol MediaLibraryMigrationDelegate: class {
func medialibraryDidStopMigration(_ medialibrary: MediaLibraryService)
}
// MARK: -
class MediaLibraryService: NSObject {
private static let databaseName: String = "medialibrary.db"
private static let migrationKey: String = "MigratedToVLCMediaLibraryKit"
......@@ -96,9 +104,11 @@ class MediaLibraryService: NSObject {
NotificationCenter.default.addObserver(self, selector: #selector(reload),
name: .VLCNewFileAddedNotification, object: nil)
}
}
// MARK: Private
// MARK: - Private initializers
private extension MediaLibraryService {
private func setupMediaDiscovery(at path: String) {
let mediaFileDiscoverer = VLCMediaFileDiscoverer.sharedInstance()
mediaFileDiscoverer?.directoryPath = path
......@@ -144,39 +154,6 @@ class MediaLibraryService: NSObject {
assertionFailure("MediaLibraryService: The database was resetted, please re-configure.")
}
}
// MARK: Internal
@objc func reload() {
medialib.reload()
}
/// Returns number of *ALL* files(audio and video) present in the medialibrary database
func numberOfFiles() -> Int {
var media = medialib.audioFiles(with: .filename, desc: false)
media += medialib.videoFiles(with: .filename, desc: false)
return media.count
}
/// Returns *ALL* file found for a specified VLCMLMediaType
///
/// - Parameter type: Type of the media
/// - Returns: Array of VLCMLMedia
func media(ofType type: VLCMLMediaType, sortingCriteria sort: VLCMLSortingCriteria = .filename, desc: Bool = false) -> [VLCMLMedia] {
return type == .video ? medialib.videoFiles(with: sort, desc: desc) : medialib.audioFiles(with: sort, desc: desc)
}
func genres(sortingCriteria sort: VLCMLSortingCriteria = .default, desc: Bool = false) -> [VLCMLGenre] {
return medialib.genres(with: sort, desc: desc)
}
func fetchMedia(with mrl: URL?) -> VLCMLMedia? {
guard let mrl = mrl else {
return nil
}
return medialib.media(withMrl: mrl)
}
}
// MARK: - Migration
......@@ -282,7 +259,38 @@ extension MediaLibraryService {
}
}
// MARK: MediaLibrary - Audio methods
// MARK: - Helpers
extension MediaLibraryService {
@objc func reload() {
medialib.reload()
}
/// Returns number of *ALL* files(audio and video) present in the medialibrary database
func numberOfFiles() -> Int {
var media = medialib.audioFiles(with: .filename, desc: false)
media += medialib.videoFiles(with: .filename, desc: false)
return media.count
}
/// Returns *ALL* file found for a specified VLCMLMediaType
///
/// - Parameter type: Type of the media
/// - Returns: Array of VLCMLMedia
func media(ofType type: VLCMLMediaType, sortingCriteria sort: VLCMLSortingCriteria = .filename, desc: Bool = false) -> [VLCMLMedia] {
return type == .video ? medialib.videoFiles(with: sort, desc: desc) : medialib.audioFiles(with: sort, desc: desc)
}
func fetchMedia(with mrl: URL?) -> VLCMLMedia? {
guard let mrl = mrl else {
return nil
}
return medialib.media(withMrl: mrl)
}
}
// MARK: - Audio methods
extension MediaLibraryService {
func artists(sortingCriteria sort: VLCMLSortingCriteria = .artist, desc: Bool = false) -> [VLCMLArtist] {
......@@ -294,7 +302,7 @@ extension MediaLibraryService {
}
}
// MARK: MediaLibrary - Video methods
// MARK: - Video methods
extension MediaLibraryService {
func requestThumbnail(for media: [VLCMLMedia]) {
......@@ -308,10 +316,9 @@ extension MediaLibraryService {
}
}
// MARK: MediaLibrary - Playlist methods
// MARK: - Playlist methods
extension MediaLibraryService {
func createPlaylist(with name: String) -> VLCMLPlaylist {
return medialib.createPlaylist(withName: name)
}
......@@ -325,6 +332,16 @@ extension MediaLibraryService {
}
}
// MARK: - Genre methods
extension MediaLibraryService {
func genres(sortingCriteria sort: VLCMLSortingCriteria = .default, desc: Bool = false) -> [VLCMLGenre] {
return medialib.genres(with: sort, desc: desc)
}
}
// MARK: - VLCMediaFileDiscovererDelegate
extension MediaLibraryService: VLCMediaFileDiscovererDelegate {
func mediaFileAdded(_ filePath: String!, loading isLoading: Bool) {
guard !isLoading else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment