youtube_explode_dart
youtube_explode_dart copied to clipboard
[Bug]: Youtube ban IP
What happened?
after some videos youtube ban the ip i need to change the internet
Stacktrace / error logs.
Package (youtube_explode_dart) version
No response
Checklist
- [x] I have provided a descriptive title
- [x] I have searched the issues of this repository and believe that this is not a duplicate
- [x] I have tested with the latest version of the library
- [x] (If relevant) I can open the video/playlist in a incognito/private window without being logged in.
- [ ] I have sponsored the project
Additional notes
No response
Same problem
Unfortunately there is nothing I can do against it; the only long-term solution would be to include the cookies of a logged-in user when requesting the video. If I have time I'll write a guide on how to do that in the coming days/week
Thank you very much! Yes, please prepare some guidance as soon as possible @Hexer10
How can I add cookies can you give me the code
class CookieYT extends YoutubeHttpClient {
@override
Map<String, String> get headers =>
{
...super.defaultHeaders
//... add your headers here.
// NOTE. defaultHeaders has a 'cookies' key, you may want to remove/ replace it
}
}
Now pass the CookieYT in YouTubeExplode instance.
final cookieExplode = YouTubeExplode(CookieYT());
cookieYT.videos.get("...");
If I only get the video subtitles, will it cause my IP to be blocked?
Same problem!!!
@khaled-0 Can you give full code for adding cookies
@khaled-0 Can you give full code for adding cookies
https://github.com/khaled-0/Syncara/blob/93e9ab6502bce3c5892f48bafd13ec86f93ae3e1/lib/clients/yt_media_client.dart
but weirdly I'm still not getting videos in some cases
@khaled-0 it's mean there is no solution for this ?
@khaled-0 can we pass cookies like this
### 1. Youtube Login with webview 2. Extract Cookies 3. Repalce with Library 4. Use the library
"Is this works or Is their any other way"
late final WebViewController _controller; String _cookieString = ""; bool _loadingVideos = false; List<yt.Video> _videos = [];
@override void initState() { super.initState(); _controller = WebViewController() ..setJavaScriptMode(JavaScriptMode.unrestricted) ..setNavigationDelegate( NavigationDelegate( onProgress: (int progress) { debugPrint('WebView is loading (progress: $progress%)'); }, onPageStarted: (String url) { debugPrint('Page started loading: $url'); }, onPageFinished: (String url) { debugPrint('Page finished loading: $url'); // Optionally auto-extract cookies when page finishes loading // _getCookies(); }, onWebResourceError: (WebResourceError error) { debugPrint(''' Page resource error: Code: ${error.errorCode} Description: ${error.description} For diagnosing, look at: ${error.url} '''); }, ), ) ..loadRequest(Uri.parse('https://youtube.com')); }
Future
Future
setState(() {
_loadingVideos = true;
_videos = [];
});
// --- FIX STARTS HERE ---
final client = _CookieClient(_cookieString);
final ytClient = yt.YoutubeExplode(client); // This line now works correctly
// --- FIX ENDS HERE ---
try {
final aaa = await ytClient.videos.streamsClient.getManifest("FbXOsVByKmk");
print(aaa.audio.withHighestBitrate().url);
final results = await ytClient.search.search("pawan kalyan");
final limited = results;
setState(() {
_videos = limited;
});
} catch (e) {
debugPrint("Search error: $e");
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error fetching videos: ${e.toString()}')),
);
} finally {
setState(() {
_loadingVideos = false;
});
ytClient.close();
}
}
@khaled-0 can we pass cookies like this
### 1. Youtube Login with webview 2. Extract Cookies 3. Repalce with Library 4. Use the library
"Is this works or Is their any other way"
late final WebViewController _controller; String _cookieString = ""; bool _loadingVideos = false; List<yt.Video> _videos = [];
@OverRide void initState() { super.initState(); _controller = WebViewController() ..setJavaScriptMode(JavaScriptMode.unrestricted) ..setNavigationDelegate( NavigationDelegate( onProgress: (int progress) { debugPrint('WebView is loading (progress: $progress%)'); }, onPageStarted: (String url) { debugPrint('Page started loading: $url'); }, onPageFinished: (String url) { debugPrint('Page finished loading: $url'); // Optionally auto-extract cookies when page finishes loading // _getCookies(); }, onWebResourceError: (WebResourceError error) { debugPrint(''' Page resource error: Code: ${error.errorCode} Description: ${error.description} For diagnosing, look at: ${error.url} '''); }, ), ) ..loadRequest(Uri.parse('https://youtube.com')); }
Future _getCookies() async { try { final cookies = await _controller.runJavaScriptReturningResult('document.cookie'); if (cookies is String) { setState(() { _cookieString = cookies; }); debugPrint("Cookies extracted:\n$_cookieString"); } } catch (e) { debugPrint("Failed to get cookies: $e"); } }
Future _searchVideos() async { if (_cookieString.isEmpty) { ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('No cookies found! Please login first.')), ); return; }
setState(() { _loadingVideos = true; _videos = []; }); // --- FIX STARTS HERE --- final client = _CookieClient(_cookieString); final ytClient = yt.YoutubeExplode(client); // This line now works correctly // --- FIX ENDS HERE --- try { final aaa = await ytClient.videos.streamsClient.getManifest("FbXOsVByKmk"); print(aaa.audio.withHighestBitrate().url); final results = await ytClient.search.search("pawan kalyan"); final limited = results; setState(() { _videos = limited; }); } catch (e) { debugPrint("Search error: $e"); ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text('Error fetching videos: ${e.toString()}')), ); } finally { setState(() { _loadingVideos = false; }); ytClient.close(); }}
it should work but cookies expire very frequently fyi
@khaled-0 but for every time I am taking cookies from it before using library.
In web view it's is saving my login. So I am opening in background and I am using the cookies before using library
@nimmalasujith is it working well ? is this method working well taking cookies and use them ?
@hanan0007 I’m not sure whether it’s actually working or not. When I pass the cookies, it doesn’t show any errors — it seems to accept them — but I can’t tell if they’re being used correctly. I’ve provided my code above in case you’d like to check it.
yes please give the code , i want to check how you inject these @nimmalasujith
My plugin omni_video_player takes care of this. It includes a fallback to YouTube embedded, which always works, so you can guarantee no service interruptions in production.
Definitely worth checking out!
Thank you for this @leonardmatasel , but actually i need the stream link , and i want to cast to the chromecast device , not to play on the mobile phone