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

    B4X:
    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

    B4X:
    '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

  • YouTubeMp3-Lib1.50.zip
    7.7 KB · Views: 536
  • YouTubeToMp3-Example.zip
    9.1 KB · Views: 551
  • YoutubeToMp3-Class-1.50.zip
    11.5 KB · Views: 547
Last edited:

MarcoRome

Expert
Licensed User
Longtime User
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:
B4X:
    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
B4X:
DownloadManager1.RegisterReceiver("DownloadManager1")
#3 You are using a Utils module, which was never initialized.
I added the following code for that
B4X:
    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:
B4X:
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:
B4X:
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

Post #1 Update Library 1.02 also with the contribution of walter.
 

wonder

Expert
Licensed User
Longtime User
Yeah, all people know this. And so I do not think anyone uses this library to an application present on Play store.
Too bad Google is so strict, this is really a great addition to B4A. :)
 

walterf25

Expert
Licensed User
Longtime User
Congratulations on your work, @MarcoRome!! :D

This kind of app, however, would be banned from Google Play, right?
There are tons of apps in the google play store like this, there are always ways of going around so they won't get banned, for one you are not hosting the content that people download, your app will simply be a tool for people to search for titles, what people do with the content is up to them.

Cheers,
Walter
 

walterf25

Expert
Licensed User
Longtime User
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

    B4X:
    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

    B4X:
    '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-Lib1.02.zip ) and copy YouTubeMp3.jar and YouTubeMp3.xml to the libraries folder
    - YouTubeToMp3-Example.zip is simple B4A
CLASS
youtubetomp3-Class1.02.zip
Library request:
DateUtils
DownloadManager
HTTP
HttpUtils2
OkHttp
JSON
RandomAccessFile
SQL
StringUtils

UPDATE 1.02 ALSO WITH CONTRIBUTE WALTER
Hi MarcoRome, i just checked and it seems that the service you are using to convert the videos to mp3s has changed, for some reason they do not return the Json string with the title, file lenght, etc... what they do now is that the file downloads directly without returning any other information. What a Bummer, i was almost done with my App and now i have to change everything around again, I hate it when they do that, oh Well......
Just thought I'd let you know in case anyone else tries to use your library it won't work anymore.
 

MarcoRome

Expert
Licensed User
Longtime User
Hi MarcoRome, i just checked and it seems that the service you are using to convert the videos to mp3s has changed, for some reason they do not return the Json string with the title, file lenght, etc... what they do now is that the file downloads directly without returning any other information. What a Bummer, i was almost done with my App and now i have to change everything around again, I hate it when they do that, oh Well......
Just thought I'd let you know in case anyone else tries to use your library it won't work anymore.
Hi Walter, I will look tonight and let you know.
 

MarcoRome

Expert
Licensed User
Longtime User
Hi MarcoRome, i just checked and it seems that the service you are using to convert the videos to mp3s has changed, for some reason they do not return the Json string with the title, file lenght, etc... what they do now is that the file downloads directly without returning any other information. What a Bummer, i was almost done with my App and now i have to change everything around again, I hate it when they do that, oh Well......
Just thought I'd let you know in case anyone else tries to use your library it won't work anymore.

Ok Update Library Rel. 1.50 see 1# Post
 

walterf25

Expert
Licensed User
Longtime User
Ok Update Library Rel. 1.50 see 1# Post
Thanks, but what is the difference, what did you change, did you notice that the api does not return the JSON response anymore, how did you solve this?

Regards,
Walter
 

MarcoRome

Expert
Licensed User
Longtime User

walterf25

Expert
Licensed User
Longtime User

MarcoRome

Expert
Licensed User
Longtime User
Bummer, and yeah that's what i'm using right now to retrieve the video information.

Any idea why they changed the API?

Thanks,
Walter
No i dont know. But the important thing is to have solved the problem ;)
 

tuhatinhvn

Active Member
Licensed User
Longtime User
There are tons of apps in the google play store like this, there are always ways of going around so they won't get banned, for one you are not hosting the content that people download, your app will simply be a tool for people to search for titles, what people do with the content is up to them.

Cheers,
Walter
can you give an example????
 

Douglas Farias

Expert
Licensed User
Longtime User
I see a lot of apps with download, but dont give the file, the users need open the app to listen the music, i dont know if this will cause ban
 

MarcoRome

Expert
Licensed User
Longtime User
I see a lot of apps with download, but dont give the file, the users need open the app to listen the music, i dont know if this will cause ban
We know that play store is very limited on a few things, so it is still better to be careful before publishing something
 

Gonza8

Member
Licensed User
Longtime User
Hello, i try the library and example but the mp3 is only 200 bytes long. I don't know where is the problem.

Thanks
 
Top