Skip to content

Commit

Permalink
Add Apple Music/Spotify integration
Browse files Browse the repository at this point in the history
Remove some debug stuff
  • Loading branch information
glouel committed Jul 2, 2021
1 parent 5854fad commit 824ab90
Show file tree
Hide file tree
Showing 32 changed files with 1,061 additions and 115 deletions.
72 changes: 68 additions & 4 deletions Aerial.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion Aerial/Source/Controllers/CustomVideoController.swift
Expand Up @@ -389,7 +389,6 @@ extension CustomVideoController: NSOutlineViewDataSource {

// A folder may have childs
if let source = item as? Source {
print("woo : \(VideoList.instance.videos.filter({ $0.source.name == source.name }).count)")
return VideoList.instance.videos.filter({ $0.source.name == source.name }).count
}

Expand Down
4 changes: 1 addition & 3 deletions Aerial/Source/Models/API/Forecast.swift
Expand Up @@ -213,7 +213,6 @@ struct Forecast {
}
debugLog("=== OF: Starting manual mode")

print(makeUrl(location: PrefsInfo.weather.locationString))
fetchData(from: makeUrl(location: PrefsInfo.weather.locationString)) { result in
switch result {
case .success(let jsonString):
Expand All @@ -226,9 +225,8 @@ struct Forecast {
} else {
completion(.failure(.unknown))
}
case .failure(let error):
case .failure(_):
completion(.failure(.unknown))
print(error.localizedDescription)
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions Aerial/Source/Models/API/GeoCoding.swift
Expand Up @@ -46,7 +46,6 @@ struct GeoCoding {
fetchData(from: makeUrl()) { result in
switch result {
case .success(let jsonString):
print(jsonString)
let jsonData = jsonString.data(using: .utf8)!

if let geoEntity = try? newJSONDecoder().decode(GeoCodingArray.self, from: jsonData) {
Expand All @@ -67,9 +66,8 @@ struct GeoCoding {
} else {
completion(.failure(.unknown))
}
case .failure(let error):
case .failure(_):
completion(.failure(.unknown))
print(error.localizedDescription)
}
}
}
Expand Down
12 changes: 4 additions & 8 deletions Aerial/Source/Models/API/OneCall.swift
Expand Up @@ -204,8 +204,6 @@ struct OneCall {
let openWeather = try newJSONDecoder().decode(OCOneCall.self, from: jsonData)
completion(.success(openWeather))
} catch {
print("decoder failure")
// print(error)
completion(.failure(.unknown))
}

Expand Down Expand Up @@ -234,9 +232,8 @@ struct OneCall {
} else {
completion(.failure(.unknown))
}
case .failure(let error):
case .failure(_):
completion(.failure(.unknown))
print(error.localizedDescription)
}
}
})
Expand All @@ -247,7 +244,6 @@ struct OneCall {
GeoCoding.fetch { result in
switch result {
case .success(let geoLocation):
print(geoLocation)
fetchData(from: makeUrl(lat: geoLocation.lat, lon: geoLocation.lon)) { result in
switch result {
case .success(let jsonString):
Expand All @@ -260,13 +256,13 @@ struct OneCall {
} else {
completion(.failure(.unknown))
}
case .failure(let error):
case .failure(_):
completion(.failure(.unknown))
print(error.localizedDescription)
}
}
case .failure(let error):
print(error.localizedDescription)
debugLog(error.localizedDescription)
completion(.failure(.unknown))
}
}
}
Expand Down
8 changes: 1 addition & 7 deletions Aerial/Source/Models/API/OpenWeather.swift
Expand Up @@ -187,7 +187,6 @@ struct OpenWeather {
fetchData(from: makeUrl(lat: lat, lon: lon)) { result in
switch result {
case .success(let jsonString):
print(jsonString)
let jsonData = jsonString.data(using: .utf8)!

if var openWeather = try? newJSONDecoder().decode(OWeather.self, from: jsonData) {
Expand All @@ -199,7 +198,6 @@ struct OpenWeather {
}
case .failure(let error):
completion(.failure(.unknown))
print(error.localizedDescription)
}
}
})
Expand All @@ -210,23 +208,19 @@ struct OpenWeather {
}
debugLog("=== OW: Starting manual mode")

print(makeUrl(location: PrefsInfo.weather.locationString))
fetchData(from: makeUrl(location: PrefsInfo.weather.locationString)) { result in
switch result {
case .success(let jsonString):
print(jsonString)
let jsonData = jsonString.data(using: .utf8)!
do {
var openWeather = try newJSONDecoder().decode(OWeather.self, from: jsonData)
openWeather.processTemperatures()
completion(.success(openWeather))
} catch {
print("error : \(error.localizedDescription)")
completion(.failure(.cityNotFound))
}
case .failure(let error):
case .failure(_):
completion(.failure(.unknown))
print(error.localizedDescription)
}
}

Expand Down
23 changes: 10 additions & 13 deletions Aerial/Source/Models/Aerial.swift
Expand Up @@ -17,11 +17,18 @@ class Aerial: NSObject {
// We also track darkmode here now
static var darkMode = false

// And we track if we are running under companion
// And we track if we are running under Aerial's Companion app
static var underCompanion = false

// Track our version number for logs and stuff
static var version: String = {
return getVersionString()
if let version = Bundle(identifier: "com.johncoates.Aerial-Test")?.infoDictionary?["CFBundleShortVersionString"] as? String {
return "Version " + version
} else if let version = Bundle(identifier: "com.JohnCoates.Aerial")?.infoDictionary?["CFBundleShortVersionString"] as? String {
return "Version " + version
}

return "Version ?"
}()

static func checkCompanion() {
Expand All @@ -45,16 +52,6 @@ class Aerial: NSObject {
}
}

static func getVersionString() -> String {
if let version = Bundle(identifier: "com.johncoates.Aerial-Test")?.infoDictionary?["CFBundleShortVersionString"] as? String {
return "Version " + version
} else if let version = Bundle(identifier: "com.JohnCoates.Aerial")?.infoDictionary?["CFBundleShortVersionString"] as? String {
return "Version " + version
}

return "Version ?"
}

// Language detection
static func getPreferredLanguage() -> String {
let printOutputLocale: NSLocale = NSLocale(localeIdentifier: Locale.preferredLanguages[0])
Expand Down Expand Up @@ -192,7 +189,7 @@ class Aerial: NSObject {
try task.run()
} catch {
// handle errors
print("Error: \(error.localizedDescription)")
debugLog("Error: \(error.localizedDescription)")
}
} else {
// A non existing command will crash 10.12
Expand Down
75 changes: 75 additions & 0 deletions Aerial/Source/Models/Music/AppleMusicSong.swift
@@ -0,0 +1,75 @@
//
// AppleMusicSong.swift
// Aerial
//
// Created by Guillaume Louel on 30/06/2021.
// Copyright © 2021 Guillaume Louel. All rights reserved.
//
// This file was generated from JSON Schema using quicktype, do not modify it directly.
// To parse the JSON, add this file to your project and do:
//
// let appleMusicSong = try? newJSONDecoder().decode(AppleMusicSong.self, from: jsonData)

import Foundation

// MARK: - AppleMusicSong
struct AppleMusicSong: Codable {
let data: [AppleMusicSongDatum]?
}

// MARK: - AppleMusicSongDatum
struct AppleMusicSongDatum: Codable {
let id, type, href: String?
let attributes: Attributes?
let relationships: Relationships?
}

// MARK: - Attributes
struct Attributes: Codable {
let previews: [Preview]?
let artwork: Artwork?
let artistName: String?
let url: String?
let discNumber: Int?
let genreNames: [String]?
let durationInMillis: Int?
let releaseDate, name, isrc: String?
let hasLyrics: Bool?
let albumName: String?
let playParams: PlayParams?
let trackNumber: Int?
let contentRating: String?
}

// MARK: - Artwork
struct Artwork: Codable {
let width, height: Int?
let url, bgColor, textColor1, textColor2: String?
let textColor3, textColor4: String?
}

// MARK: - PlayParams
struct PlayParams: Codable {
let id, kind: String?
}

// MARK: - Preview
struct Preview: Codable {
let url: String?
}

// MARK: - Relationships
struct Relationships: Codable {
let artists, albums: Albums?
}

// MARK: - Albums
struct Albums: Codable {
let href: String?
let data: [AlbumsDatum]?
}

// MARK: - AlbumsDatum
struct AlbumsDatum: Codable {
let id, type, href: String?
}

0 comments on commit 824ab90

Please sign in to comment.