HaarigerHarald / android-youtubeExtractor

Deprecated: Android based YouTube URL extractor and downloader
Other
878 stars 305 forks source link

LiveStream video is extracted without audio #74

Open JmyW opened 5 years ago

JmyW commented 5 years ago

Hi Since yesterday, the Live Stream video became failed. The extracted URLs in ytFiles are not including both Video and Audio. I check each ytFile through getAudioBitrate, they all are -1, means no sound. I can find one with 128kbps but its video height is -1, means no video. Does anyone know the reason? Could Harald or anyone help to analyse it? Thanks in advance.

https://www.youtube.com/watch?v=GtoIMPrppUY https://www.youtube.com/watch?v=7hbAIHIdcko https://www.youtube.com/watch?v=nmZUSI55CfA https://www.youtube.com/watch?v=kHfz5vER9jQ

kaiv2000 commented 5 years ago

Confirm this issue.

JmyW commented 5 years ago

@kaiv2000 Have you gotten the solution?

kaiv2000 commented 5 years ago

unfortunatelly not yet

jishantmed commented 5 years ago

@kaiv2000 you are using "hlsvp" to get a match live tv or not. this has been changed "hlsManifestUrl" please check .Hope it will help you

b7ca6q commented 5 years ago

Do you guys got the solution for it?

JmyW commented 5 years ago

No 😢 I have even dropped down my app in store for a while. But I'm hoping someone can help me to solve it and resume my app in store.

anirudha-banerjee commented 5 years ago

Did anyone find a solution for this?

anirudha-banerjee commented 5 years ago

Did anyone find a solution for this?

@kaiv2000 you are using "hlsvp" to get a match live tv or not. this has been changed "hlsManifestUrl" please check .Hope it will help you

Thank you. Converting the pattern from "hlsvp" to "hlsManifestUrl", work. Being able to stream youtube live streams with audio.

JmyW commented 5 years ago

@anirudha-banerjee Could you share more how to "convert" the pattern from hlsvp to hsManifestUrl? Where should be modified in code?

anirudha-banerjee commented 5 years ago

@JmyW You need to make the change in YouTubeExtractor class in youtubeExtractor module. Inside the class you will find, all the patterns that this project is using in order to extract video data. There search for "hlsvp" pattern and replace with "hlsManifestUrl(.+?)(&|\z)". If this does not work, please replace with "hlsManifestUrl%22%3A%22(.+?)(&|\z)". "%22%3A%22" means ":".

JmyW commented 5 years ago

Thanks! Yes, I'm using the youtubExtractor locally. Then I followed your string "hlsManifestUrl%22%3A%22(.+?)(&|\z)". I tested and found a few of live video can be played now but most of them are still failed. :-(
Can you share some YouTube URLs you succeeded for me to do further analysis?

[Pass] https://www.youtube.com/watch?v=4ZVUmEUFwaY

[Fail] https://www.youtube.com/watch?v=DVOHYy_m_qU https://www.youtube.com/watch?v=rQSwh3bgs5k

anirudha-banerjee commented 5 years ago

I too found that the links which were playing on my phone(android 8), were not playing on my tab(android 5). While debugging saw that, after getting hls data using "hlsManifestUrl%22%3A%22(.+?)(&|\\z)" pattern, when i call new BufferedReader(new InputStreamReader(urlConnection.getInputStream())), the code gives "FileNotFound" Exception. Now, this was happening only on my tab. Whereas, on phone any youtube live link i parse, it starts playing. So tried the following method, for the code to work on both the type of device and on all types of youtube live link(Have checked a couple of youtube live links, have shared the links below).

After you have extracted hls data using the above mentioned pattern, you will have to extract the exact url, ending in ".m3u8", from the above mentioned hls sparse meta data. Use "(.*?)^https(.*?)(?=\")" pattern to extract hls link ending in ".m3u8". After extracting the link, use that link to open connection and then get the stream.

So the code now should look like this: Also i have replaced finally with catch.

private static final Pattern patHlsManifestUrl = Pattern.compile("(.*?)^https(.*?)(?=\")");
private static final Pattern patHlsvp = Pattern.compile("hlsManifestUrl%22%3A%22(.+?)(&|\\z)");

if(videoMeta.isLiveStream()){
            mat = patHlsvp.matcher(streamMap);
            if(mat.find()) {
                String hlsvp = URLDecoder.decode(mat.group(1), "UTF-8");
                SparseArray<YtFile> ytFiles = new SparseArray<>();

                mat = patHlsManifestUrl.matcher(hlsvp);
                if (mat.find()){
                    getUrl = new URL(URLDecoder.decode(mat.group(), "UTF-8"));
                    urlConnection = (HttpURLConnection) getUrl.openConnection();
                    urlConnection.setRequestProperty("User-Agent", USER_AGENT);
                    urlConnection.connect();
                    try {
                        reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
                        String line;
                        while ((line = reader.readLine()) != null) {
                            if(line.startsWith("https://") || line.startsWith("http://")){
                                mat = patHlsItag.matcher(line);
                                if(mat.find()){
                                    int itag = Integer.parseInt(mat.group(1));
                                    YtFile newFile = new YtFile(FORMAT_MAP.get(itag), line);
                                    ytFiles.put(itag, newFile);
                                }
                            }
                        }
                    }
                    catch (FileNotFoundException ex){
                        Log.e(LOG_TAG, "Problem while extracting live url", ex);
                        if (reader != null)
                            reader.close();
                        urlConnection.disconnect();
                    }
                    if (reader != null)
                        reader.close();
                    urlConnection.disconnect();

                    if (ytFiles.size() == 0) {
                        if (LOGGING)
                            Log.d(LOG_TAG, streamMap);
                        return null;
                    }
                    return ytFiles;
                }
                return null;
            }
            return null;
        }   

Working youtube live links: NASA Live: Earth From Space - Nasa Live Stream Wheels On The Bus +More Nursery Rhymes and Kids Songs | Baby Songs By Little Baby Bum LIVE

JmyW commented 5 years ago

@anirudha-banerjee Thank you so much for your sharing. Yes, it's great! Your solution fixes it, the Live video is now able to be played. Thank you!

vivekAtHorizon commented 1 year ago

@anirudha-banerjee what are streamMap and patHlsItag or those are available only in the previous versions/code? I'm trying to add this code and it shows me an error Cannot resolve symbol... while using both of the variables.