Add option for setting more recognizable file names #86

Closed
opened 2025-11-09 09:40:22 -06:00 by GiteaMirror · 5 comments
Owner

Originally created by @06000208 on GitHub (Jul 4, 2023).

When I save files, I would prefer the file name to contain relevant information that could be later used to determine the source of the file.

For example, the media from this tweet https://twitter.com/dril/status/1667377869566390280 being saved as dril-1667377869566390280.png, with the syntax handle-id.ext

Since cobalt handles multiple platforms, I wouldn't mind the name of the platform being included, if that's a necessity.

This feature request was inspired by how tw-media-downloader (extension, repo) handles file names, as it recently stopped working with direct tweet downloads.

Proposed Technical Implementation

In a perfect world, you would be able to use the download attribute on an anchor tag with the same URL that cobalt normally opens, but that's impossible as the download attribute only works with same-origin URLs and blob downloads.

Thusly, in order to achieve this client side, cobalt's javascript would have to:

  1. Perform a request (likely with the fetch api) and handle the response
  2. Encode the retrieved file as a blob
  3. Set the needed attributes on an anchor element (probably with createObjectURL)
  4. Click the anchor with click() to initiate the download

I'm unsure if there's anything platforms could do to prevent files from being retrieved client side this way, probably something to do with CORS, but I of course hope this method would consistently work.

Otherwise, this could be achieved server side by proxying the files with the desired Content-Disposition header, but I expect doing it that way would, in my opinion:

  • Be too significant for cobalt's bandwidth, and by extension, hosting costs
  • Take on too significant technical debt regarding subverting platforms who may ban cobalt's IP, rate limits, and other factors
Originally created by @06000208 on GitHub (Jul 4, 2023). When I save files, I would prefer the file name to contain relevant information that could be later used to determine the source of the file. For example, the media from this tweet https://twitter.com/dril/status/1667377869566390280 being saved as `dril-1667377869566390280.png`, with the syntax `handle-id.ext` Since cobalt handles multiple platforms, I wouldn't mind the name of the platform being included, if that's a necessity. This feature request was inspired by how tw-media-downloader ([extension](https://addons.mozilla.org/en-US/firefox/addon/tw-media-downloader), [repo](https://github.com/furyutei/twMediaDownloader)) handles file names, as it recently stopped working with direct tweet downloads. ## Proposed Technical Implementation In a perfect world, you would be able to use the [download attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attributes) on an anchor tag with the same URL that cobalt normally opens, but that's impossible as the download attribute only works with same-origin URLs and blob downloads. Thusly, in order to achieve this client side, cobalt's javascript would have to: 1. Perform a request (likely with the [fetch api](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)) and handle the response 2. Encode the retrieved file as a [blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) 3. Set the needed attributes on an anchor element (probably with [createObjectURL](https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL_static)) 4. Click the anchor with click() to initiate the download I'm unsure if there's anything platforms could do to prevent files from being retrieved client side this way, probably something to do with CORS, but I of course hope this method would consistently work. Otherwise, this could be achieved server side by proxying the files with the desired Content-Disposition header, but I expect doing it that way would, in my opinion: - Be too significant for cobalt's bandwidth, and by extension, hosting costs - Take on too significant technical debt regarding subverting platforms who may ban cobalt's IP, rate limits, and other factors
GiteaMirror added the feature request label 2025-11-09 09:40:22 -06:00
Author
Owner

@wukko commented on GitHub (Jul 21, 2023):

cobalt already puts post id into file names for all services, but all extra info is not added at this time.

@wukko commented on GitHub (Jul 21, 2023): cobalt already puts post id into file names for all services, but all extra info is not added at this time.
Author
Owner

@06000208 commented on GitHub (Jul 23, 2023):

cobalt already puts post id into file names for all services

this doesn't appear to be the case? for example, take this tweet: https://twitter.com/KS_wktk/status/1370702788624142336

to download the video, cobalt opens this in a new tab or copies it to clipboard, neither of which provide control over file name: https://video.twimg.com/tweet_video/EwW2ovRUcAYOHfC.mp4

when saved with ctrl+s, it will have the default file name of EwW2ovRUcAYOHfC.mp4 and won't contain the post id 1370702788624142336

@06000208 commented on GitHub (Jul 23, 2023): > cobalt already puts post id into file names for all services this doesn't appear to be the case? for example, take this tweet: https://twitter.com/KS_wktk/status/1370702788624142336 to download the video, cobalt opens this in a new tab or copies it to clipboard, neither of which provide control over file name: https://video.twimg.com/tweet_video/EwW2ovRUcAYOHfC.mp4 when saved with ctrl+s, it will have the default file name of EwW2ovRUcAYOHfC.mp4 and won't contain the post id 1370702788624142336
Author
Owner

@wukko commented on GitHub (Jul 23, 2023):

that’s because it’s a direct file link straight from twitter. cobalt can change the filename only when it handles files by itself.

@wukko commented on GitHub (Jul 23, 2023): that’s because it’s a direct file link straight from twitter. cobalt can change the filename only when it handles files by itself.
Author
Owner

@06000208 commented on GitHub (Jul 24, 2023):

yes, that was clear, just asking for clarification with an example, as you stated it already puts post id into file names for all services, and if that's true, I wouldn't have needed to make the feature request

@06000208 commented on GitHub (Jul 24, 2023): yes, that was clear, just asking for clarification with an example, as you stated it already puts post id into file names for all services, and if that's true, I wouldn't have needed to make the feature request
Author
Owner

@wukko commented on GitHub (Oct 15, 2023):

added in 7.6

@wukko commented on GitHub (Oct 15, 2023): added in 7.6
Sign in to join this conversation.