diff --git a/Sources/YouTubeKit/YouTubeResponseTypes/AutoCompletion/AutoCompletionResponse.swift b/Sources/YouTubeKit/YouTubeResponseTypes/AutoCompletion/AutoCompletionResponse.swift index f859797..299b28e 100644 --- a/Sources/YouTubeKit/YouTubeResponseTypes/AutoCompletion/AutoCompletionResponse.swift +++ b/Sources/YouTubeKit/YouTubeResponseTypes/AutoCompletion/AutoCompletionResponse.swift @@ -22,8 +22,8 @@ public struct AutoCompletionResponse: YouTubeResponse { public var autoCompletionEntries: [String] = [] public static func decodeData(data: Data) throws -> AutoCompletionResponse { - var dataString = String(decoding: data, as: UTF8.self) - .replacingOccurrences(of: "window.google.ac.h(", with: "") + guard var dataString = String(data: data, encoding: String.Encoding.windowsCP1254)? + .replacingOccurrences(of: "window.google.ac.h(", with: "") else { throw ResponseExtractionError(reponseType: Self.self, stepDescription: "Couldn't convert the response data to a string.") } dataString = String(dataString.dropLast()) let json = JSON(parseJSON: dataString) @@ -69,10 +69,9 @@ public struct AutoCompletionResponse: YouTubeResponse { for autoCompletionEntry in autoCompletionEntriesArray { if let autoCompletionEntry = autoCompletionEntry.array { for entryPartsOfArray in autoCompletionEntry { - if let autoCompletionString = entryPartsOfArray.string { - response.autoCompletionEntries.append(autoCompletionString) - break - } + guard let entryString = entryPartsOfArray.string else { continue } + response.autoCompletionEntries.append(entryString) + break } } } diff --git a/Tests/YouTubeKitTests/YouTubeKitTests.swift b/Tests/YouTubeKitTests/YouTubeKitTests.swift index d8451cb..7618446 100644 --- a/Tests/YouTubeKitTests/YouTubeKitTests.swift +++ b/Tests/YouTubeKitTests/YouTubeKitTests.swift @@ -703,7 +703,7 @@ final class YouTubeKitTests: XCTestCase { let TEST_NAME = "Test: testAutoCompletionResponse() -> " - let query: String = "mrbe" + let query: String = "hugo" let requestResult = try await AutoCompletionResponse.sendThrowingRequest(youtubeModel: YTM, data: [.query: query])