Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Please allow creation of internet shortcut files (.url, .webloc, .desktop) #16402
Comments
|
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. |
What have HTTP headers got to do with this matter? Imagine, I have a list of videos I want to watch, like: https://www.youtube.com/user/sxephil/videos. This list has videos with URLs of the form https://www.youtube.com/watch?v=4_jkeWgtZ18, which are the first thing youtube-dl encounters before trying to go deeper. These URLs must be written into the internet shortcut files, one of these URLs per file. MPC-BE, e.g., understands them. You can also double-click one of those and a browser tab will open. Example
[EDIT: It's also useful for getting the URLs of an RSS feed without downloading the videos when you would rather like to stream them.] I think, if more people had and knew these possibilities for binge-watching a channel and staying up-to-date with it or revisit the channel later for a further binge-watch session, the function would get its valid share of usage. And what else is youtube-dl's goal but to enable people to get access to their videos under other circumstances than what the website provides for, even if it's "just" by acting as a means of checking what you have already watched (what you already have been presented via link files). (I'm referring to
Would you, please, alternatively, point me to the important locations in the codebase and tell me possible things to consider, so that I can try it myself -- at least off the top of your head?
|
|
Interesting idea! You can use youtube-dl --get-id $URL | while read id
do
echo "[InternetShortcut]" > "$id.url"
echo "URL=https://www.youtube.com/watch?v=$id" >> "$id.url"
doneThis will create a file named If you want to have the We need the You can then use that output to generate these youtube-dl --get-title --get-id $URL | while read title
do
read id
echo "[InternetShortcut]" > "$title.url"
echo "URL=https://www.youtube.com/watch?v=$id" >> "$title.url"
doneThe problem is that using a video title as a filename directly is unsafe; you need to handle at least the forbidden characters in filenames in Windows ( |
|
Unfortunately, we also need to update a list of link files, and also find IDs of videos that were uploaded a while ago, but not made visible just until now, so that they appear inmidst of video IDs for which link files were already created. Further, I'd like the naming scheme Using the ecosystem of youtube-dl with its |
|
@noureddin You need to keep in mind |
|
Thanks, @rautamiekka! |
|
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 About naming the files, the way I showed to create files using the video title can be easily changed to use the 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. 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 |
Thanks, that's important information, should we need to write a solution on top of youtube-dl. |
|
I created a pull request that implements this feature: #16455. |
Make sure you are using the latest version: run
youtube-dl --versionand ensure your version is 2018.05.01. If it's not, read this FAQ entry and update. Issues with outdated version will be rejected.Before submitting an issue make sure you have:
What is the purpose of your issue?
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:
]
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
.urlfiles 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:
.url.webloc.desktopMaybe, the
--formatswitch could be extended with the identifierlinkorshortcut. 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
.urland.websitefiles. "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.urlshortcuts. (Firefox also creates.urlfiles when dragging the address bar text.)Caveats for Linux:
.desktopfiles 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.desktopfiles withlinuxlink. (I'm not a Linux user.)Alternatively or additionally, you may further specify the
linkidentifier 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 desktopProposed 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.desktopfiles. "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.
.urlfiles[InternetShortcut]\r\n URL={{{url}}}\r\nChrome 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
.urlfiles via COM..weblocfiles<?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.desktopfiles[Desktop Entry]\n Encoding=UTF-8\n Name={{{title}}}\n Type=Link\n URL={{{url}}}\n Icon=text-html\nFurther information and things to consider
.urlfile 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.--download-archiveswitch for continuing watching a channel works with internet shortcut files, also, even when previously created shortcut files were deleted.