Kodi Community Forum
Release [Module] youtube-dl - multi-site playable URL resolver - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Support (https://forum.kodi.tv/forumdisplay.php?fid=33)
+--- Forum: Add-on Support (https://forum.kodi.tv/forumdisplay.php?fid=27)
+---- Forum: Video Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=154)
+---- Thread: Release [Module] youtube-dl - multi-site playable URL resolver (/showthread.php?tid=200877)

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22


[Module] youtube-dl - multi-site playable URL resolver - ruuk - 2014-07-29

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.


RE: [Module] youtube-dl (Pre-release) - Koying - 2014-08-11

Was thinking that this was really missing Wink

Is there already "frontend" addons to you module, to the best of your knowledge?
Pretty sure a youtube frontend would allow VEVO, by instance...


RE: [Module] youtube-dl (Pre-release) - ruuk - 2014-08-11

(2014-08-11, 12:55)Koying Wrote: Was thinking that this was really missing Wink

Is there already "frontend" addons to you module, to the best of your knowledge?
Pretty sure a youtube frontend would allow VEVO, by instance...

My WebViewer and Forum Browser addons use it to play video links. One user was adding it to some addons he created, and AddonScriptorDE said it would be useful for many of his addons and save him a lot of time. I better get going and submit it to the official repository Smile


RE: [Module] youtube-dl (Pre-release) - Koying - 2014-08-11

(2014-08-11, 19:19)ruuk Wrote: I better get going and submit it to the official repository Smile
Most definitely Smile


v14.810.0 - ruuk - 2014-08-11

Version 14.810.0

Changes:
  • Update youtube-dl core to 2014.08.10


On my REPO.

I also submitted this to the official repository. I'll update here when it is accepted.


RE: [Module] youtube-dl - multi-site playable URL resolver - Kib - 2014-08-11

(2014-08-11, 19:45)ruuk Wrote: I also submitted this to the official repository. I'll update here when it is accepted.

I am sure we would love to have this in the official repo, but the request hasn't come in yet. Are you sure you sent it to the correct address?


RE: [Module] youtube-dl - multi-site playable URL resolver - ruuk - 2014-08-11

(2014-08-11, 20:47)Kib Wrote:
(2014-08-11, 19:45)ruuk Wrote: I also submitted this to the official repository. I'll update here when it is accepted.

I am sure we would love to have this in the official repo, but the request hasn't come in yet. Are you sure you sent it to the correct address?

Sent it to [email protected] as I always have, just a few minutes before I made the post. Has the address changed?


RE: [Module] youtube-dl - multi-site playable URL resolver - Martijn - 2014-08-11

nope, not changed. still no request though and I know it's working because others did come in.

* Martijn hates the ML


RE: [Module] youtube-dl - multi-site playable URL resolver - ruuk - 2014-08-11

I just re-sent it to the mailing list address and also one of my addresses on a different server and it at least got to my address fine. Hopefully it showed up on the ML this time as well.


RE: [Module] youtube-dl - multi-site playable URL resolver - Kib - 2014-08-11

Yep, I can see it now.


RE: [Module] youtube-dl - multi-site playable URL resolver - Skipmode A1 - 2014-08-15

Very usefull this, thanks ruuk.

Btw it does not work for xbmc 12.x or older.


RE: [Module] youtube-dl - multi-site playable URL resolver - ruuk - 2014-08-16

Version 14.810.0

Now also on the official repository Smile


RE: [Module] youtube-dl - multi-site playable URL resolver - mujunk - 2014-08-19

Pardon my ignorance. What is the Average Joe required to do with this? I have installed your repo but couldnt find this under video addons.


RE: [Module] youtube-dl - multi-site playable URL resolver - ruuk - 2014-08-19

(2014-08-19, 12:56)mujunk Wrote: Pardon my ignorance. What is the Average Joe required to do with this? I have installed your repo but couldnt find this under video addons.

This isn't for the "Average Joe". This is a module for other addons to use. It's main feature it that it converts the video URL to the actual playable video URL. One of the hardest parts of coding a video addon is to access the actual playable URL. Not only does it take some complex parsing and various tricks to accomplish, the method also needs to change occasionally to adapt to changes in the site.

The youtube-dl project works with hundreds of sites and is updated constantly for changes in those sites.

So for instance the YouTube addon recently had issues playing videos because of changes in the YouTube site. If this module had existed at that time and the YouTube addon was using it it would not have needed any intervention by the author to account for those changes, because the youtube-dl project was quickly updated.
Another example of it's usage is in my Forum Browser addon. It allows it to play video links from a variety of sites without me having to do anything but pass in the video page URL.


RE: [Module] youtube-dl - multi-site playable URL resolver - Lunatixz - 2014-08-19

Great module, Thanks... Can't wait to implement it Smile


This forum uses Lukasz Tkacz MyBB addons.