-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
11 changed files
with
378 additions
and
60 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,12 @@ | ||
// | ||
// ArtistInfoResponse.swift | ||
// firstfm | ||
// | ||
// Created by Stanislas Lange on 18/07/2021. | ||
// | ||
|
||
import Foundation | ||
|
||
struct ArtistInfoResponse: Codable { | ||
let artist: ArtistInfo | ||
} |
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,22 @@ | ||
// | ||
// ArtistBio.swift | ||
// firstfm | ||
// | ||
// Created by Stanislas Lange on 19/07/2021. | ||
// | ||
|
||
import Foundation | ||
|
||
struct ArtistBio: Codable { | ||
let links: ArtistBioLinks | ||
let content, published, summary: String | ||
} | ||
|
||
struct ArtistBioLinks: Codable { | ||
let link: ArtistBioLink | ||
} | ||
|
||
struct ArtistBioLink: Codable { | ||
let rel: String | ||
let href: String | ||
} |
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,20 @@ | ||
// | ||
// ArtistInfo.swift | ||
// firstfm | ||
// | ||
// Created by Stanislas Lange on 19/07/2021. | ||
// | ||
|
||
import Foundation | ||
|
||
struct ArtistInfo: Codable { | ||
let bio: ArtistBio | ||
let ontour: Int | ||
let stats: ArtistStats | ||
let mbid: String | ||
let image: [LastFMImage] | ||
var similar: SimilarArtists | ||
let url: String | ||
let tags: Tags | ||
let name, streamable: String | ||
} |
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,12 @@ | ||
// | ||
// ArtistStats.swift | ||
// firstfm | ||
// | ||
// Created by Stanislas Lange on 19/07/2021. | ||
// | ||
|
||
import Foundation | ||
|
||
struct ArtistStats: Codable { | ||
let playcount, listeners: Int | ||
} |
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,18 @@ | ||
// | ||
// SimilarArtist.swift | ||
// firstfm | ||
// | ||
// Created by Stanislas Lange on 19/07/2021. | ||
// | ||
|
||
import Foundation | ||
|
||
struct SimilarArtist: Codable { | ||
let url: String | ||
let name: String | ||
var image: [LastFMImage] | ||
} | ||
|
||
struct SimilarArtists: Codable { | ||
var artist: [SimilarArtist] | ||
} |
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,17 @@ | ||
// | ||
// Tag.swift | ||
// firstfm | ||
// | ||
// Created by Stanislas Lange on 19/07/2021. | ||
// | ||
|
||
import Foundation | ||
|
||
struct Tags: Codable { | ||
let tag: [Tag] | ||
} | ||
|
||
struct Tag: Codable { | ||
let name: String | ||
let url: String | ||
} |
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,50 @@ | ||
// | ||
// DoubleFormat.swift | ||
// firstfm | ||
// | ||
// Created by Stanislas Lange on 19/07/2021. | ||
// | ||
|
||
import Foundation | ||
|
||
// https://stackoverflow.com/a/48371527/6945353 | ||
|
||
extension Double { | ||
func reduceScale(to places: Int) -> Double { | ||
let multiplier = pow(10, Double(places)) | ||
let newDecimal = multiplier * self // move the decimal right | ||
let truncated = Double(Int(newDecimal)) // drop the fraction | ||
let originalDecimal = truncated / multiplier // move the decimal back | ||
return originalDecimal | ||
} | ||
} | ||
|
||
extension Int { | ||
func formatted() -> String { | ||
let num = abs(Double(self)) | ||
let sign = (self < 0) ? "-" : "" | ||
|
||
switch num { | ||
case 1_000_000_000...: | ||
var formatted = num / 1_000_000_000 | ||
formatted = formatted.reduceScale(to: 1) | ||
return "\(sign)\(formatted)B" | ||
|
||
case 1_000_000...: | ||
var formatted = num / 1_000_000 | ||
formatted = formatted.reduceScale(to: 1) | ||
return "\(sign)\(formatted)M" | ||
|
||
case 1_000...: | ||
var formatted = num / 1_000 | ||
formatted = formatted.reduceScale(to: 1) | ||
return "\(sign)\(formatted)k" | ||
|
||
case 0...: | ||
return "\(self)" | ||
|
||
default: | ||
return "\(sign)\(self)" | ||
} | ||
} | ||
} |
Oops, something went wrong.