B4A Library Library YouTube to Mp3

Discussion in 'Additional libraries, classes and official updates' started by MarcoRome, Jul 22, 2015.

  1. MarcoRome

    MarcoRome Expert Licensed User

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

    Attached Files:

    Last edited: Jul 29, 2015
  2. walterf25

    walterf25 Well-Known Member Licensed User

    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
     
  3. thader2012

    thader2012 Member Licensed User

    Wonderfull!!! its very nice! thanks!!
     
  4. walterf25

    walterf25 Well-Known Member Licensed User

    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
     
  5. MarcoRome

    MarcoRome Expert Licensed User

    Hi Walter.
    The your movie give me error, anyway do you have this library:
    DateUtils
    DownloadManager
    HTTP
    HttpUtils2
    OkHttp
    JSON
    RandomAccessFile
    SQL
    StringUtils
     
  6. walterf25

    walterf25 Well-Known Member Licensed User

    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
     
  7. MarcoRome

    MarcoRome Expert Licensed User

    No dont wrong. But is strain that you have this error.
    I dont see your movie give me error.
     
  8. walterf25

    walterf25 Well-Known Member Licensed User

    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
     
  9. MarcoRome

    MarcoRome Expert Licensed User

    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 ) ??
     
  10. walterf25

    walterf25 Well-Known Member Licensed User

    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
     
  11. MarcoRome

    MarcoRome Expert Licensed User

    Do you have try in different device ?
     
  12. walterf25

    walterf25 Well-Known Member Licensed User

    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:
    mp3.Initialize("https://www.youtube.com/watch?v=i62Zjga8JOM"True"YouTube", Me, "check_short")
    Thanks,
    Walter
     
  13. MarcoRome

    MarcoRome Expert Licensed User

    Mhhh..Ok in attachment 1# you have also class. Let me know
     
  14. walterf25

    walterf25 Well-Known Member Licensed User

    Ok, the problem is this line 48, If i comment this line everything works fine.

    Code:
    job1.GetRequest.SetContentEncoding("text/plain")
    this is the error i get and the application stops exactly at line 48 of your class.

    Code:
    ** 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
     
  15. walterf25

    walterf25 Well-Known Member Licensed User

    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
     
  16. MarcoRome

    MarcoRome Expert Licensed User

    I dont know Walter i havent Lollipop version. Sorry
     
  17. walterf25

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

    Attached Files:

    MarcoRome and DonManfred like this.
  18. ArminKH

    ArminKH Well-Known Member

    marco are u start developing librariessss?
    goooooooood luck ;)
     
    MarcoRome likes this.
  19. MarcoRome

    MarcoRome Expert Licensed User

    Good Job Walter.
    welcome ;)
     
  20. MarcoRome

    MarcoRome Expert Licensed User

    The star is DonManfred and in last time , but dont last is Johan
     
Loading...