HaarigerHarald/android-youtubeExtractor

ytFiles Are Always Returning as null. What am I doing wrong?

Mathias8405 opened this issue · 27 comments

I am trying to add this to my Android application written in Kotlin. I am using valid YouTube urls, and I've tried several different valid iTags all of which returns null. It can't find any files to download. Is it my code or is this a library issue? I've been trying to figure this out for hours. I appreciate all the help that I can get with this! Thanks in advance!

Here is my function code:

@SuppressLint("StaticFieldLeak")
 private fun ytDownload(context: Context, iTag: Int, downloadTitle: String, downloadDescription: String, downloadFileName: String, youTubeUrl: String) {
        val youTubeExtractor = object : YouTubeExtractor(context) {
            override fun onExtractionComplete(ytFiles: SparseArray<YtFile>?, videoMeta: VideoMeta?) {
                try {
                    if (ytFiles != null) {
                        val yFile = ytFiles.get(iTag)
                        if (yFile != null) {
                            val streamUrl = yFile.url
                            val request = DownloadManager.Request(Uri.parse(streamUrl))
                            request.setTitle(downloadTitle)
                            request.setDescription(downloadDescription)

                            val file = File(
                                Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
                                downloadFileName
                            )
                            request.setDestinationUri(Uri.fromFile(file))

                            val downloadManager =
                                context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
                            downloadManager.enqueue(request)
                        } else {
                            Toast.makeText(context, "Download Failed! Selected iTag not available.", Toast.LENGTH_SHORT).show()
                        }
                    } else {
                        Toast.makeText(context, "Download Failed! No available video streams.", Toast.LENGTH_SHORT).show()
                    }
                } catch (e: Exception) {
                    Toast.makeText(context, "Error: ${e.message}", Toast.LENGTH_LONG).show()
                }
            }
        }
        youTubeExtractor.extract(youTubeUrl, true, true)
    }

Here is the dependency I am using

 `implementation 'com.github.HaarigerHarald:android-youtubeExtractor:v2.1.0`

Here is my Manifest

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Instance
ytDownload(applicationContext, 18, "YouTube Downloader", "Downloading Video...", "VideoFile.mp4", videoUrlET.text.toString())

Logcat Error
W/System.err: java.io.FileNotFoundException: https://www.youtube.com/get_video_info?video_id=imjM7MuBrMs&eurl=https%3A%2F%2Fyoutube.googleapis.com%2Fv%2FimjM7MuBrMs

This library has been deprecated for quite some time and is no longer supported.

Currently only this paid library is working fine
https://github.com/Rider02vn/Youtube-Extractor

@Mathias8405
It seems that recently a change in the youtube share url has appeared.
You must therefore make this modification to the URL of the share:

if (YTsharedUrl.contains("watch?v=watch?v=")){
       YTsharedUrl= YTsharedUrl.replace("watch?v=watch?v=","watch?v=");
}

Paid library posted by @cryinrain69 "https://github.com/Rider02vn/Youtube-Extractor" is a scam!!

@Mathias8405
" implementation 'com.github.HaarigerHarald:android-youtubeExtractor:v2.1.0"
This library does not work for me!
And the master-SNAPSHOT is no longer accessible.
You must therefore copy the classes from the source code into a package directory of your project.
Then add this dependency to your build.gradle:
"implementation('com.github.evgenyneu:js-evaluator-for-android:v4.0.0') {
exclude module: 'appcompat-v7'
}"

And enjoy!

@Mathias8405 " implementation 'com.github.HaarigerHarald:android-youtubeExtractor:v2.1.0" This library does not work for me! And the master-SNAPSHOT is no longer accessible. You must therefore copy the classes from the source code into a package directory of your project. Then add this dependency to your build.gradle: "implementation('com.github.evgenyneu:js-evaluator-for-android:v4.0.0') { exclude module: 'appcompat-v7' }"

And enjoy!

Thanks! If I need any additional help, I will let you know.

@Mathias8405 " implementation 'com.github.HaarigerHarald:android-youtubeExtractor:v2.1.0" This library does not work for me! And the master-SNAPSHOT is no longer accessible. You must therefore copy the classes from the source code into a package directory of your project. Then add this dependency to your build.gradle: "implementation('com.github.evgenyneu:js-evaluator-for-android:v4.0.0') { exclude module: 'appcompat-v7' }"

And enjoy!

I am not sure what I am doing wrong, but I created a project with just this on it. If you wouldn't mind downloading the file to see what's wrong, I would greatly appreciate it! Thanks!

https://file.io/oZq7uQSAHMaV

I failed to compile the code (gradle version).
So I removed the 2.1.0 dependency from your build.gradle then added js-evaluator-for-android.
I created a youtubeextractor directory in your project with the necessary source code classes.
There may still be imports to modify in the code...
For me I don't use booleans from the extract method.
If I understood correctly, you enter in an editText the youtube share url?
Check that it is in the form "https://www.youtube.com/watch?v=FzWGvx1pmFA&feature=share"
For me this implementation should work:
https://drive.google.com/file/d/13nMDvxyrMlyLxmsfHtoWOlUG3fr24kQO/view?usp=sharing

I failed to compile the code (gradle version). So I removed the 2.1.0 dependency from your build.gradle then added js-evaluator-for-android. I created a youtubeextractor directory in your project with the necessary source code classes. There may still be imports to modify in the code... For me I don't use booleans from the extract method. If I understood correctly, you enter in an editText the youtube share url? Check that it is in the form "https://www.youtube.com/watch?v=FzWGvx1pmFA&feature=share" For me this implementation should work: https://drive.google.com/file/d/13nMDvxyrMlyLxmsfHtoWOlUG3fr24kQO/view?usp=sharing

Thanks!

I failed to compile the code (gradle version). So I removed the 2.1.0 dependency from your build.gradle then added js-evaluator-for-android. I created a youtubeextractor directory in your project with the necessary source code classes. There may still be imports to modify in the code... For me I don't use booleans from the extract method. If I understood correctly, you enter in an editText the youtube share url? Check that it is in the form "https://www.youtube.com/watch?v=FzWGvx1pmFA&feature=share" For me this implementation should work: https://drive.google.com/file/d/13nMDvxyrMlyLxmsfHtoWOlUG3fr24kQO/view?usp=sharing

Thanks!

Does the extractor work?

I failed to compile the code (gradle version). So I removed the 2.1.0 dependency from your build.gradle then added js-evaluator-for-android. I created a youtubeextractor directory in your project with the necessary source code classes. There may still be imports to modify in the code... For me I don't use booleans from the extract method. If I understood correctly, you enter in an editText the youtube share url? Check that it is in the form "https://www.youtube.com/watch?v=FzWGvx1pmFA&feature=share" For me this implementation should work: https://drive.google.com/file/d/13nMDvxyrMlyLxmsfHtoWOlUG3fr24kQO/view?usp=sharing

Thanks!

Does the extractor work?

I was busy yesterday. I was just able to look at it. I converted all the codes over to Kotlin from Java. I am having issues with the YouTubeUriExtractor class. I have some errors in there that I am not sure how to fix. Everything else looks good. Want to see if you can fix that class? I appreciate it!

https://file.io/r0TXZzirsNlx

https://file.io/r0TXZzirsNlx

Your link to download the project archive does not work.
You can perfectly coexist in your project classes in Java and in Kotlin, and call the Java classes from your code in Kotlin. That's what you were doing by implementing the 2.1.0 dependency.
There is no need to convert to Kotlin.
The YouTubeUriExtractor class is not used, so you can remove it.

https://file.io/r0TXZzirsNlx

Your link to download the project archive does not work. You can perfectly coexist in your project classes in Java and in Kotlin, and call the Java classes from your code in Kotlin. That's what you were doing by implementing the 2.1.0 dependency. There is no need to convert to Kotlin. The YouTubeUriExtractor class is not used, so you can remove it.

Thanks. But I still don't understand. I am much more confused now. If I delete the Extractor class, what instance do I call in the MainActivity class for download manager to download the link? This is what I am not understanding.

https://file.io/r0TXZzirsNlx

Your link to download the project archive does not work. You can perfectly coexist in your project classes in Java and in Kotlin, and call the Java classes from your code in Kotlin. That's what you were doing by implementing the 2.1.0 dependency. There is no need to convert to Kotlin. The YouTubeUriExtractor class is not used, so you can remove it.

`binding.downloadBtn.setOnClickListener {
val getYTUrl: String = binding.ytUrlET.text.toString()
val getTagId: Int = binding.tagET.text.toString().toInt()

        val fileNameET = EditText(this)
        fileNameET.gravity = Gravity.CENTER
        fileNameET.inputType = InputType.TYPE_CLASS_TEXT
        fileNameET.setText(R.string.default_file_name)

        AlertDialog.Builder(this)
            .setIcon(R.drawable.baseline_edit_24)
            .setTitle("Name Your File")
            .setPositiveButton("OK"){dialog, _ ->
                val getFileName: String = fileNameET.text.toString()

                if (getFileName.isNotEmpty()) { // What replaces this?
                    //ytDownload(this, getTagId,
                    //"YouTube Downloader",
                        //"Downloading Content...",
                        //getFileName, getYTUrl)
                }

                dialog.dismiss()
            }
            .setNegativeButton("Cancel", null)
            .setView(fileNameET)
            .create()
            .show()
    }
}`

YouTubeUriExtractor

The class you are using in your MainActivity is YouTubeExtractor not YouTubeUriExtractor

Here you use this class:

private fun ytDownload(context: Context, iTag: Int, downloadTitle: String, downloadDescription: String, downloadFileName: String, youTubeUrl: String) {
        val youTubeExtractor = object : YouTubeExtractor(context) {.....
       }
}````

https://file.io/r0TXZzirsNlx

Your link to download the project archive does not work. You can perfectly coexist in your project classes in Java and in Kotlin, and call the Java classes from your code in Kotlin. That's what you were doing by implementing the 2.1.0 dependency. There is no need to convert to Kotlin. The YouTubeUriExtractor class is not used, so you can remove it.

`binding.downloadBtn.setOnClickListener { val getYTUrl: String = binding.ytUrlET.text.toString() val getTagId: Int = binding.tagET.text.toString().toInt()

        val fileNameET = EditText(this)
        fileNameET.gravity = Gravity.CENTER
        fileNameET.inputType = InputType.TYPE_CLASS_TEXT
        fileNameET.setText(R.string.default_file_name)

        AlertDialog.Builder(this)
            .setIcon(R.drawable.baseline_edit_24)
            .setTitle("Name Your File")
            .setPositiveButton("OK"){dialog, _ ->
                val getFileName: String = fileNameET.text.toString()

                if (getFileName.isNotEmpty()) { // What replaces this?
                    //ytDownload(this, getTagId,
                    //"YouTube Downloader",
                        //"Downloading Content...",
                        //getFileName, getYTUrl)
                }

                dialog.dismiss()
            }
            .setNegativeButton("Cancel", null)
            .setView(fileNameET)
            .create()
            .show()
    }
}`
if (getFileName.isNotEmpty()) {
                        ytDownload(this, getTagId,
                        "YouTube Downloader",
                            "Downloading Content...",
                            getFileName, getYTUrl)
                    }

This code is correct.

https://file.io/r0TXZzirsNlx

Your link to download the project archive does not work. You can perfectly coexist in your project classes in Java and in Kotlin, and call the Java classes from your code in Kotlin. That's what you were doing by implementing the 2.1.0 dependency. There is no need to convert to Kotlin. The YouTubeUriExtractor class is not used, so you can remove it.

`binding.downloadBtn.setOnClickListener { val getYTUrl: String = binding.ytUrlET.text.toString() val getTagId: Int = binding.tagET.text.toString().toInt()

        val fileNameET = EditText(this)
        fileNameET.gravity = Gravity.CENTER
        fileNameET.inputType = InputType.TYPE_CLASS_TEXT
        fileNameET.setText(R.string.default_file_name)

        AlertDialog.Builder(this)
            .setIcon(R.drawable.baseline_edit_24)
            .setTitle("Name Your File")
            .setPositiveButton("OK"){dialog, _ ->
                val getFileName: String = fileNameET.text.toString()

                if (getFileName.isNotEmpty()) { // What replaces this?
                    //ytDownload(this, getTagId,
                    //"YouTube Downloader",
                        //"Downloading Content...",
                        //getFileName, getYTUrl)
                }

                dialog.dismiss()
            }
            .setNegativeButton("Cancel", null)
            .setView(fileNameET)
            .create()
            .show()
    }
}`
if (getFileName.isNotEmpty()) {
                        ytDownload(this, getTagId,
                        "YouTube Downloader",
                            "Downloading Content...",
                            getFileName, getYTUrl)
                    }

This code is correct.

I am doing what you are saying, but it's not working for me. Nevermind. I appreciate your time helping me. I'll just use a website for downloading.

What

 youTubeUrl

What's not working?
Is YtFiles null?
Did you provide youTubeUrl in this form: "https://youtube.com/watch?v=t_8VOPR5zxo&feature=share"? (where t_8VOPR5zxo is the id of the video)
What itag did you test with? (try with 140)

What

 youTubeUrl

What's not working? Is YtFiles null? Did you provide youTubeUrl in this form: "https://youtube.com/watch?v=t_8VOPR5zxo&feature=share"? (where t_8VOPR5zxo is the id of the video) What itag did you test with? (try with 140)

Am I on the right track? Where does the youtubeurl go?

https://file.io/bla9MnkLNkZG

What

 youTubeUrl

What's not working? Is YtFiles null? Did you provide youTubeUrl in this form: "https://youtube.com/watch?v=t_8VOPR5zxo&feature=share"? (where t_8VOPR5zxo is the id of the video) What itag did you test with? (try with 140)

At this point, I am done trying because I can't get this setup correctly. So, unless you do it all, and get it working, and send the whole project back to me, I give up. Send the working project to rockdrummer84@gmail.com if you decide to do that. If not, that's cool. If you do, that's awesome, and I appreciate it. For now, I am closing this as unresolved.

What

 youTubeUrl

What's not working? Is YtFiles null? Did you provide youTubeUrl in this form: "https://youtube.com/watch?v=t_8VOPR5zxo&feature=share"? (where t_8VOPR5zxo is the id of the video) What itag did you test with? (try with 140)

At this point, I am done trying because I can't get this setup correctly. So, unless you do it all, and get it working, and send the whole project back to me, I give up. Send the working project to rockdrummer84@gmail.com if you decide to do that. If not, that's cool. If you do, that's awesome, and I appreciate it. For now, I am closing this as unresolved.

I quickly realized a project in java. It will suffice to convert MainActivity to Kotlin.

1- open the Youtube app and choose a video.
2- share and copy the share link.
3 - paste the link in the editText of the app and press download.

I configured the code with itag 140 to retrieve only the sound. The list of possible iTags is in the YouTubeExtractor class.

I attach the project and the apk to test:
https://drive.google.com/file/d/1IiZ5zjD-k-cTsbNxRTgpDi7hMr9o4vcT/view?usp=sharing (project)
https://drive.google.com/file/d/1_ZjZph_6KXLhU2zphy833E8Hv1jNEjXv/view?usp=sharing (apk)

What

 youTubeUrl

What's not working? Is YtFiles null? Did you provide youTubeUrl in this form: "https://youtube.com/watch?v=t_8VOPR5zxo&feature=share"? (where t_8VOPR5zxo is the id of the video) What itag did you test with? (try with 140)

At this point, I am done trying because I can't get this setup correctly. So, unless you do it all, and get it working, and send the whole project back to me, I give up. Send the working project to rockdrummer84@gmail.com if you decide to do that. If not, that's cool. If you do, that's awesome, and I appreciate it. For now, I am closing this as unresolved.

I quickly realized a project in java. It will suffice to convert MainActivity to Kotlin.

1- open the Youtube app and choose a video. 2- share and copy the share link. 3 - paste the link in the editText of the app and press download.

I configured the code with itag 140 to retrieve only the sound. The list of possible iTags is in the YouTubeExtractor class.

I attach the project and the apk to test: https://drive.google.com/file/d/1IiZ5zjD-k-cTsbNxRTgpDi7hMr9o4vcT/view?usp=sharing (project) https://drive.google.com/file/d/1_ZjZph_6KXLhU2zphy833E8Hv1jNEjXv/view?usp=sharing (apk)

Thanks! I will take a look at this later. I will get back with you. Thanks again!

What

 youTubeUrl

What's not working? Is YtFiles null? Did you provide youTubeUrl in this form: "https://youtube.com/watch?v=t_8VOPR5zxo&feature=share"? (where t_8VOPR5zxo is the id of the video) What itag did you test with? (try with 140)

At this point, I am done trying because I can't get this setup correctly. So, unless you do it all, and get it working, and send the whole project back to me, I give up. Send the working project to rockdrummer84@gmail.com if you decide to do that. If not, that's cool. If you do, that's awesome, and I appreciate it. For now, I am closing this as unresolved.

I quickly realized a project in java. It will suffice to convert MainActivity to Kotlin.

1- open the Youtube app and choose a video. 2- share and copy the share link. 3 - paste the link in the editText of the app and press download.

I configured the code with itag 140 to retrieve only the sound. The list of possible iTags is in the YouTubeExtractor class.

I attach the project and the apk to test: https://drive.google.com/file/d/1IiZ5zjD-k-cTsbNxRTgpDi7hMr9o4vcT/view?usp=sharing (project) https://drive.google.com/file/d/1_ZjZph_6KXLhU2zphy833E8Hv1jNEjXv/view?usp=sharing (apk)

This works great! Thanks so much!

What

 youTubeUrl

What's not working? Is YtFiles null? Did you provide youTubeUrl in this form: "https://youtube.com/watch?v=t_8VOPR5zxo&feature=share"? (where t_8VOPR5zxo is the id of the video) What itag did you test with? (try with 140)

At this point, I am done trying because I can't get this setup correctly. So, unless you do it all, and get it working, and send the whole project back to me, I give up. Send the working project to rockdrummer84@gmail.com if you decide to do that. If not, that's cool. If you do, that's awesome, and I appreciate it. For now, I am closing this as unresolved.

I quickly realized a project in java. It will suffice to convert MainActivity to Kotlin.

1- open the Youtube app and choose a video. 2- share and copy the share link. 3 - paste the link in the editText of the app and press download.

I configured the code with itag 140 to retrieve only the sound. The list of possible iTags is in the YouTubeExtractor class.

I attach the project and the apk to test: https://drive.google.com/file/d/1IiZ5zjD-k-cTsbNxRTgpDi7hMr9o4vcT/view?usp=sharing (project) https://drive.google.com/file/d/1_ZjZph_6KXLhU2zphy833E8Hv1jNEjXv/view?usp=sharing (apk)

Let's stay in touch if changes are made in the future. Do you have discord or any other social media platform that you prefer that we can stay connected on?

yep!
My discord is aristide131.

yep! My discord is aristide131.

Awesome thanks!