Python 提取下载图像的 URL (`where from`) 信息

Python Extract URL (`where from`) information of downloaded image

我从网站下载了一张图片,我可以手动看到我从中下载图片的 URL 出现在图片的信息对话框 window。

我想使用 python 提取该字段的最后一部分,即 0001ss180819.png

我试过了PIL:

from PIL import Image, ExifTags

img = Image.open("/Users/anonymous/Downloads/figs/image (1).jpeg")
exif = { ExifTags.TAGS[k]: v for k, v in img._getexif().items() if k in ExifTags.TAGS }

但我无法获取所需的信息,即 where from 字段,如下所示。

我的目标是根据这些信息重命名照片。

下载文件的 url 不在图像本身内,而是作为扩展属性(来自 macOS)。参见 https://superuser.com/questions/214934/how-can-mac-os-x-save-details-about-the-url-from-which-a-file-has-been-downloade

仅作记录,我已设法在 python:

内找到解决方案
from subprocess import call
import os, numpy as np

path = "/Users//Downloads/photos/"
files = [f for f in os.listdir(path)]
n_images = len(files)

for i in range(n_images):
    full_file_path = os.path.join(path + files[i])
    tmp = os.popen("mdls -name kMDItemWhereFroms '{}'".format(full_file_path)).read()
    ID = tmp.split('file=')[-1].split('.')[0].split('ss')[0]
    new_name = '/Users//Downloads/photos/' + ID + '.jpeg'
    call(["mv", "{}".format(full_file_path), "{}".format(new_name)])