Kodi Community Forum

Full Version: [RELEASE] context.youtube.dl.menu (Context menu + button to download Youtube videos)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
While the youtube-dl control addon has functionality to download streams, I found it to be very slow and it requires remote control like Yatse or similar to send commands to Kodi to access the download controls.
I wanted to be able to just have a context menu entry to download YouTube videos while in the Youtube addon or any other addon using youtube as source or even from favorites. I also wanted the option to have a download button while a video is playing. This addon attempts to do just that.

In order to download the highest quality video & audio (1080p and higher), it requires ffmpeg or avconv to be installed on a system level. Youtube uses separate audio and video streams for those high quality and to combine the separate streams into a single file, ffmpeg or avconv is required. The addon falls back gracefully to obtain the best single stream containing both video & audio from youtube (max 720p) if neither ffmpeg or avconv binaries are available.
Note: Android systems will not be able to download high-quality streams with this addon.

This addon has configuration options to run as a service and patch the currently installed Kodi theme to add a red record button to the On Screen Display (OSD) while playing videos. This needs to be enabled if you wish to have that button, without it, you can only download videos using the default context menu.

To install:
- download my repository https://github.com/AnonTester/kodi-repo/...-1.0.0.zip
- Kodi → Addons → Addon Browser → Install from zip file → repository.anontester-1.0.0.zip
- Kodi → Addons → Addon Browser → Install from repository → Wuff's Repository → Context Menus → Youtube dl Context Menu → install
- Then enable it via Add-ons → My Add-ons → Context Menus → Youtube dl Context Menu → Enable
- Configuration option: enable the OSD button (if desired)

Requirements:
- Youtube-dl control addon
- ffmpeg or avconv system binaries (for merging high quality streams)

This addon was developed on Kodi 18 on Linux and is working for me. If you encounter any issues, provide debug logs and I'll look into it!
Hi, your download link doesn't work.
https://github.com/AnonTester/kodi-repo/...-1.0.0.zip
apologies. corrected now.
Hi I'd like to request a recording time option if its possible, I remember setting up something like this which actually took me quite a while to figure out using kodi on Linux.
I had a 30 mins option
I had a 1 hour option,
2 hour option
3 and 4 hour options.

When I switched to Android I spoke to the guy who created the video and he said there was no way to do this on android, something to do with ffmpeg. Anyway I can see you've somehow achieved this so is there anyway this is a possibility?
What would be the purpose of such a time limit? Do you want to record youtube live streams?

My addon is a front-end to youtube-dl and that is designed to download whole videos and not parts of it. There are no options or functions in youtube-dl to download only part of a stream and create the appropriate file header for such a partial video. On systems without ffmpeg like Android, youtube-dl would find the video stream that contains both audio and video and download that file in its entirety. There is no post-processing or any conversion done as ffmpeg or avconv would be required for that.
ffmpeg itself does have options to limit the output by filesize or length and can convert on-the-fly between various formats. However, on an Android system, a standalone ffmpeg is not available and if it were, it couldn't be used by Kodi and this addon. As far as I understand, this is due to the sandboxing of applications on Android.
On a linux or windows system, an external downloader could be defined for youtube-dl to use and that external downloader could be ffmpeg with specific options (like limiting the length). But I think this goes way beyond the purpose of what this addon is meant to do.
It gives an error and fails.
Without any details I cannot help you. Upload your kodi log (ideally debug log) and I can look into it.
(2019-07-01, 21:35)AnonTester Wrote: [ -> ]Without any details I cannot help you. Upload your kodi log (ideally debug log) and I can look into it.

Here is my log after a fail. Sure would be nice if it would work.

This is from x86-64 kodi LibreElec with ffmpeg tools installed from LibreElec repo.

https://paste.kodi.tv/ekabogofes.kodi
@tekno
While I see errors from my plugin and I'll look into it in more detail on the weekend, the second error refers to the main youtube-dl addon which my addon interfaces with. It's possibly an older version and can't get the proper details for the video you're trying to download - or you found a bug with it.
2019-09-19 00:23:22.784 T:139946011412224 NOTICE: context.youtube.dl.menu: err ERROR: 3dE6EWXrXFI: "token" parameter not in video info for unknown reason; please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; see https://yt-dl.org/update on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.

Try updating the youtube-dl addon. I'm updating it manually directly from the github page with a small bash shell script on my linux box (adjust paths as necessary for your system and install git:

#!/bin/sh
cd ~/.kodi/addons/script.module.youtube.dl/lib
rm -rf youtube_dl-old
mkdir tmp
cd tmp
#git checkout https://github.com/rg3/youtube-dl.git
git clone https://github.com/rg3/youtube-dl.git
mv ../youtube_dl ../youtube_dl-old
mv youtube-dl/youtube_dl ..
cd ..
rm -rf tmp
ls -la
chown kodi.kodi youtube_dl
python -m youtube_dl --version
Latest version of youtube-dl is 2019.09.12.1

It also seems that ffmpeg isn't actually installed?
2019-09-19 00:23:15.236 T:139946011412224 NOTICE: context.youtube.dl.menu: FFmpeg/AVCONV versions: {u'ffprobe': False, u'avconv': False, u'avprobe': False, u'ffmpeg': False}
Check on the command line if ffmpeg is in the path and/or available and just enter:
ffmpeg -version
Got it working. Now the only issue is that the downloaded file isnt moved. First I tried a USB attached device, that didnt work so I set it to a storage folder on my coreelec box. Even that didnt work. So I finally set it to \storage\.kodi\temp which is where it defaults to anyway but it still gives an error saying failed to move. By "it" I am sure the error is on the part of youtube-dl control and not this context menu addon but any help is welcome! Thanks in advance.
@extremeaudio, I've noticed issues with moving the downloaded files myself and tried all sorts of workarounds, but can't figure out exactly why it's not working properly any longer. The files are downloaded fine and are in the temp directory, but moving them to their final destination fails while the video is playing in Kodi itself. If downloaded and moved from the video list when the video is not playing, moving the file works fine. Even triggering the download and then skipping to the next video in a playlist works, but it fails while the video is playing. It doesn't make any sense to me why playing it would cause it to fail to write the downloaded file to the destination folder. I can only assume there are some changes to the Kodi VFS (Virtual FileSystem) modules. I can create a file and delete a file while the video is playing, but the data is not being written.

If/when I figure this out, I'll release an update. For now, it should work on your system when you download files from the video list context menu rather than from the OSD during playback.
Lately all downloads are failing "Youtube Contxt Error - Check Log"

 Running: YouTube (6.8.0) on Leia (Kodi-18.6) with Python 2.7.16 Path: /kodion/search/list/ Params: {} 2020-05-01 18:47:29.135 T:3212927808 ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<-- - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS! Error Type: Error Contents: ERROR: unable to download video data: HTTP Error 403: Forbidden Traceback (most recent call last): File "/storage/.kodi/addons/context.youtube.dl.menu/ytcontext.py", line 340, in main() File "/storage/.kodi/addons/context.youtube.dl.menu/ytcontext.py", line 140, in __init__ self.download() File "/storage/.kodi/addons/context.youtube.dl.menu/ytcontext.py", line 282, in download ydl.process_ie_result(ydl_info, download=True) File "/storage/.kodi/addons/script.module.youtube.dl/lib/youtube_dl/YoutubeDL.py", line 863, in process_ie_result return self.process_video_result(ie_result, download=download) File "/storage/.kodi/addons/script.module.youtube.dl/lib/youtube_dl/YoutubeDL.py", line 1644, in process_video_result self.process_info(new_info) File "/storage/.kodi/addons/script.module.youtube.dl/lib/youtube_dl/YoutubeDL.py", line 1928, in process_info self.report_error('unable to download video data: %s' % error_to_compat_str(err)) File "/storage/.kodi/addons/script.module.youtube.dl/lib/youtube_dl/YoutubeDL.py", line 625, in report_error self.trouble(error_message, tb) File "/storage/.kodi/addons/script.module.youtube.dl/lib/youtube_dl/YoutubeDL.py", line 595, in trouble raise DownloadError(message, exc_info) DownloadError: ERROR: unable to download video data: HTTP Error 403: Forbidden -->End of Python script error report<--]
@extremeaudio
The key part of this error is
Code:
File "/storage/.kodi/addons/script.module.youtube.dl/lib/youtube_dl/YoutubeDL.py", line 595, in trouble raise DownloadError(message, exc_info) DownloadError: ERROR: unable to download video data: HTTP Error 403: Forbidden
indicating that you got a 403 HTTP Forbidden error when trying to download and this error was thrown by the main youtube.dl module which is used by my addon.

There are 2 possible reasons I can think of why you're getting this.
1.) Youtube or something in your network connection blocks or interferes with the request
2.) The youtube-dl module on your system is outdated and not retrieving the proper download locations. The latest version from ruuk incorporates ytdl version from 24/March/2020    https://github.com/ruuk/script.module.youtube.dl 
Try upgrading if you're not on the latest version.
If that still doesn't work, you can try to download the latest ytdl version yourself and add it into the yourube-dl module directory.
I've got a small shell script to get the latest version on my linux system. This makes a copy of your current ytdl version, then downloads the latest version from github and puts it in place - adjust the code for your paths in the second line:
Code:
#!/bin/sh
cd ~/.kodi/addons/script.module.youtube.dl/lib
rm -rf youtube_dl-old
mkdir tmp
cd tmp
git clone https://github.com/rg3/youtube-dl.git
mv ../youtube_dl ../youtube_dl-old
mv youtube-dl/youtube_dl ..
cd ..
rm -rf tmp
ls -la
chown kodi.kodi youtube_dl
python -m youtube_dl --version
My version is the latest. The youtube-dl addon is set to auto update. However the downloading is still a hit and miss. So today when I first fired up kodi it worked and then from the second file onwards its stopped working.

Does the script of yours do anything different from what the addon auto updater does in Kodi anyway?
yes, my script does something different.

the autoupdater in kodi will update the addons from the repositories you've got installed or in the very least the official kodi repository.

The youtube-dl control kodi addon from ruuk is a wrapper for the youtube-dl core from rg3 and adds control features. The core as part of the plugin is not updated as frequently as there are new core releases though and it is still using the core from 2020.03.24 - 24th of March.
The script I posted above will insert the latest core youtube-dl from rg3 into the youtube-dl control kodi addon. The core gets updated frequently and the current release is 2020.05.08 - 8th of May.

The thread for ruuk's addon is here https://forum.kodi.tv/showthread.php?tid=200877&page=20  Please ask for help there and/or ask for a bump of the core version.
Pages: 1 2