Please allow creation of internet shortcut files (.url, .webloc, .desktop)
See original GitHub issueMake sure you are using the latest version: run youtube-dl --version
and ensure your version is 2018.05.01. If it’s not, read this FAQ entry and update. Issues with outdated version will be rejected.
- I’ve verified and I assure that I’m running youtube-dl 2018.05.01
Before submitting an issue make sure you have:
- At least skimmed through the README, most notably the FAQ and BUGS sections
- Searched the bugtracker for similar issues including closed ones
- Checked that provided video/audio/playlist URLs (if any) are alive and playable in a browser
What is the purpose of your issue?
- Bug report (encountered problems with youtube-dl)
- Site support request (request for adding support for a new site)
- Feature request (request for a new functionality)
- Question
- Other
The following sections concretize particular purposed issues, you can erase any section (the contents between triple —) not applicable to your issue
Description of your issue, suggested solution and other information
What?
youtube-dl should be able to create internet shortcut files in different formats. That is, instead of downloading a file, a small textfile is created – based on a template for the desired format – that contains the respective URL.
[EDIT: Example file content:
[InternetShortcut]
URL=https://www.youtube.com/watch?v=4_jkeWgtZ18
]
Why?
This is useful, e.g., when you want to binge-watch YouTube channels and want to take care yourself of what you already watched and didn’t watch, and in what order, instead of relying on the abilities of the video platform, but don’t want to get your disk space reduced unnecessarily.
You can also drag .url
files on Windows into a player like MPC-BE to stream them, which is much more performant than in the browser! Unlike with downloaded videos, it’s still easy with an internet shortcut to get access to the video comments in the browser.
After binge-watching a channel, you can share a zip file with shortcut files of the best content with others.
How?
Each major OS has its own file format for internet shortcuts. Though on macOS, while there is no system-level support for the Windows format, many apps support it, if I understood that correctly:
- Windows:
.url
- macOS:
.webloc
- Linux:
.desktop
Maybe, the --format
switch could be extended with the identifier link
or shortcut
. This would default to the file format that is associated with the current platform.
To explicitly specify the file format, the following identifiers could be established: winlink
, maclink
, linuxlink
.
Caveats for Windows: There are .url
and .website
files. “Based on exprimentation, I found programatically generating a .website file is non-trivial. If you don’t get the parameters exactly right, it will not work properly. As of yet, I cannot find documentation describing the format. The name of the link appears to be embedded in the file.” (source) So, we should stick to traditional .url
shortcuts. (Firefox also creates .url
files when dragging the address bar text.)
Caveats for Linux: .desktop
files are described: “A Free Desktop Entry, used by Gnome and KDE, as well as Solaris (which I think uses Gnome).” (source) Therefore, I’m not sure, whether we can generalize .desktop
files with linuxlink
. (I’m not a Linux user.)
Alternatively or additionally, you may further specify the link
identifier with the extension, or use it directly like --format mp4
:
--format link[ext=url]
--format link[ext=webloc]
--format link[ext=desktop]
--format url
--format webloc
--format desktop
Proposed templates
The following placeholders are used in the templates that have to be replaced in a string-based manner, nothing fancy:
{{{url}}}
– Different sections of the URL must be encoded differently. See https://news.ycombinator.com/item?id=11674220.{{{title}}}
– Only used for.desktop
files. “Ubuntu…The file explorer displays the name embedded in the file.” (source) Hence, it should probably be identical to the filename. Characters that are invalid in the file system should be okay according to these example files.
The file must be saved with UTF-8 encoding.
.url
files
[InternetShortcut]\r\n URL={{{url}}}\r\n
Chrome creates files of that structure.
Note: Windows internet shortcut files may also be created via COM. Here’s a code example of MPC-BE for reading .url
files via COM.
.webloc
files
<?xml version="1.0" encoding="UTF-8"?>\n <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n <plist version="1.0">\n <dict>\n <key>URL</key>\n [\t for indent] <string>{{{url}}}</string>\n [\t for indent] </dict>\n </plist>\n
.desktop
files
[Desktop Entry]\n Encoding=UTF-8\n Name={{{title}}}\n Type=Link\n URL={{{url}}}\n Icon=text-html\n
Further information and things to consider
- There’s a Web Shortcut Utility Suite, that just has libraries for Java and Perl. However, the developer writes:
During development I collected shortcuts from various operating systems (both to study and to use for unit tests). I also manually created some examples for testing purposes. I made these available in their own repository with the hope that they will be useful to other developers. [link]
- Windows is caching the URL of a
.url
file based on its filename or file path. This may mislead you when testing, or, possibly, a user when they run youtube-dl multiple times with simple output filenames. - It’s important, that the
--download-archive
switch for continuing watching a channel works with internet shortcut files, also, even when previously created shortcut files were deleted.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:10
This simply won’t work: none of these shortcut formats apparently support passing HTTP headers. Needless to say it’s extremely specific and out of scope.
@h-h-h-h
I just checked, and yes, you’re correct; youtube-dl doesn’t put anything in the download-archive file when simulating (e.g., using the
--get-*
switches), and I can’t find anything in the help to make it do that.About naming the files, the way I showed to create files using the video title can be easily changed to use the
--get-filename
switch instead of--get-title
, and now, you have all the flexibility of the output templates.The only thing is that an id is printed before the filename.
I think the only remaining problem is recording what videos are downloaded, even if their link files are deleted. This would be easy if there were a switch in youtube-dl to make it record simulated downloads in the archive file.
I agree that using youtube-dl is much saner. But if this functionality isn’t going into youtube-dl, one can make a small Python script that uses youtube-dl to get all the needed metadata (in JSON maybe), read the archive file, write the link files, and append the newly “saved” videos to the archive file.
But I noticed that youtube-dl looks in the archive file, if given, even when simulating. This means we can handle recording the saved videos, and leave filtering old videos to youtube-dl itself.
My Bash prototype, again. 😃