]> git.r.bdr.sh - rbdr/lyricli/commitdiff
Simulate lyrics engine
authorBen Beltran <redacted>
Thu, 18 May 2017 04:23:18 +0000 (23:23 -0500)
committerBen Beltran <redacted>
Thu, 18 May 2017 04:23:18 +0000 (23:23 -0500)
Sources/lyricli.swift
Sources/lyrics_engine.swift [new file with mode: 0644]
Sources/main.swift
Sources/source_manager.swift
Sources/track.swift

index d55b500af960bb8b39c5c571ea78fbe91bec4aff..c44a7f401f4e9d3e20af94f58531764700340e70 100644 (file)
@@ -2,23 +2,33 @@
 public class Lyricli {
     public static var version = "0.0.0-feature/option-parsing"
 
+    public static var showTitle = false
+
     public static func printLyrics() {
 
         let sourceManager = SourceManager()
 
         if let currentTrack = sourceManager.currentTrack {
-            print(currentTrack.artist)
-            print(currentTrack.name)
+
+            let engine = LyricsEngine(withTrack: currentTrack)
+
+            if let lyrics = engine.lyrics {
+                if showTitle {
+                    printTitle(currentTrack)
+                }
+
+                print(lyrics)
+            }
+            else {
+                print("Lyrics not found :(")
+            }
+
         }
         else {
-            print("Current track not found")
+            print("No Artist/Song could be found :(")
         }
     }
 
-    public static func printTitle() {
-        print("Getting Song Title: Not yet implemented")
-    }
-
     public static func printSources() {
         print("Listing Sources: Not yet implemented")
     }
@@ -34,4 +44,8 @@ public class Lyricli {
     public static func resetSource(_ sourceName: String) {
         print("Reset source \(sourceName): Not yet implemented")
     }
+
+    private static func printTitle(_ track: Track) {
+        print("\(track.artist) - \(track.name)")
+    }
 }
diff --git a/Sources/lyrics_engine.swift b/Sources/lyrics_engine.swift
new file mode 100644 (file)
index 0000000..661ce86
--- /dev/null
@@ -0,0 +1,20 @@
+/// Looks for lyrics on the internet
+class LyricsEngine {
+
+    let track: Track
+
+    var lyrics: String? {
+        get {
+            if track.artist == "test" && track.name == "test" {
+                return "Doo doo doo"
+            }
+
+            return nil
+        }
+    }
+
+    init(withTrack targetTrack: Track) {
+
+        track = targetTrack
+    }
+}
index 0ae48bcd891837259fa344cfb4c14feb394e2651..e4b2760e873888695e8174b42db9c84b77ca82e3 100644 (file)
@@ -80,7 +80,7 @@ func main() {
 
     if let titleFlag = flags["title"] as? BoolOption {
         if titleFlag.value == true {
-            Lyricli.printTitle()
+            Lyricli.showTitle = true
         }
     }
 
index d0af81720325aef3684ef06034ad3caa0bfffbc8..dd956ad3ca680418376cc06e1b494d14f511ac3b 100644 (file)
@@ -1,5 +1,5 @@
 /// Manages the different sources. Keeps track of them, lists and toggles
-public class SourceManager {
+class SourceManager {
 
     private var availableSources: [String: Source] = [
         "arguments": ArgumentsSource()
index efc09f45173ae6a120a857ee091bcf41d4d6f7ee..d2a9047faa6e4a21bce15b0f15fd3711a312135d 100644 (file)
@@ -1,7 +1,7 @@
 /// Contains the artist and name of a track
-public class Track {
-    public let name: String
-    public let artist: String
+class Track {
+    let name: String
+    let artist: String
 
     init(withName trackName: String, andArtist trackArtist: String) {