Archived
1
This commit is contained in:
Kim Wittenburg
2019-02-01 22:59:01 +01:00
parent ba472864df
commit 0a485ff42a
82 changed files with 3975 additions and 1822 deletions

78
TagTunes/Tag.swift Executable file
View File

@@ -0,0 +1,78 @@
//
// Tag.swift
// TagTunes
//
// Created by Kim Wittenburg on 21.01.16.
// Copyright © 2016 Kim Wittenburg. All rights reserved.
//
import Foundation
/// This enum contains cases for the different tags supported by TagTunes. Tags
/// may or may not be returned by the iTunes Store. Use the
/// `isReturnedBySearchAPI` property to query this information.
///
/// The `Tag` enum supports localization for displaying the name of a tag in the
/// user interface. Use the `localizedName` property for this purpose.
public enum Tag: String {
case Name = "name", Artist = "artist", Year = "year", TrackNumber = "trackNumber", TrackCount = "trackCount", DiscNumber = "discNumber", DiscCount = "discCount", Genre = "genre", AlbumName = "album", AlbumArtist = "albumArtist", ReleaseDate = "releaseDate", Compilation = "compilation"
case Artwork = "artwork"
case SortName = "sortName", SortArtist = "sortArtist", SortAlbumName = "sortAlbum", SortAlbumArtist = "sortAlbumArtist", Composer = "composer", SortComposer = "sortComposer", Comment = "comment"
/// Returns `true` for tags that are returned from the
/// [Search API](https://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html).
public var isReturnedBySearchAPI: Bool {
switch self {
case Name, Artist, Year, TrackNumber, TrackCount, DiscNumber, DiscCount, Genre, AlbumName, AlbumArtist, Compilation, ReleaseDate:
return true
case Artwork:
return true
case SortName, SortArtist, SortAlbumName, SortAlbumArtist, Composer, SortComposer, Comment:
return false
}
}
/// Returns a `AEKeyword` associated with the tag. This code can be used to
/// work with Apple-Event properties of the `iTunesTrack` class.
internal var code: AEKeyword {
let keyword: String
switch self {
case Name: keyword = "pnam"
case Artist: keyword = "pArt"
case Year: keyword = "pYr "
case TrackNumber: keyword = "pTrN"
case TrackCount: keyword = "pTrC"
case DiscNumber: keyword = "pDsN"
case DiscCount: keyword = "pDsC"
case Genre: keyword = "pGen"
case AlbumName: keyword = "pAlb"
case AlbumArtist: keyword = "pAlA"
case Compilation: keyword = "pAnt"
case ReleaseDate: keyword = "pRlD"
case Artwork: keyword = "cArt"
case SortName: keyword = "pSNm"
case SortArtist: keyword = "pSAr"
case SortAlbumName: keyword = "pSAl"
case SortAlbumArtist: keyword = "pSAA"
case Composer: keyword = "pCmp"
case SortComposer: keyword = "pSCm"
case Comment: keyword = "pCmt"
}
return AEKeyword(keyword)
}
/// Returns the localized name of the tag which can be displayed in the user
/// interface.
public var localizedName: String {
return NSLocalizedString("Tag: \(self.rawValue)", comment: "")
}
// TODO: Order of tags should not be determined here.
/// Returns an array of all tags. The tags are sorted by whether they are
/// returned by the
/// [Search API](https://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html).
public static var allTags: [Tag] {
return [.Name, .Artist, .Year, .TrackNumber, .TrackCount, .DiscNumber, .DiscCount, .Genre, .AlbumName, .AlbumArtist, .Compilation, .ReleaseDate, .Artwork, .SortName, .SortArtist, .SortAlbumName, .SortAlbumArtist, .Composer, .SortComposer, .Comment]
}
}