write a java code that read a url and extract all streams even though if they are not shown as m3u8 or so. for example playeed by jwplayer. from sites such as https://thetvapp.to/tv/tlc-live-stream/
Assistant
User
write a java code for android (using android studio) that read a url and extract all streams even though if they are not shown as m3u8 or so. for example playeed by jwplayer. from sites such as https://thetvapp.to/tv/tlc-live-stream/
Extracting video stream URLs (including HLS streams like m3u8 or others) embedded in a website like https://thetvapp.to/tv/tlc-live-stream/ can be quite challenging because:
The stream URLs often aren't exposed directly in the static HTML.
They can be embedded dynamically via JavaScript.
They can be obfuscated or protected with encryption.
Players such as JW Player may load streams dynamically after page load.
Approach Overview
To reliably extract stream URLs from pages with dynamic content, a headless browser (e.g. Selenium, Playwright) is generally required because simply fetching the static HTML with Java alone will often not suffice.
Once the page is rendered, the code can look for:
<video> tags and their sources
JW Player setup scripts or JSON data that specify stream URLs
Network requests for .m3u8, .mpd or other media manifests
Constraints
Pure Java standard HTTP clients cannot execute JavaScript, so they won't be sufficient.
A Java tool like Selenium WebDriver paired with a headless browser (ChromeDriver or Firefox Geckodriver) can render the page and allow us to parse dynamic content.
Optionally, intercept network requests to catch manifest URLs.
1) Using Selenium WebDriver to parse the page and extract streams
This example:
Loads the specified URL in headless Chrome
Waits for the page to load completely
Extracts all video-related URLs from the page
Attempts to parse JW Player configuration if present
ChromeDriver binary must be available and compatible with your Chrome version.
java
Notes:
Selenium WebDriver is a powerful tool enabling browser automation and JS execution.
We wait for 5 seconds after page load to allow JS-driven content to populate.
The regex searches for .m3u8 URLs inside script tags (often streaming manifests).
You can explore network requests via Chrome's DevTools Protocol (CDP) for more advanced extraction, but this requires more complex integration.
Some sites protect streams heavily via DRM or encrypted players — such streams may be impossible to retrieve by URL alone.
If ChromeDriver is not set in your environment PATH, specify its exact location with System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver").
You may tweak or extend the regex to capture other stream formats (e.g. .mp4, .mpd for DASH).
This solution should help you programmatically extract most embedded streams even if they are dynamically loaded or not obvious in the initial HTML markup.
Reading a webpage in Android and extracting dynamically loaded streams (like JW Player streams) is quite challenging because:
Android apps cannot easily run complex JavaScript that web players use.
Android's built-in WebView or HTTP clients fetch static HTML only.
Stream URLs are often embedded via JavaScript, loaded dynamically, or obfuscated.
What can we do on Android?
Load the page in a WebView with JavaScript enabled
Then, inject JavaScript to extract the stream URLs from the page's DOM or player objects.
Intercept network requests in the WebView
Monitor all network requests made—many streams load manifest URLs dynamically, and intercepting these network calls might reveal the streams.
Limitations
Android's WebView doesn't have built-in APIs for full request interception like desktop browsers do.
We can use WebViewClient.shouldInterceptRequest() to intercept resource loads.
JW Player often loads streams via AJAX or XHR requests—these requests manifest there.
You won't get all streams if they require authentication, encryption, or DRM.
Here is an approach:
Use a WebView to load the page.
Implement a WebViewClient overriding shouldInterceptRequest() to capture URLs loaded in the page.
Inject JavaScript to scan the page for common stream URLs (e.g. .m3u8, .mp4).
Print all detected URLs.
Step-by-step example:
Create an Activity with a fullscreen WebView.
Enable JavaScript.
Implement interception of requests.
Inject JavaScript after the page loads to detect any player data in JS (e.g. JSON objects with streams).
Android Java code example (simplified)
java
package com.example.streamextractor;
import android.annotation.SuppressLint;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.webkit.JavascriptInterface;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import java.util.HashSet;
import java.util.Set;
public class MainActivity extends AppCompatActivity {
private static final String TAG = "StreamExtractor";
private WebView webView;
// Keep detected streams here (thread safety not considered for brevity)
private Set<String> detectedStreams = new HashSet<>();
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create WebView programmatically or via layout
webView = new WebView(this);
setContentView(webView);
// Enable JavaScript
webView.getSettings().setJavaScriptEnabled(true);
// Add JS interface to receive messages from JS
webView.addJavascriptInterface(new StreamJavaScriptInterface(), "AndroidStreamExtractor");
// Set a custom WebViewClient to intercept requests and monitor loading
webView.setWebViewClient(new CustomWebViewClient());
// Load target URL
webView.loadUrl("https://thetvapp.to/tv/tlc-live-stream/");
}
private class CustomWebViewClient extends WebViewClient {
// Intercept resource requests to capture stream URLs
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
String url = request.getUrl().toString();
// Check if URL looks like a stream URL
if (isStreamUrl(url)) {
if (detectedStreams.add(url)) {
Log.i(TAG, "Stream URL intercepted: " + url);
}
}
return super.shouldInterceptRequest(view, request);
}
// After page finishes loading, inject JS to scrape the DOM for streams
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
// Run injected JavaScript to detect possible stream URLs embedded in page or JW Player config
injectJavaScriptToExtractStreams();
}
}
// Check if a URL looks like a video stream
private boolean isStreamUrl(String url) {
url = url.toLowerCase();
return url.endsWith(".m3u8") ||
url.endsWith(".mp4") ||
url.endsWith(".mpd") ||
url.contains("manifest") ||
url.contains("stream");
}
// Inject JavaScript to find streams inside the DOM or JW Player configs
private void injectJavaScriptToExtractStreams() {
// This JS scans <video> tags + <source> sources + looks for m3u8 or mp4 links in scripts or JW Player config objects
String jsCode = "javascript:(function() {" +
" var found = [];" +
" // Find all <video> and <source> elements with streaming URLs" +
" var sources = Array.from(document.querySelectorAll('video source'));" +
" sources.forEach(function(s) { if(s.src) found.push(s.src); });" +
" var videos = Array.from(document.querySelectorAll('video'));" +
" videos.forEach(function(v) { if(v.src) found.push(v.src); });" +
" // Search script tags for m3u8 urls" +
" var scripts = Array.from(document.getElementsByTagName('script'));" +
" var regex = /https?:\\/\\/[^\\s\"']+\\.m3u8/g;" +
" scripts.forEach(function(script) {" +
" var text = script.innerText;" +
" if(text) {" +
" var matches = text.match(regex);" +
" if(matches) found = found.concat(matches);" +
" }" +
" });" +
" // Also check known JWPlayer global config (if loaded)" +
" try {" +
" if(window.jwplayer) {" +
" var player = jwplayer();" +
" if(player && player.getPlaylist) {" +
" var playlist = player.getPlaylist();" +
" playlist.forEach(function(item) {" +
" if(item.file) found.push(item.file);" +
" if(item.sources) {" +
" item.sources.forEach(function(source) { found.push(source.file); });" +
" }" +
" });" +
" }" +
" }" +
" } catch(e) {}" +
" // Remove duplicates" +
" var uniq = Array.from(new Set(found));" +
" // Send the detected URLs back to Android" +
" uniq.forEach(function(url) {" +
" window.AndroidStreamExtractor.onStreamFound(url);" +
" });" +
"})()";
webView.evaluateJavascript(jsCode, null);
}
// JavaScript interface to receive stream URLs discovered by JS injection
private class StreamJavaScriptInterface {
@JavascriptInterface
public void onStreamFound(String url) {
if (url != null && !url.isEmpty()) {
if (detectedStreams.add(url)) {
Log.i(TAG, "Stream URL extracted via JS injection: " + url);
}
}
}
}
}
Explanation:
This code loads the URL in a WebView.
shouldInterceptRequest() inspects all network requests and logs URLs that look like media streams.
After the page loads, the app injects JavaScript that searches the DOM, <video> and <source> tags, and scripts for .m3u8 URLs or those inside JW Player's playlist.
The JavaScript then calls back to Android via a JavascriptInterface to report streams found.
All discovered URLs are logged, and you can further process or display these to the user.
Use a full browser engine or a backend service that runs headless Chrome for better JS execution and network inspection if streams are not detected reliably.
Conclusion
This is about as good as it gets purely in Android Java in-app without running your own proxy or headless browser outside.
Due to page complexity and streaming protection, some streams might still not be detected.
If you want more reliable and complex scraping, consider:
A server-side scraper using headless Chrome (e.g., Puppeteer) and returning results to your app.
Or dedicated stream-finding libraries for Android.
If you want help building those, just ask!
Thanks for the feedback. The site https://thetvapp.to/tv/tlc-live-stream/ is complex: it loads content dynamically and heavily uses JavaScript, including player setup and streams accessed through obfuscated scripts. Extracting streams reliably from such sites on Android with just WebView and JavaScript injection is tricky.
Why it is still hard to get the streams?
The streams may be loaded via XHR/fetch requests or WebSocket.
JW Player or another player may initialize asynchronously.
Streams may be embedded inside complex JSON or JS variables loaded after multiple deferred script executions.
shouldInterceptRequest only captures top-level and subresource HTTP(S) requests but may miss chained or native (media codec) requests.
Android WebView is limited in network interception compared to desktop DevTools.