Release [Module] youtube-dl - multi-site playable URL resolver
#1
Information 
youtube-dl


This addon provides access to youtube-dl as an Kodi (XBMC) module.
youtube-dl is a video downloader written in python and released in the public domain. It supports 270+ sites and is updated frequently.

This addon wraps youtube-dl in an easy to use module and was designed to be updated by dropping in the youtube-dl core without modification. In future versions, the core will be update-able by the the user or automatically.
Basically the module allows you to get the Kodi (XBMC) playable video URL from a site's video page URL. It also provides convenience functions for video downloading.

Currently it is only available on my repository but I will submit it to the official repository soon.

The zip for my repository is HERE.

If you need help, ask a question in this thread or join #ruuk on freenode.

USAGE

Add this to your addon.xml to use the latest version. You will need to update this for new versions of the addon because I'm not sure module addons will update otherwise.
This was the newest version at the time of this post, you will need to change the version in the future if you want to ensure the latest version is used.

Code:
<import addon="script.module.youtube.dl" version="14.810.0"/>

Getting playable streams:

Code:
import YDStreamExtractor
YDStreamExtractor.disableDASHVideo(True) #Kodi (XBMC) only plays the video for DASH streams, so you don't want these normally. Of course these are the only 1080p streams on YouTube

url = "http://www.youtube.com/watch?v=_yVv9dx88x0" #a youtube ID will work as well and of course you could pass the url of another site
vid = YDStreamExtractor.getVideoInfo(url,quality=1) #quality is 0=SD, 1=720p, 2=1080p and is a maximum
stream_url = vid.streamURL() #This is what Kodi (XBMC) will play

For sites that can have multiple streams (ie different trailers for the same video URL) you would use:

Code:
choices = []
if vid.hasMultipleStreams():
    for s in vid.streams():
        title = s['title']
        choices.append(title)
    index = some_function_asking_the_user_to_choose(choices)
    vid.selectStream(index) #You can also pass in the the dict for the chosen stream
stream_url = vid.streamURL()

Also, the following is useful if you need to verify whether multiple URLs represent a playable video. It basically checks whether the the URL is a valid type for one of the supported sites without actually accessing anything:

Code:
#This will return True if the URL points (probably) to a video without actually fetching all the stream info.
YDStreamExtractor.mightHaveVideo(url)

For some sites and URLs the module will fail to detect a valid URL because of redirects. For those sites you can set the keyword argument "resolve_redirects=True" for mightHaveVideo() and getVideoInfo().


And to download a video:

Code:
import YDStreamUtils
import YDStreamExtractor
YDStreamExtractor.disableDASHVideo(True)

url = "http://www.youtube.com/watch?v=_yVv9dx88x0"
vid = YDStreamExtractor.getVideoInfo(url,quality=1)
path = "/directory/where/we/want/the/video"

with YDStreamUtils.DownloadProgress() as prog: #This gives a progress dialog interface ready to use
    try:
        YDStreamExtractor.setOutputCallback(prog)
        result = YDStreamExtractor.downloadVideo(vid,path)
        if result:
            #success
            full_path_to_file = result.filepath
        elif result.status != 'canceled':
            #download failed
            error_message = result.message
    finally:
        YDStreamExtractor.setOutputCallback(None)

YDStreamExtractor.py has some documentation for the functions if you need more detail.
Reply


Messages In This Thread
[Module] youtube-dl - multi-site playable URL resolver - by ruuk - 2014-07-29, 06:07
v14.810.0 - by ruuk - 2014-08-11, 19:45
v14.925.0 - by ruuk - 2014-09-25, 17:49
v14.1026.0 - by ruuk - 2014-10-26, 21:53
v14.1210.0 - by ruuk - 2014-12-10, 23:32
v14.1210.1 - by ruuk - 2014-12-11, 21:17
v15.318.0 - by ruuk - 2015-04-02, 23:01
v15.1123.0 - by ruuk - 2015-11-23, 21:20
v15.1124.0 - by ruuk - 2015-11-24, 21:05
v15.1223.0 - by ruuk - 2015-12-23, 22:27
v16.306.0 - by ruuk - 2016-03-13, 19:05
v16.318.0 - by ruuk - 2016-03-21, 20:31
v16.327.0 - by ruuk - 2016-03-31, 01:12
v16.521.0 - by ruuk - 2016-05-22, 18:15
v16.627.0 - by ruuk - 2016-06-28, 20:38
v16.1026.0 - by ruuk - 2016-10-28, 18:32
v17.310.0 - by ruuk - 2017-03-11, 23:47
v17.518.0 - by ruuk - 2017-05-21, 08:53
v17.518.1 - by ruuk - 2017-05-25, 04:00
v17.709.0 - by ruuk - 2017-07-11, 03:00
v17.1228.0 - by ruuk - 2017-12-28, 22:46
v17.1231.0 - by ruuk - 2018-01-01, 05:46
v18.320.0 - by ruuk - 2018-03-25, 02:07
v18.425.0 - by ruuk - 2018-04-28, 02:53
v14.1217.0 - by ruuk - 2014-12-27, 21:12
RE: Script Error Message - by ruuk - 2016-04-14, 13:15
RE: v16.1026.0 - by Lunatixz - 2016-10-28, 20:25
L0RE - by L0RE - 2017-12-19, 14:34
Script Error Message - by eondesigns1138 - 2016-04-08, 10:46
Error python dependency 2.25.0 - by Alyy - 2016-05-21, 10:45
Logout Mark Read Team Forum Stats Members Help
[Module] youtube-dl - multi-site playable URL resolver2