B4A Library YouTube-DL (extract direct urls)

YouTube-DL - extract direct urls

This is a wrapper for an Android adaption of YouTube-DL. It was written by tastelessjolt and can be found on his/her repository on GitHub:

Many users asked me if we can stream YouTube streams with video-libraries/players such as standard VideoView, ExoPlayer, Vlc, Vitamio5 etc. As far as I know, if you use the standard "shared" link-format of YouTube videos, the video-players cannot play the videos. I suspected if you had the direct-url of the videos, then you should be able to do this. To test, I wrapped YouTube-DL and it works. This means you can stream and download such videos. I wouldn't use this lib in an app published on Google Play for obvious reasons.

The necessary libraries are attached. You also need to download the Kotlin Standard Support library (version 1.3.0) which you can find here: https://bit.ly/2GG6ItK. Add all libraries to your Additional Library folder.

A demo-project is also attached which you can download.

Example output:
title: The Shady Truth about Apple's MacBook Pro!
author: ZONEofTECH
thumbnailUrl: https://i.ytimg.com/vi/QizfKeKpR7c/default.jpg
lastUpdated: 2018-12-26 14:36:04.885
length: 689
videoId: QizfKeKpR7c
viewCount: -1

quality: hd720
url: https://r4---sn-hpa7.....5mpZ **TRUNCATED BY ME**
downloadState: NOT_DOWNLOADED
sanitizedFilename: The Shady Truth about Apple's MacBook Pro!
description: mp4
extension: mp4
itag: 22
audio: true
video: true
content: Video + Audio 720p 192kbps
location: null
type: video/mp4; codecs="avc1.64001F, mp4a.40.2"

Library information:


Author: Github: tastelessjolt, Wrapped by: moster67/Mikael Osterhed
Version: 0.25
  • B4AYouTubeDL
    This is a wrap of an Android version of YouTube-DL which will extract a direct link which
    can be used to download or stream a video.
    You need to initialize the library, then you pass on the shortened YouTube link (in Google's
    Share format such as **h_ttps://youtu.be/IfHG7bj-CE3**) to the ExtractLink-method.
    You will then need to monitor the two available events: OnError and OnResult.
    OnError will trigger if something goes wrong. The OnResult-event will trigger if everything worked fine
    and returns two Map-objects. The first object, VideoInfo, contains general information about the
    video while the second object, StreamInfo, contains direct-links of the video. The StreamInfo
    contains different formats of the links and another Map-object which holds the url and other
    information indicating quality, with or without video/audio etc for each format. Normally the
    first (0) item in the Map is the best one (quality-wise)
    You can use the "itag" information to also get the best url. The lowest value of "itag" should be the best one.
    • Events:
      • OnError
      • OnResult (VideoInfo As Object, StreamInfo As Object)
    • Functions:
      • ExtractLink (url As String)
        Extracts from YouTube the direct links which can be used for downloading/streaming.
        Pass the url using YouTube's share format (for example: **h_ttps://youtu.be/IfHG7bj-CE3**)
        Check the OnError- and OnResult-events for results.
      • Initialize (EventName As String)
        Initializes the library. Make sure to give an event name too so you
        can check the events OnError and OnResult.

I don't know much about YouTube-DL. I just tested it out briefly and it seems to work fine at the time of writing this post i.e. 26/12/2018.

That said, I have no intention of keeping the library up-to-date. Therefore, I am attaching the sources of the wrapper if someone else would like to update it or improve it. You can find the original sources at the Github-page I linked earlier in this post. Just be aware that the original project is mixed with Java and Kotlin. You can watch my videos published here to learn how to wrap Kotlin-projects.

Please remember that creating libraries and maintaining them takes time and so does supporting them. Please consider a donation if you use my free libraries as this will surely help keeping me motivated. Thank you!


  • JavaSource_B4aYouTubeDL.zip
    2.4 KB · Views: 565
  • Libs_YouTubeDL.zip
    41.6 KB · Views: 632
  • YouTubeDLDemo.zip
    8.9 KB · Views: 605
Last edited: