Skip to content

Commit

Permalink
Merge pull request #4 from thatcherclough/spotify
Browse files Browse the repository at this point in the history
Added support for Spotify
  • Loading branch information
thatcherclough authored Dec 3, 2020
2 parents 8e25a99 + 7794aaf commit c5a6f6a
Show file tree
Hide file tree
Showing 236 changed files with 2,784 additions and 322 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.DS_Store
/Pods
*xcworkspace/xcuserdata/*
/videos/
1 change: 1 addition & 0 deletions CoverFlow-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
//

#import <HueSDK/HueSDK.h>
#import <SpotifyiOS/SpotifyiOS.h>
82 changes: 69 additions & 13 deletions CoverFlow.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,34 @@

/* Begin PBXBuildFile section */
B6EE4D5E6C89C5D1D011CD19 /* Pods_CoverFlow.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EE561888D47C9248FD364BBD /* Pods_CoverFlow.framework */; };
DD3C001A2577C8E10080CE82 /* SpotifyiOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DD3C000F2577C7A10080CE82 /* SpotifyiOS.framework */; };
DD3C001E2577C9F30080CE82 /* HueSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DD3C00102577C7A10080CE82 /* HueSDK.framework */; };
DD3C001F2577C9F30080CE82 /* HueSDK.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = DD3C00102577C7A10080CE82 /* HueSDK.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
DD42841E254E743500E6E3D1 /* songChange.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = DD42841D254E743500E6E3D1 /* songChange.mp3 */; };
DD428420254E74FF00E6E3D1 /* audioCheck.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = DD42841F254E74FF00E6E3D1 /* audioCheck.mp3 */; };
DD439AD125609FDC00082CEF /* AppleMusicController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD439AD025609FDC00082CEF /* AppleMusicController.swift */; };
DD439AD325609FE700082CEF /* SpotifyController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD439AD225609FE700082CEF /* SpotifyController.swift */; };
DDAEDC98253CF53D002F3175 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDAEDC97253CF53D002F3175 /* AppDelegate.swift */; };
DDAEDC9A253CF53D002F3175 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDAEDC99253CF53D002F3175 /* SceneDelegate.swift */; };
DDAEDC9C253CF53D002F3175 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDAEDC9B253CF53D002F3175 /* ViewController.swift */; };
DDAEDC9F253CF53D002F3175 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DDAEDC9D253CF53D002F3175 /* Main.storyboard */; };
DDAEDCA1253CF541002F3175 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DDAEDCA0253CF541002F3175 /* Assets.xcassets */; };
DDAEDCA4253CF541002F3175 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DDAEDCA2253CF541002F3175 /* LaunchScreen.storyboard */; };
DDAEDCBD253CFCD7002F3175 /* BridgeDiscoveryController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDAEDCBC253CFCD7002F3175 /* BridgeDiscoveryController.swift */; };
DDFD8BD9253E308400BBE27A /* HueSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DDAEDCB1253CF585002F3175 /* HueSDK.framework */; };
DDFD8BDA253E308400BBE27A /* HueSDK.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = DDAEDCB1253CF585002F3175 /* HueSDK.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
DDF07094256C375100353469 /* MusicProviderViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDF07093256C375100353469 /* MusicProviderViewController.swift */; };
DDFD8BDF253E323900BBE27A /* BridgeInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDFD8BDE253E323900BBE27A /* BridgeInfo.swift */; };
DDFD8BE1253E382C00BBE27A /* PushButtonViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDFD8BE0253E382C00BBE27A /* PushButtonViewController.swift */; };
DDFD8BE3253E479400BBE27A /* LightSelectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDFD8BE2253E479400BBE27A /* LightSelectionViewController.swift */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
DDFD8BDB253E308400BBE27A /* Embed Frameworks */ = {
DD3C00202577C9F30080CE82 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 12;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
DDFD8BDA253E308400BBE27A /* HueSDK.framework in Embed Frameworks */,
DD3C001F2577C9F30080CE82 /* HueSDK.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -43,8 +47,12 @@
66953F2EC209EF73DCB309AE /* Pods-TempName.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TempName.release.xcconfig"; path = "Target Support Files/Pods-TempName/Pods-TempName.release.xcconfig"; sourceTree = "<group>"; };
90BB89A3DAB3B6ABDD25053E /* Pods-TempName.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TempName.debug.xcconfig"; path = "Target Support Files/Pods-TempName/Pods-TempName.debug.xcconfig"; sourceTree = "<group>"; };
9FB6E60052D5E69CAB8CF1B2 /* Pods-CoverFlow.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CoverFlow.debug.xcconfig"; path = "Target Support Files/Pods-CoverFlow/Pods-CoverFlow.debug.xcconfig"; sourceTree = "<group>"; };
DD3C000F2577C7A10080CE82 /* SpotifyiOS.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SpotifyiOS.framework; path = Frameworks/SpotifyiOS.framework; sourceTree = "<group>"; };
DD3C00102577C7A10080CE82 /* HueSDK.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = HueSDK.framework; path = Frameworks/HueSDK.framework; sourceTree = "<group>"; };
DD42841D254E743500E6E3D1 /* songChange.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; name = songChange.mp3; path = CoverFlow/Assets.xcassets/songChange.mp3; sourceTree = "<group>"; };
DD42841F254E74FF00E6E3D1 /* audioCheck.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; name = audioCheck.mp3; path = CoverFlow/Assets.xcassets/audioCheck.mp3; sourceTree = "<group>"; };
DD439AD025609FDC00082CEF /* AppleMusicController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleMusicController.swift; sourceTree = "<group>"; };
DD439AD225609FE700082CEF /* SpotifyController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpotifyController.swift; sourceTree = "<group>"; };
DDAEDC94253CF53D002F3175 /* CoverFlow.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CoverFlow.app; sourceTree = BUILT_PRODUCTS_DIR; };
DDAEDC97253CF53D002F3175 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
DDAEDC99253CF53D002F3175 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand All @@ -54,8 +62,8 @@
DDAEDCA3253CF541002F3175 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
DDAEDCA5253CF541002F3175 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
DDAEDCAD253CF56F002F3175 /* CoverFlow-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CoverFlow-Bridging-Header.h"; sourceTree = "<group>"; };
DDAEDCB1253CF585002F3175 /* HueSDK.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = HueSDK.framework; sourceTree = "<group>"; };
DDAEDCBC253CFCD7002F3175 /* BridgeDiscoveryController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BridgeDiscoveryController.swift; sourceTree = "<group>"; };
DDF07093256C375100353469 /* MusicProviderViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MusicProviderViewController.swift; sourceTree = "<group>"; };
DDFD8BDE253E323900BBE27A /* BridgeInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BridgeInfo.swift; sourceTree = "<group>"; };
DDFD8BE0253E382C00BBE27A /* PushButtonViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PushButtonViewController.swift; sourceTree = "<group>"; };
DDFD8BE2253E479400BBE27A /* LightSelectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LightSelectionViewController.swift; sourceTree = "<group>"; };
Expand All @@ -67,7 +75,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
DDFD8BD9253E308400BBE27A /* HueSDK.framework in Frameworks */,
DD3C001E2577C9F30080CE82 /* HueSDK.framework in Frameworks */,
DD3C001A2577C8E10080CE82 /* SpotifyiOS.framework in Frameworks */,
B6EE4D5E6C89C5D1D011CD19 /* Pods_CoverFlow.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -78,6 +87,8 @@
57783310C00EE6ADA2D86FB3 /* Frameworks */ = {
isa = PBXGroup;
children = (
DD3C00102577C7A10080CE82 /* HueSDK.framework */,
DD3C000F2577C7A10080CE82 /* SpotifyiOS.framework */,
EE561888D47C9248FD364BBD /* Pods_CoverFlow.framework */,
);
name = Frameworks;
Expand All @@ -98,7 +109,6 @@
isa = PBXGroup;
children = (
DDAEDCAD253CF56F002F3175 /* CoverFlow-Bridging-Header.h */,
DDAEDCB1253CF585002F3175 /* HueSDK.framework */,
DD42841F254E74FF00E6E3D1 /* audioCheck.mp3 */,
DD42841D254E743500E6E3D1 /* songChange.mp3 */,
DDAEDC96253CF53D002F3175 /* CoverFlow */,
Expand All @@ -122,6 +132,8 @@
DDAEDC97253CF53D002F3175 /* AppDelegate.swift */,
DDAEDC99253CF53D002F3175 /* SceneDelegate.swift */,
DDAEDC9B253CF53D002F3175 /* ViewController.swift */,
DD439AD225609FE700082CEF /* SpotifyController.swift */,
DD439AD025609FDC00082CEF /* AppleMusicController.swift */,
DDAEDC9D253CF53D002F3175 /* Main.storyboard */,
DDFD8BE0253E382C00BBE27A /* PushButtonViewController.swift */,
DDAEDCBC253CFCD7002F3175 /* BridgeDiscoveryController.swift */,
Expand All @@ -130,6 +142,7 @@
DDAEDCA2253CF541002F3175 /* LaunchScreen.storyboard */,
DDAEDCA5253CF541002F3175 /* Info.plist */,
DDFD8BE2253E479400BBE27A /* LightSelectionViewController.swift */,
DDF07093256C375100353469 /* MusicProviderViewController.swift */,
);
path = CoverFlow;
sourceTree = "<group>";
Expand All @@ -146,7 +159,7 @@
DDAEDC91253CF53D002F3175 /* Frameworks */,
DDAEDC92253CF53D002F3175 /* Resources */,
7ED350797F24C3FBCCB06D1A /* [CP] Embed Pods Frameworks */,
DDFD8BDB253E308400BBE27A /* Embed Frameworks */,
DD3C00202577C9F30080CE82 /* Embed Frameworks */,
);
buildRules = (
);
Expand Down Expand Up @@ -255,10 +268,13 @@
DDAEDC9C253CF53D002F3175 /* ViewController.swift in Sources */,
DDAEDC98253CF53D002F3175 /* AppDelegate.swift in Sources */,
DDFD8BE3253E479400BBE27A /* LightSelectionViewController.swift in Sources */,
DD439AD325609FE700082CEF /* SpotifyController.swift in Sources */,
DDAEDC9A253CF53D002F3175 /* SceneDelegate.swift in Sources */,
DDFD8BDF253E323900BBE27A /* BridgeInfo.swift in Sources */,
DDFD8BE1253E382C00BBE27A /* PushButtonViewController.swift in Sources */,
DDF07094256C375100353469 /* MusicProviderViewController.swift in Sources */,
DDAEDCBD253CFCD7002F3175 /* BridgeDiscoveryController.swift in Sources */,
DD439AD125609FDC00082CEF /* AppleMusicController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -408,19 +424,39 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = "";
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = YA924NN5VN;
DYLIB_INSTALL_NAME_BASE = "";
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)",
"$(PROJECT_DIR)/Frameworks",
);
INFOPLIST_FILE = CoverFlow/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.1.0;
MARKETING_VERSION = 1.2.0;
OTHER_LDFLAGS = (
"$(inherited)",
"-framework",
"\"ColorThiefSwift\"",
"-framework",
"\"CoreTelephony\"",
"-framework",
"\"Foundation\"",
"-framework",
"\"Keys\"",
"-framework",
"\"Reachability\"",
"-framework",
"\"SystemConfiguration\"",
"-framework",
"\"UIKit\"",
"-ObjC",
);
PRODUCT_BUNDLE_IDENTIFIER = dev.thatcherclough.CoverFlow;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "CoverFlow-Bridging-Header.h";
Expand All @@ -438,19 +474,39 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = "";
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = YA924NN5VN;
DYLIB_INSTALL_NAME_BASE = "";
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)",
"$(PROJECT_DIR)/Frameworks",
);
INFOPLIST_FILE = CoverFlow/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.1.0;
MARKETING_VERSION = 1.2.0;
OTHER_LDFLAGS = (
"$(inherited)",
"-framework",
"\"ColorThiefSwift\"",
"-framework",
"\"CoreTelephony\"",
"-framework",
"\"Foundation\"",
"-framework",
"\"Keys\"",
"-framework",
"\"Reachability\"",
"-framework",
"\"SystemConfiguration\"",
"-framework",
"\"UIKit\"",
"-ObjC",
);
PRODUCT_BUNDLE_IDENTIFIER = dev.thatcherclough.CoverFlow;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "CoverFlow-Bridging-Header.h";
Expand Down
Binary file not shown.

This file was deleted.

121 changes: 121 additions & 0 deletions CoverFlow/AppleMusicController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
//
// AppleMusicController.swift
// CoverFlow
//
// Created by Thatcher Clough on 11/14/20.
//

import Foundation
import StoreKit
import MediaPlayer
import Keys

class AppleMusicController {

// MARK: Constructor and variables

var apiKey: String!
var countryCode: String!
let player = MPMusicPlayerController.systemMusicPlayer

init(apiKey: String) {
self.apiKey = apiKey
getCountryCode()
}

func getCountryCode() {
DispatchQueue.global(qos: .background).async {
let controller = SKCloudServiceController()
controller.requestStorefrontCountryCode { countryCode, error in
if countryCode == nil || error != nil {
self.countryCode = "us"
} else {
self.countryCode = countryCode
}
}
}
}

// MARK: Functions

func getCurrentAlbumName() -> String {
let nowPlaying: MPMediaItem? = player.nowPlayingItem
let albumName = nowPlaying?.albumTitle
if nowPlaying == nil || albumName == nil {
return "nil"
} else {
return albumName!
}
}

func getCurrentArtistName() -> String {
let nowPlaying: MPMediaItem? = player.nowPlayingItem
let artistName = (nowPlaying?.albumArtist != nil) ? nowPlaying?.albumArtist : nowPlaying?.artist
if nowPlaying == nil || artistName == nil {
return "nil"
} else {
return artistName!
}
}

func getCoverFromAPI(albumName: String, artistName: String, completion: @escaping (String?)->()) {
let searchTerm = albumName.replacingOccurrences(of: " ", with: "+")
var components = URLComponents()
components.scheme = "https"
components.host = "api.music.apple.com"
components.path = "/v1/catalog/\(countryCode ?? "us")/search"
components.queryItems = [
URLQueryItem(name: "term", value: searchTerm),
URLQueryItem(name: "limit", value: "15"),
URLQueryItem(name: "types", value: "albums"),
]
let url = components.url!

var request = URLRequest(url: url)
request.setValue("Bearer \(apiKey ?? "nil")", forHTTPHeaderField: "Authorization")
request.httpMethod = "GET"

let task = URLSession.shared.dataTask(with: request as URLRequest, completionHandler: { data, response, error in
guard error == nil else {
return completion(nil)
}
guard let data = data else {
return completion(nil)
}

do {
if let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String: Any] {
if let results = json["results"] as? [String: Any] {
if let albums = results["albums"] as? [String: Any] {
if let data = albums["data"] as? NSArray {
for album in data {
guard let albumJson = album as? [String: Any] else {
continue
}
guard let attributes = albumJson["attributes"] as? [String: Any] else {
continue
}

if (attributes["name"] as! String == albumName) && (attributes["artistName"] as! String == artistName) {
guard let artwork = attributes["artwork"] as? [String: Any] else {
continue
}

var url = artwork["url"] as? String
url = url?.replacingOccurrences(of: "{w}", with: "200")
url = url?.replacingOccurrences(of: "{h}", with: "200")
return completion(url)
}
}
}
}
}
}
return completion(nil)
} catch {
return completion(nil)
}
})
task.resume()
}
}
Loading

0 comments on commit c5a6f6a

Please sign in to comment.