Stuff…
This commit is contained in:
71
TagTunes/SongItem.swift
Executable file
71
TagTunes/SongItem.swift
Executable file
@@ -0,0 +1,71 @@
|
||||
//
|
||||
// SongItem.swift
|
||||
// TagTunes
|
||||
//
|
||||
// Created by Kim Wittenburg on 30.05.15.
|
||||
// Copyright (c) 2015 Kim Wittenburg. All rights reserved.
|
||||
//
|
||||
|
||||
import SearchAPI
|
||||
|
||||
/// Represents a `Song` from the Search API.
|
||||
public class SongItem: TagTunesEntityItem {
|
||||
|
||||
/// Returns the `entity` as a `Song`.
|
||||
public var song: Song {
|
||||
return entity as! Song
|
||||
}
|
||||
|
||||
public var album: Album {
|
||||
return parentItem?.entity as! Album
|
||||
}
|
||||
|
||||
override public var saved: Bool {
|
||||
let components = NSCalendar.currentCalendar().components(.Year, fromDate: song.releaseDate)
|
||||
for track in associatedTracks {
|
||||
let trackName = Preferences.sharedPreferences.useCensoredNames ? song.censoredName : song.name
|
||||
let albumName = Preferences.sharedPreferences.useCensoredNames ? album.censoredName : album.name
|
||||
let options = Preferences.sharedPreferences.caseSensitive ? [] : NSStringCompareOptions.CaseInsensitiveSearch
|
||||
if let name = track.name where name.compare(trackName, options: options, range: nil, locale: nil) != .OrderedSame {
|
||||
return false
|
||||
}
|
||||
if let album = track.album where album.compare(albumName, options: options, range: nil, locale: nil) != .OrderedSame {
|
||||
return false
|
||||
}
|
||||
guard track.artist == song.artist.name && track.year == components.year && track.trackNumber == song.trackNumber && track.trackCount == song.trackCountOnDisc && track.discNumber == song.discNumber && track.discCount == song.discCount && track.genre == song.primaryGenre && track.albumArtist == album.artist.name && track.composer == "" else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
public override func valueForTag(tag: Tag) throws -> AnyObject! {
|
||||
let censoredNames = Preferences.sharedPreferences.useCensoredNames
|
||||
switch tag {
|
||||
case .Name: return censoredNames ? song.censoredName : song.name
|
||||
case .Artist: return censoredNames ? song.artist.censoredName : song.artist.name
|
||||
case .Year:
|
||||
let components = NSCalendar.currentCalendar().components(.Year, fromDate: song.releaseDate)
|
||||
return components.year
|
||||
case .TrackNumber: return song.trackNumber
|
||||
case .TrackCount: return song.trackCountOnDisc
|
||||
case .DiscNumber: return song.discNumber
|
||||
case .DiscCount: return song.discCount
|
||||
case .Genre: return song.primaryGenre
|
||||
case .AlbumName: return censoredNames ? album.censoredName : album.name
|
||||
case .AlbumArtist: return album.artist.name
|
||||
case .Compilation: return album.compilation
|
||||
case .ReleaseDate: return song.releaseDate
|
||||
// TODO: Artwork download error!
|
||||
case .Artwork: return album.artwork.optimalArtworkImageForSize(CGFloat.max)
|
||||
case .SortName,
|
||||
.SortArtist,
|
||||
.SortAlbumName,
|
||||
.SortAlbumArtist,
|
||||
.Composer,
|
||||
.SortComposer,
|
||||
.Comment: return nil
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user