【问题标题】:using mdls command to generate a metadata report使用 mdls 命令生成元数据报告
【发布时间】:2012-04-19 19:01:54
【问题描述】:

全部,
我有一个 shell 脚本,它遍历用户提供的文件夹中的所有媒体(音频、视频)文件,并创建一个基于文本的漂亮元数据报告。我在 Mac OS X 上使用 Spotlight 的 mdls 命令获取所有相关元数据。问题是有时我会在所有媒体文件的报告中看到“空”结果。如果我再次运行脚本,它似乎可以工作。我很困惑为什么会这样。这是输出元数据报告的脚本的一部分:

cd "path_to_folder"
while IFS= read -r -d $'\0' file; do
  duration=`mdls -name kMDItemDurationSeconds "$file" | cut -d "=" -f 2 `
  duration=`printf "%.2f" $duration;`
  pixel_height=`mdls -name kMDItemPixelHeight "$file" | cut -d "=" -f 2`
  pixel_width=`mdls -name kMDItemPixelWidth "$file" | cut -d "=" -f 2`
  codec=`mdls -name kMDItemCodecs "$file" | cut -d "=" -f 2`
  temp="$i) [$file]\n- Duration: $duration\n- Dimensions: $pixel_width X $pixel_height pixels\n- Codec: $codec\n"
  metaDataOutput=$metaDataOutput"\n"$temp
  i=$((i + 1))
done < <(find .  \( -iname \*.m4v -o -iname \*.mov -o -iname \*.mp3 -o -iname \*.m4r -o -iname \*.m4a \)  -print0 )

echo -e  "\n[Report]\n"$metaDataOutput  

预期的输出是这样的:

1) [./test1.mov]
- 持续时间:22.03
- 尺寸:480 X 640 像素
- 编解码器:(“H.264”)

2) [./test2.mov]
- 时长:25.03
- 尺寸:480 X 640 像素
- 编解码器:(“H.264”)

但有时所有媒体文件的输出都为空:

1) [./test1.mov]
- 持续时间:空
- 尺寸:空 X 空像素
- 编解码器:(空)

2) [./test2.mov]
- 持续时间:空
- 尺寸:空 X 空像素
- 编解码器:(空)

我在这里错过了一个技巧吗?为什么脚本有时会工作,有时会输出null?

【问题讨论】:

    标签: macos bash metadata spotlight


    【解决方案1】:

    问题是 Spotlight 没有为文件编制索引。我使用 mdimport 命令强制 Spotlight 为文件夹编制索引,这已经解决了问题

    【讨论】:

    • 例如使用mdimport -r PLUGIN 强制 Spotlight 使用特定插件重新索引所有文件(使用 mdimport -L 获取插件列表)
    猜你喜欢
    • 1970-01-01
    • 2016-10-26
    • 1970-01-01
    • 2017-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多