Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get the original link from which a file was download to Python?

On Mac OS, when you "Get Info" from a file, in "More info", there's a "Where from" information that shows me the original url from where I download the file.

I want to get to this information using Python, and I cannot seem to find a way to do it.

The os.path library doesn't seem to help since it only gives me information on things like creation time, size, etc. and nothing about the original download link.

like image 499
Francisco Nascimento Avatar asked Sep 30 '20 20:09

Francisco Nascimento


People also ask

How do I know the URL of the downloading file?

If you download a file using google chrome you can see its by using shortcut Ctrl+J or directly go to your downloads and under every download there is its original download URL. If you can't see the complete URL then you can right click on that URL and Copy Link.


Video Answer


1 Answers

IMPORTANT: This answer only applies to macOS.

The additional information is stored as a "file attribute". As far as I am aware, the os.path and pathlib cannot read arbitrary attributes.

However, you can use libraries, such as xattr to read "non-standard"1 attributes.

Something like this should work2:

import xattr

value = xattr.getxattr("file.txt", "some_key").decode("utf-8")

macOS stores informations such as the "Where from" attribute under the key com.apple.metadata:kMDItemWhereFroms.


1 I consider the values returned by fstat as standard attributes. I am aware, that there is no "true" standard.

2 The code hasn't been tested yet; I left my device at home.

like image 119
Julian Kirsch Avatar answered Oct 16 '22 07:10

Julian Kirsch