Skip to content

Commit

Permalink
Fixed autocompletion extraction.
Browse files Browse the repository at this point in the history
  • Loading branch information
b5i committed Jul 30, 2024
1 parent b154b23 commit f0fa63d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/YouTubeKitTests/YouTubeKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down

0 comments on commit f0fa63d

Please sign in to comment.