static func printLyrics(_ currentTrack: Track) {
let engine = LyricsEngine(withTrack: currentTrack)
+ if showTitle {
+ printTitle(currentTrack)
+ }
if let lyrics = engine.lyrics {
- if showTitle {
- printTitle(currentTrack)
- }
-
print(lyrics)
} else {
print("Lyrics not found :(")
// Print the currently available sources
static func printSources() {
- print("Listing Sources: Not yet implemented")
+ let sourceManager = SourceManager()
+ for (sourceName, _) in sourceManager.availableSources {
+ if (Configuration.shared["enabled_sources"] as? [String] ?? []).contains(sourceName) {
+ print("\(sourceName) (enabled)")
+ } else {
+ print(sourceName)
+ }
+ }
}
// Runs the enable method of a source and writes the configuration to set it
// as enabled
- static func enableSource(_ sourceName: String) {
- print("Enable source \(sourceName): Not yet implemented")
+ static func enableSource(_ sourceName: String) throws {
+ let sourceManager = SourceManager()
+ if let source = sourceManager.availableSources[sourceName] {
+ if let enabledSources = Configuration.shared["enabled_sources"] as? [String] {
+ if source.enable() == false {
+ throw SourceCouldNotBeEnabled()
+ }
+ if !enabledSources.contains(sourceName) {
+ Configuration.shared["enabled_sources"] = enabledSources + [sourceName]
+ }
+ return
+ }
+ throw ConfigurationCouldNotBeRead()
+ }
+ throw SourceNotAvailable()
}
// Remove a source from the enabled sources configuration
- static func disableSource(_ sourceName: String) {
- print("Disable source \(sourceName): Not yet implemented")
+ static func disableSource(_ sourceName: String) throws {
+ let sourceManager = SourceManager()
+ if let source = sourceManager.availableSources[sourceName] {
+ if let enabledSources = Configuration.shared["enabled_sources"] as? [String] {
+ if source.disable() == false {
+ throw SourceCouldNotBeDisabled()
+ }
+ Configuration.shared["enabled_sources"] = enabledSources.filter { $0 != sourceName }
+ return
+ }
+ throw ConfigurationCouldNotBeRead()
+ }
+ throw SourceNotAvailable()
}
// Removes any configuration for a source, and disables it
- static func resetSource(_ sourceName: String) {
- print("Reset source \(sourceName): Not yet implemented")
+ static func resetSource(_ sourceName: String) throws {
+ let sourceManager = SourceManager()
+ if let source = sourceManager.availableSources[sourceName] {
+ if source.reset() == false {
+ throw SourceCouldNotBeReset()
+ }
+ try disableSource(sourceName)
+ return
+ }
+ throw SourceNotAvailable()
}
// Prints the track artist and name