question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Please allow creation of internet shortcut files (.url, .webloc, .desktop)

See original GitHub issue

Make 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

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]

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:10

github_iconTop GitHub Comments

3reactions
dstftwcommented, May 8, 2018

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.

1reaction
noureddincommented, May 9, 2018

@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. 😃

download_archive=.archive  # a hidden file
youtube-dl --get-id --get-filename --download-archive "$download_archive" \
		-o '%(playlist_index)s. %(title)s-%(id)s.%(ext)s' $URL |
while read id
do
	read filename
	filename="${filename%.*}.url"  # change the extension to .url
	echo "Downloading $id: $filename"  # be a little verbose
	echo '[InternetShortcut]' > "$filename.url"
	echo "URL=https://www.youtube.com/watch?v=$id" >> "$filename.url"
	echo "youtube $id" >> "$download_archive"  # record in the archive,
	# in the same format youtube-dl recognizes
done
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Create a Desktop Shortcut to a Website - HelloTech
To create a desktop shortcut to a website using Google Chrome, go to a website and click the three-dot icon in the top-right...
Read more >
Create a Website Shortcut on Your Mac Dock (Using a Webloc)
In this tutorial, I give you a step-by-step guide to creating a web shortcut file, creating an app launch icon, and instructions for...
Read more >
Create a shortcut for URL? - Ask Ubuntu
In Ubuntu an URL shortcut is stored in a .desktop file as follow (for example): ... Add a context menu to quickly save...
Read more >
Open .URL files (Internet Shortcut) with any Browser via Right ...
Method 3: Using the classic “Open with” menu ... Right-click on a .url file and click Open with… ... Select your browser from...
Read more >
WEBLOC File Extension - FileInfo.com
A WEBLOC file is a website shortcut generated by web browsers in macOS, such as Apple Safari or Google Chrome. It contains the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found