B4A Library Library YouTube to Mp3

Hi all.

This is simple library convert YouTube to Mp3 and you have also title, description, image, channelid, channelname
Utilize service YouTubeinMp3
Is very simple:

YouTubeMp3
Author:
Devil-App
Version: 1.5
Methods:
  • IsInitialized As Boolean
    Tests whether the object has been initialized.
  • initialize (youtubelink As String, Download As Boolean, Folder As String, Module As Object, EventName As String) As String

    Code: Copy
    Sub Activity_Create(FirstTime As Boolean)
    
        Dim mp3 As youtubetomp3
        mp3.Initialize("i62Zjga8JOM", "YouTube", Me, "check_link")
    
    End Sub
    
    
    Sub check_information(valore As typeLevel)
    LogColor(valore.image, Colors.Red)
    LogColor(valore.title, Colors.Blue)
    LogColor(valore.description, Colors.Red)
    LogColor(valore.channelid, Colors.Red)
    LogColor(valore.channelname, Colors.Red)
    End Sub

    Code: Copy
    'Do you want YouTube To Mp3:
    'You have 2 parameters:
    'Initialize(idyoutube As String, Folder As String, Me, "check_information")
    'youtubelink --> "https://www.youtube.com/watch?v=i62Zjga8JOM" Is link youtube that you want --> Mp3
    'Folder --> YouTube, name Folder where you want To save the File.
    'Example:
    'Dim mp3 As youtubetomp3
    'mp3.Initialize("i62Zjga8JOM","YouTube", Me, "check_information")
    '.....
    'Sub check_information(valore As typeLevel)
    'LogColor(valore.title, Colors.Blue)
    'LogColor(valore.image, Colors.Red)
    'LogColor(valore.description, Colors.Red)
    'LogColor(valore.channelid, Colors.Red)
    'LogColor(valore.channelname, Colors.Red)
    'End Sub
    '******
    [*]

    You have this Result:

    2015-07-28 16.26.40.png


    Screenshot 2015-07-28 18.23.45.png

    LIBRARY
    - Unzip the attached file ( YouTubeMp3-Lib1.50.zip ) and copy YouTubeMp3.jar and YouTubeMp3.xml to the libraries folder
    - YouTubeToMp3-Example.zip is simple B4A
In attachment also Class: YoutubeToMp3-Class-1.50.zip
 

Attachments

Last edited:
Hi all.

This is simple library convert YouTube to Mp3
Utilize service YouTubeinMp3
Is very simple:

YouTubeMp3
Author:
Devil-App
Version: 1
Methods:
  • IsInitialized As Boolean
    Tests whether the object has been initialized.
  • initialize (youtubelink As String, Download As Boolean, Folder As String, Module As Object, EventName As String) As String

    Code: Copy
    Sub Activity_Create(FirstTime As Boolean)
    
        Dim mp3 As youtubetomp3
        mp3.Initialize("https://www.youtube.com/watch?v=i62Zjga8JOM", True, "YouTube", Me, "check_link")
    
    End Sub
    
    Sub check_link(valore As typeLevel)
    
    LogColor(valore.title, Colors.Blue)
    LogColor(valore.link, Colors.Red)
    LogColor(valore.success, Colors.Green)
    
    End Sub

    Code: Copy
    'Do you want YouTube to Mp3:
    'You have 3 parameters:
    'Initialize(youtubelink As String, Download As Boolean, Folder As String, Me, "check_short")
    'youtubelink --> "https://www.youtube.com/watch?v=i62Zjga8JOM" is link youtube that you want --> Mp3
    'Download --> True, if you want download file
    'Folder --> YouTube, name Folder where you want to save the file.
    'Example:
    'Dim mp3 As youtubetomp3
    'mp3.Initialize("https://www.youtube.com/watch?v=i62Zjga8JOM", True, "YouTube", Me, "check_short")
    '.....
    'Sub check_short(valore As typeLevel)
    'LogColor(valore.title, Colors.Blue)
    'LogColor(valore.link, Colors.Red)
    'LogColor(valore.success, Colors.Green)
    'End Sub
    '******

    You have this Result:

    View attachment 36123

    View attachment 36124

    LIBRARY
    - Unzip the attached file ( YoutubeMp3-Lib.zip ) and copy YouTubeMp3.jar and YouTubeMp3.xml to the libraries folder
    - YouTubeToMp3-Example.zip is simple B4A
Awesome, i've been working on something similar, maybe i will post it later on, basically the library i'm working on you can search for a video title name or artis, and it will return a list of videos which you can extract the video Id number from, using your library i can now convert this videos to mp3, great work.

Thanks,
Walter
 
Hi all.

This is simple library convert YouTube to Mp3
Utilize service YouTubeinMp3
Is very simple:

YouTubeMp3
Author:
Devil-App
Version: 1
Methods:
  • IsInitialized As Boolean
    Tests whether the object has been initialized.
  • initialize (youtubelink As String, Download As Boolean, Folder As String, Module As Object, EventName As String) As String

    Code: Copy
    Sub Activity_Create(FirstTime As Boolean)
    
        Dim mp3 As youtubetomp3
        mp3.Initialize("https://www.youtube.com/watch?v=i62Zjga8JOM", True, "YouTube", Me, "check_link")
    
    End Sub
    
    Sub check_link(valore As typeLevel)
    
    LogColor(valore.title, Colors.Blue)
    LogColor(valore.link, Colors.Red)
    LogColor(valore.success, Colors.Green)
    
    End Sub

    Code: Copy
    'Do you want YouTube to Mp3:
    'You have 3 parameters:
    'Initialize(youtubelink As String, Download As Boolean, Folder As String, Me, "check_short")
    'youtubelink --> "https://www.youtube.com/watch?v=i62Zjga8JOM" is link youtube that you want --> Mp3
    'Download --> True, if you want download file
    'Folder --> YouTube, name Folder where you want to save the file.
    'Example:
    'Dim mp3 As youtubetomp3
    'mp3.Initialize("https://www.youtube.com/watch?v=i62Zjga8JOM", True, "YouTube", Me, "check_short")
    '.....
    'Sub check_short(valore As typeLevel)
    'LogColor(valore.title, Colors.Blue)
    'LogColor(valore.link, Colors.Red)
    'LogColor(valore.success, Colors.Green)
    'End Sub
    '******

    You have this Result:

    View attachment 36123

    View attachment 36124

    LIBRARY
    - Unzip the attached file ( YoutubeMp3-Lib.zip ) and copy YouTubeMp3.jar and YouTubeMp3.xml to the libraries folder
    - YouTubeToMp3-Example.zip is simple B4A
I just tested your library and i'm getting the following error, any idea as to why this is, i tried it with your example and get the same error. Am I missing something?

** Activity (main) Create, isFirst = true **
main_activity_create (B4A line: 32)
mp3.Initialize("java.lang.NoSuchMethodError: No virtual method _getrequest()Lanywheresoftware/b4h/okhttp/OkHttpClientWrapper$OkHttpRequest; in class Lanywheresoftware/b4a/samples/httputils2/httpjob; or its super classes (declaration of 'anywheresoftware.b4a.samples.httputils2.httpjob' appears in /data/app/youtubemp3.example-1/base.apk)
at devil.app.shortlink.youtubetomp3._initialize(youtubetomp3.java:150)
at youtubemp3.example.main._activity_create(main.java:348)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at youtubemp3.example.main.afterFirstLayout(main.java:100)
at youtubemp3.example.main.access$100(main.java:17)
at youtubemp3.example.main$WaitForLayout.run(main.java:78)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5297)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)

Thanks,
Walter
 
I just tested your library and i'm getting the following error, any idea as to why this is, i tried it with your example and get the same error. Am I missing something?



Thanks,
Walter

Hi Walter.
The your movie give me error, anyway do you have this library:
DateUtils
DownloadManager
HTTP
HttpUtils2
OkHttp
JSON
RandomAccessFile
SQL
StringUtils
 
Hi Walter. Do you have this library:
DateUtils
DownloadManager
HTTP
HttpUtils2
OkHttp
JSON
RandomAccessFile
SQL
StringUtils
Yes I do, but you didn't specify in your first post all this libraries were needed, i was under the impression that when you compile a module into a library any libraries you use also get compiled along with the library you are creating.
Am I wrong?

Thanks,
Walter
 
Yes I do, but you didn't specify in your first post all this libraries were needed, i was under the impression that when you compile a module into a library any libraries you use also get compiled along with the library you are creating.
Am I wrong?

Thanks,
Walter

No dont wrong. But is strain that you have this error.
I dont see your movie give me error.
 
No dont wrong. But is strain that you have this error.
I dont see your movie give me error.
Ok, i have included all the libraries you mentioned in post #5, but i still get the same error!
It's a shame because i'm done writing my library and i was hoping to start making a small app where you can search for any song title using the youtube api, and using your library to convert the videos to mp3.

Let me know if you figure out why i'm seeing this issue!

Thanks,
Walter
 
Give me more information:
1. I dont see your movie
2. Do you run my example or your project ?
3. Do you have this error in debug mode (rapid or legacy ) ??
 
Give me more information:
1. I dont see your movie
2. Do you run my example or your project ?
3. Do you have this error in debug mode (rapid or legacy ) ??
I'm running your example, I tried running it in debug mode, and release mode as well, both modes give me the same issue.
don't worry about my movie, the link gets corrupted when you paste it inside the <quote></quote>.

Thanks,
Walter
 
Do you have try in different device ?
Yes i have, i tried on my samsung Tab running version 4.4.2 and my LG G3 running version 5.0.1. i get same error on both devices.

The issue is obviously at this line

"main_activity_create (B4A line: 32)"
Code: Copy
mp3.Initialize("https://www.youtube.com/watch?v=i62Zjga8JOM", True, "YouTube", Me, "check_short")

Thanks,
Walter
 
Mhhh..Ok in attachment 1# you have also class. Let me know
Ok, the problem is this line 48, If i comment this line everything works fine.

Code: Copy
job1.GetRequest.SetContentEncoding("text/plain")

this is the error i get and the application stops exactly at line 48 of your class.

Code: Copy
** Activity (main) Create, isFirst = true **
youtubetomp3_initialize (B4A line: 48)
job1.GetRequest.SetContentEncoding("text/plain")
java.lang.RuntimeException: Only Post / Put requests support this method.
    at anywheresoftware.b4a.http.HttpClientWrapper$HttpUriRequestWrapper.SetContentEncoding(HttpClientWrapper.java:435)
    at youtubemp3.example.youtubetomp3._initialize(youtubetomp3.java:197)
    at youtubemp3.example.main._activity_create(main.java:347)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
    at youtubemp3.example.main.afterFirstLayout(main.java:100)
    at youtubemp3.example.main.access$100(main.java:17)
    at youtubemp3.example.main$WaitForLayout.run(main.java:78)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:146)
    at android.app.ActivityThread.main(ActivityThread.java:5602)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
    at dalvik.system.NativeStart.main(Native Method)
sending message to waiting queue of uninitialized activity (submitjob)

Thanks,
Walter
 
One more issue i just noticed, now that everything is working fine, i noticed that even though the response from the server says that the mp3 file was successfully downloaded, for some reason when i go to the Youtube_Mp3 folder the mp3 file does not appear to be inside that folder, it might me an issue with Lollipop version, i do not see this issue on my samsung galaxy tab 7, any ideas what could be going on?

Thanks,
Walter
 
One more issue i just noticed, now that everything is working fine, i noticed that even though the response from the server says that the mp3 file was successfully downloaded, for some reason when i go to the Youtube_Mp3 folder the mp3 file does not appear to be inside that folder, it might me an issue with Lollipop version, i do not see this issue on my samsung galaxy tab 7, any ideas what could be going on?

Thanks,
Walter
I dont know Walter i havent Lollipop version. Sorry
 
I dont know Walter i havent Lollipop version. Sorry

Ok, i made some modifications to your class, i found the following issues:

#1 You need to create the directory where the mp3 will be downloaded to, this was the reason why your example would fail in my LG-G3 running lollipop version.
I added the following code for that:
Code: Copy
    If File.IsDirectory(File.DirRootExternal, Folder) = False Then
    Log("creating directory: " & Folder)
        File.MakeDir(File.DirRootExternal, Folder)
    Else
    Log("Folder already exists!")
    End If
#2 You need to register the DownloadManager, otherwise the DownloadComplete Sub will never be raised.
I added the following code for that
Code: Copy
DownloadManager1.RegisterReceiver("DownloadManager1")
#3 You are using a Utils module, which was never initialized.
I added the following code for that
Code: Copy
    If Utils.IsInitialized=False Then
        Utils.Initialize(DownloadManager1)
    End If
#4 I noticed that when you are using a secured network, the requests don't work, and I also unencoded the URL retrieved.
using the following code:
Code: Copy
 Dim su As StringUtils
 DOWNLOAD_ADDRESS =valore.link.Replace("http", "https")
 DOWNLOAD_ADDRESS = su.DecodeUrl(DOWNLOAD_ADDRESS, "UTF-8")
#5 and lastly, I moved this code:
Code: Copy
CallSub2(MN,EN,valore)
to the Private Sub DownloadManager1_DownloadComplete(DownloadId1 As Long) sub
you had it at the JobDone sub which was not realistic, as the true completion of the download is at the DownloadManager1_Downloadcomplete sub.

i'm attaching the revised version of your class, you should recompile with a new version and repost it.

Cheers,
Walter
 

Attachments

Ok, i made some modifications to your class, i found the following issues:

#1 You need to create the directory where the mp3 will be downloaded to, this was the reason why your example would fail in my LG-G3 running lollipop version.
I added the following code for that:
Code: Copy
    If File.IsDirectory(File.DirRootExternal, Folder) = False Then
    Log("creating directory: " & Folder)
        File.MakeDir(File.DirRootExternal, Folder)
    Else
    Log("Folder already exists!")
    End If
#2 You need to register the DownloadManager, otherwise the DownloadComplete Sub will never be raised.
I added the following code for that
Code: Copy
DownloadManager1.RegisterReceiver("DownloadManager1")
#3 You are using a Utils module, which was never initialized.
I added the following code for that
Code: Copy
    If Utils.IsInitialized=False Then
        Utils.Initialize(DownloadManager1)
    End If
#4 I noticed that when you are using a secured network, the requests don't work, and I also unencoded the URL retrieved.
using the following code:
Code: Copy
Dim su As StringUtils
DOWNLOAD_ADDRESS =valore.link.Replace("http", "https")
DOWNLOAD_ADDRESS = su.DecodeUrl(DOWNLOAD_ADDRESS, "UTF-8")
#5 and lastly, I moved this code:
Code: Copy
CallSub2(MN,EN,valore)
to the Private Sub DownloadManager1_DownloadComplete(DownloadId1 As Long) sub
you had it at the JobDone sub which was not realistic, as the true completion of the download is at the DownloadManager1_Downloadcomplete sub.

i'm attaching the revised version of your class, you should recompile with a new version and repost it.

Cheers,
Walter

Good Job Walter.
welcome ;)
 
Back
Top