-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b7e83c1
commit eb31c57
Showing
19 changed files
with
880 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
enum ApplicationType { | ||
case music, spotify | ||
} | ||
|
||
protocol Application { | ||
static var shared: Application { get } | ||
|
||
static func copySongURL() | ||
static func nextTrack() | ||
static func revealSong() | ||
static func revealArtist() | ||
static func revealAlbum() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import AppKit | ||
|
||
class MusicApplication: Application { | ||
static let app = AppleMusicBridge.appleMusicApplication() | ||
static var songId: String? | ||
static var albumId: String? | ||
|
||
private static let instance = MusicApplication() | ||
|
||
static var shared: Application { | ||
instance | ||
} | ||
|
||
static func copySongURL() { | ||
guard let songId = songId, let albumId = albumId else { return } | ||
|
||
let pasteboard = NSPasteboard.general | ||
pasteboard.declareTypes([.string], owner: nil) | ||
pasteboard.setString("https://music.apple.com/album/\(albumId)?i=\(songId)", forType: .string) | ||
} | ||
|
||
static func nextTrack() { | ||
app?.nextTrack() | ||
} | ||
|
||
static func revealSong() { | ||
app?.currentTrack.reveal() | ||
} | ||
|
||
static func revealArtist() { | ||
guard let songId = songId else { return } | ||
|
||
MusicAPI.getURI(songId: songId, for: .artist) { uri in | ||
if let uri = uri { | ||
NSWorkspace.shared.open(uri) | ||
} | ||
} | ||
} | ||
|
||
static func revealAlbum() { | ||
guard let songId = songId else { return } | ||
|
||
MusicAPI.getURI(songId: songId, for: .album) { uri in | ||
if let uri = uri { | ||
NSWorkspace.shared.open(uri) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import AppKit | ||
|
||
class SpotifyApplication: Application { | ||
static let app = SpotifyBridge.spotifyApplication() | ||
|
||
private static let instance = SpotifyApplication() | ||
|
||
static var shared: Application { | ||
instance | ||
} | ||
|
||
private static var songId: String? { | ||
app?.currentTrack.spotifyUrl.components(separatedBy: ":").last | ||
} | ||
|
||
static func copySongURL() { | ||
guard let songId = songId else { return } | ||
|
||
let pasteboard = NSPasteboard.general | ||
pasteboard.declareTypes([.string], owner: nil) | ||
pasteboard.setString("https://open.spotify.com/track/\(songId)", forType: .string) | ||
} | ||
|
||
static func nextTrack() { | ||
app?.nextTrack() | ||
} | ||
|
||
static func revealSong() { | ||
if let urlString = app?.currentTrack.spotifyUrl, let url = URL(string: urlString) { | ||
NSWorkspace.shared.open(url) | ||
} | ||
} | ||
|
||
static func revealArtist() { | ||
guard let songId = songId else { return } | ||
|
||
SpotifyAPI.getURI(songId: songId, for: .artist) { uri in | ||
if let uri = uri { | ||
NSWorkspace.shared.open(uri) | ||
} | ||
} | ||
} | ||
|
||
static func revealAlbum() { | ||
guard let songId = songId else { return } | ||
|
||
SpotifyAPI.getURI(songId: songId, for: .album) { uri in | ||
if let uri = uri { | ||
NSWorkspace.shared.open(uri) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.