diff --git a/lib/src/search/search_client.dart b/lib/src/search/search_client.dart index 24959c0..de5606f 100644 --- a/lib/src/search/search_client.dart +++ b/lib/src/search/search_client.dart @@ -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> 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; + final suggestions = data[1] as List; + return suggestions.map((e) => e[0]).toList().cast(); + } + /// Queries to YouTube to get the results. @Deprecated('Use getVideosFromPage instead - ' 'Should be used only to get related videos') diff --git a/pubspec.yaml b/pubspec.yaml index f25ec5c..f1ab391 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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