Skip to content

Commit

Permalink
Update AcoustID section in README and clarify error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
wallisch committed Sep 26, 2024
1 parent 4570630 commit d344e1a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 40 deletions.
56 changes: 16 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,53 +124,29 @@ let acoustID = AcoustID(apiKey: "zfkYWDrOqAk", timeout: 10.0)
Lookup an AudioFingerprint object

``` swift
acoustID.lookup(newFingerprint) { response in
switch response {
case .failure(let error):
// AcoustID.Error
case .success(let results):
// [AcoustID.APIResult]
for result in results {
// Matching score (0.0 to 1.0)
let score = result.score

for recording in result.recordings! {
// Song title
let title = recording.title

// Song artists
let artists = recording.artists

// Song release groups (Albums, Singles, etc.)
let releasegroups = recording.releasegroups
}
do {
let results = try await acoustID.lookup(newFingerprint)
// [AcoustID.APIResult]
for result in results {
// Matching score (0.0 to 1.0)
let score = result.score
for recording in result.recordings! {
// Song title
let title = recording.title
// Song artists
let artists = recording.artists
// Song release groups (Albums, Singles, etc.)
let releasegroups = recording.releasegroups
}
}
}
```

### Handling errors

Throwing calls throw either an `AudioDecoder.Error`

``` swift
do {
let fileURL = URL(fileURLWithPath: "Invalid.mp3")
try AudioFingerprint(from: fileURL)
} catch {
// AudioDecoder.Error.invalidFile
// AcoustID.Error
}
```

Or an `AudioFingerprint.Error`
### Handling errors

``` swift
do {
try AudioFingerprint(from: "Invalid", duration: 46.0)
} catch {
// AudioFingerprint.Error.invalidFingerprint
}
```
The `AudioFingerprint` class throws either `AudioDecoder.Error` or `AudioFingerprint.Error` errors, the `AcoustID` class throws `AcoustID.Error` errors.

### Accessing Chromaprints C API

Expand Down
1 change: 1 addition & 0 deletions Tests/ChromaSwiftTests/ChromaSwiftTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ChromaSwiftTests: XCTestCase {
let fireworksURL = Bundle.module.url(forResource: "Fireworks", withExtension: "mp3", subdirectory: "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AUIJgoIJwFQhAgiAFCAGcsQEQQIBghCQBBhFDAEMAMgIBQAJgxQyDBDgGKMMCMREkAsJpwwQChgoEDAECUUYEAAg4BhDApkjBAGOEEEgIYB"
let fireworksHash = "00100100010001011111000101100111"

let invalidAPIKeyUrl = URL(string: "https://api.acoustid.org/v2/lookup?client=zfkYWDrUqAk&meta=recordings+releasegroups+compress&duration=46&fingerprint=AQABYJGikFSmJBCPijt6Hqkj_PjgH1l-XDyOnoeW48EFBqJ-4_BxHOeRT4Z_7IFPVLWRQ3sYwzJqW3iOixZeDdoTIeVRK7jE4znCPDrOHNcI8TnKI7wUNDryfvgfnDN6QjzRLsej48e5HbeCB9UHfzHEQ3TjYPrwu_gYdOXx5cSHMw_xED2PHlPy48eDZkW_47jEQufRE4auw8cXFtaP8MmOnMdvaA9jWEftHD8uyULHhBA_hM1x5Th59ImQ7nh2yBr8o5wR5spRHncu5LxwHX0I8UbZI9eFJzquEU9Eoju8NUV-fKjM491xKjz0ohfhQ8eUH88RfjkaLkeON4R2ozmOoz92iBz6Ic-OI48uVIalSUfvQnvh9fCOPi4eXFIonNBsNPKRR9hzfDv6HDmqDd_wKjs0Q8uJVy_u8KiFV7gvbLWKvngETRThoztK0vAP7-jj4sElhcIJLZrRH3mEPce3I3yO4tvxDb2yw-HR4zeqkcdFHd-L3XB9op-MK7iPqvnxlIUd4sepoP1x69CnEj18Qg98TA_-ICWV4wjUhkFz9MdxTIceNOyQ48yOnDvuHJ2mw66h49MOlMfjCZd0nEI9QtRRK0eOPXnQDXmOariOa0H1HO7RNcfdo43S4zr-YpcHV0cvGZeE6njyw8rCFHiOiuLxH6eSHXrRi_ChY_vR5wi_o-GyI8ehqSmaH8fRYw9EDv2Q5ziRRxcqw9Kko3ehHd50eEcfFw8uKRSgeUQjz8gj7Dm-Hf2Ro9qOb7h4VCSaE--NO0Qb-cKn49iuBldN1BNOHVVznIeVhcaPc2jH49-hK9LRHz6hw8f0HD_CPMrR7sjxhtBuNMfxoMceiOwQ4jsAJAUQlAEGmDCIAGXEAQBbyohCAgEVqEACCCIUA4QYAQgBVBAgiCGAKMIgEMIAYQgwSABhFmACCACIoEKQJhAxhhhBhFBCEAABJQgAhAgBkgFBhHCCEAKEQIYgRgAjCiFhBAAOCAQQQ4IgAJgh5xhklGBKCACQI-I4QggSSCiUgBBCAKEMEM4agRwRxxFCCBJIKAAREIAIaBBQQgKBiBBCMASAAIgAgaxgSgiLiCkHKSKEAcZIIpwzhBJCiFEKQQUQIAARSBRyiBCpgGBGGCEAcEAggAQSRgBqBDkbGYWYEgIo5Ig4hCCBiFIQKSGEAUAhkBARwiGGgABCEACIUEAYpgBRADBDyjFOAA")!
let invalidAPIKeyData = Data("{\"error\" : {\"message\" : \"invalid API key\", \"code\" : 4}, \"status\" : \"error\"}".utf8)
let invalidFingerprintUrl = URL(string: "https://api.acoustid.org/v2/lookup?client=zfkYWDrOqAk&meta=recordings+releasegroups+compress&duration=46&fingerprint=AwABYJGikFSmJBB_VFTQ88gHqzvgH1mu48KP5jw0Hz8OKYPzG_CPE8ePXIZ_7IHPo6qRQ3sYw_JRO8ePS7JwptAeIQyPByeP5wjz6DhzXCPE5yiP8FKORsj74c-D3-gJ8TTaBY-O5zh93AqqBV-gK8chWnQwHb9Y1COu8TjP4SeeycXR86gcTDl-PGhW9DuOJ2Kh9Thh6Dr84cth_Qgf5ciP09DeGI2Obzm-45IsdEwI8UPYHN_xH30ihNnRLjvkwusR3miuHGWP_0LOC9fRZ4GWH2eOXBee6LhGPBGJ7vDWFPnxodp4fIdKhcdZ9IQP8Zie40eYRznaHTneENqN5jiO_tghckWPfAfy6EJlwZLCoy-09_AK7-jj4sElhcIJLTU6H3mEPce3o88RHt_wDVWVHS564vmL86hFXMePrT764omgiYaP7kHJC0d5PC7uB9conNCiGfWOfNiT4zvC56iG6_jQKzscHj1-o1oUHtfxvdgN1yf6ybiC0sebH1ampTieo6J4_Li1Q59K9IIPPdh-9EH4Bw2548ihaima_ehx9NgDfWg-5MF55DvuHI00Ha-hB950eOhj4cIlVcJRjxB1hI1yYE8edBvyo9pxBW9QPYc7outxh0cb-cJ1_NjVwD96yTiFqsfzw8rCFD8-VObx7jgVHnrRi_ChY8qP5wi_HA2XI8dNaLfRHMfRHztEDv2QZ8eRRxcqw5IiHX2hHd50eEcfFw8uKRROaDYa-cgj7Dm-HeFzoNqOb7iyoyKaE7_xkUctH59c3Nh-4qpRK8J9VM2Pp4QdGj9OBe2P_9AVHf3hEzp8TM_xI8yVB50QqA3R3Ojx4JiOByI7hMezIz8AxARABDCABGICAONMAgI5SglEAgGgAgGUICEEI0IxQIgRgBAgBAGAGECAIswBIZwCVAEjBBBUKCcAJIIKQRp0xhBDBCECUAYgAo4gABAiggAJCBCCCEAIAUIAQwxBjABGFEICCqCIAMIwBYgCgBlyjkGGCSUEA8IRcRwhBAkkFAhIEACEEwZJAgSzxDjnjFCOEGKEEwpBBwQgAhoKlJBAIAGEYMwII4AgQCGABCJCSCC02UgQxYQywBgFERGHEkKMYhYpgAxAACKFHICEIAYEQ0gYAYADAgHEkCAIAGDIOQYZJZgSginkiDiOEIIEEgoiJYSAwACFEUBECCEYAkAAgQgBRCggDFNCKETKYYIJxQA")!
Expand Down

0 comments on commit d344e1a

Please sign in to comment.