Implement `getQuerySuggestions`.
This commit is contained in:
parent
f774072fb1
commit
ae097a3198
|
@ -1,3 +1,5 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import '../../youtube_explode_dart.dart';
|
||||
import '../retry.dart';
|
||||
import '../reverse_engineering/responses/search_page.dart';
|
||||
|
@ -52,6 +54,18 @@ class SearchClient {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns the suggestions youtube provide while search on the page.
|
||||
Future<List<String>> getQuerySuggestions(String query) async {
|
||||
final request = await _httpClient.get(
|
||||
'https://suggestqueries-clients6.youtube.com/complete/search?client=youtube&hl=en&gl=en&q=${Uri.encodeComponent(query)}&callback=func');
|
||||
final body = request.body;
|
||||
final startIndex = body.indexOf('func(');
|
||||
final jsonStr = body.substring(startIndex + 5, body.length - 1);
|
||||
final data = json.decode(jsonStr) as List<dynamic>;
|
||||
final suggestions = data[1] as List<dynamic>;
|
||||
return suggestions.map((e) => e[0]).toList().cast<String>();
|
||||
}
|
||||
|
||||
/// Queries to YouTube to get the results.
|
||||
@Deprecated('Use getVideosFromPage instead - '
|
||||
'Should be used only to get related videos')
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: youtube_explode_dart
|
||||
description: A port in dart of the youtube explode library. Supports several API functions without the need of Youtube API Key.
|
||||
version: 1.9.0-nullsafety.2
|
||||
version: 1.9.0-nullsafety.3
|
||||
|
||||
homepage: https://github.com/Hexer10/youtube_explode_dart
|
||||
|
||||
|
|
Loading…
Reference in New Issue