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

  Thread Rating:
  • 2 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
ruuk Offline
Team-Kodi Member
Posts: 2,205
Joined: Aug 2005
Reputation: 199
Location: Bremerton, WA USA
Information  [Module] youtube-dl - multi-site playable URL resolver
Post: #1
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.
(This post was last modified: 2016-07-16 22:23 by ruuk.)
find quote
Koying Offline
Team-Kodi Developer
Posts: 5,708
Joined: Sep 2008
Reputation: 179
Location: Brussels, Belgium
Post: #2
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...
find quote
ruuk Offline
Team-Kodi Member
Posts: 2,205
Joined: Aug 2005
Reputation: 199
Location: Bremerton, WA USA
Post: #3
(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
find quote
Koying Offline
Team-Kodi Developer
Posts: 5,708
Joined: Sep 2008
Reputation: 179
Location: Brussels, Belgium
Post: #4
(2014-08-11 19:19)ruuk Wrote:  I better get going and submit it to the official repository Smile
Most definitely Smile
find quote
ruuk Offline
Team-Kodi Member
Posts: 2,205
Joined: Aug 2005
Reputation: 199
Location: Bremerton, WA USA
Post: #5
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.
find quote
Kib Offline
Team Kodi 🐤 Member
Posts: 5,023
Joined: Jan 2010
Reputation: 87
Location: The Hague
Post: #6
(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?
find quote
ruuk Offline
Team-Kodi Member
Posts: 2,205
Joined: Aug 2005
Reputation: 199
Location: Bremerton, WA USA
Post: #7
(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?
find quote
Martijn Offline
Team Kodi
Posts: 16,981
Joined: Jul 2011
Reputation: 310
Location: Dawn of time
Post: #8
nope, not changed. still no request though and I know it's working because others did come in.

* Martijn hates the ML

Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
(This post was last modified: 2014-08-11 20:54 by Martijn.)
find quote
ruuk Offline
Team-Kodi Member
Posts: 2,205
Joined: Aug 2005
Reputation: 199
Location: Bremerton, WA USA
Post: #9
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.
find quote
Kib Offline
Team Kodi 🐤 Member
Posts: 5,023
Joined: Jan 2010
Reputation: 87
Location: The Hague
Post: #10
Yep, I can see it now.
find quote
Skipmode A1 Offline
Skilled Python Coder
Posts: 308
Joined: Mar 2013
Reputation: 25
Post: #11
Very usefull this, thanks ruuk.

Btw it does not work for xbmc 12.x or older.
find quote
ruuk Offline
Team-Kodi Member
Posts: 2,205
Joined: Aug 2005
Reputation: 199
Location: Bremerton, WA USA
Post: #12
Version 14.810.0

Now also on the official repository Smile
find quote
mujunk Offline
Member
Posts: 91
Joined: Feb 2013
Reputation: 3
Post: #13
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.
find quote
ruuk Offline
Team-Kodi Member
Posts: 2,205
Joined: Aug 2005
Reputation: 199
Location: Bremerton, WA USA
Post: #14
(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.
find quote
Lunatixz Offline
Skilled Python Coder
Posts: 4,928
Joined: May 2011
Reputation: 147
Location: NYC
Post: #15
Great module, Thanks... Can't wait to implement it Smile
find quote
Post Reply