eigan/mediasort

此包的最新版本(0.14)没有可用的许可证信息。

媒体文件批量重命名工具

0.14 2020-07-05 11:01 UTC

README

Tests Coverage

Mediasort

媒体文件(音频、视频和图片)的批量重命名工具。根据从文件中提取的元信息重命名文件,并移动或创建硬链接。

示例

mediasort source/ destination/
  • destination 是可选的。
  • --format=":year/:month/:date :time" 新文件名的默认格式

常见选项

  • -r 递归
  • --link 使用硬链接
  • -n 无交互(自动确认)
  • -q 静默
  • 查看更多选项
之前
source
├── IMG_20170331_180220.jpg
├── IMG_20170802_183621.jpg
├── IMG_20170802_183630.jpg
├── IMG_20170802_183634.jpg
└── VID_20171002_084709.mp4
之后

文件被移动到 destination/ (使用 --link 创建硬链接)

destination
└── 2017
    ├── 03 - March
    │   └── 2017-03-31 18:02:20.jpg
    ├── 08 - August
    │   ├── 2017-08-02 18:36:22.jpg
    │   ├── 2017-08-02 18:36:30.jpg
    │   └── 2017-08-02 18:36:35.jpg
    └── 10 - October
        └── 2017-10-02 08:47:09.mp4

安装

查看 wiki 页面

要求

  • PHP 7.0.24+
    • ext-exif. 用于精确的元信息(日期),等等。
    • ext-phar 用于 composer(从源代码构建)或执行 phar 文件

Arch Linux

Mediasort 通过 AUR 可用:[mediasort](https://aur.archlinux.org/packages/mediasort/)

Composer(全局)

composer global require eigan/mediasort

用法

选项

--format            Reformat the path
                    Example: --format=":year/:month/:date :time" (default)
             
                    Possible formatters:
                        :original (original path)
                        :date (alias ":year-:monthnum-:day")
                        :time (alias ":hour::minute::second")
                        :month (alias ":monthnum - :monthname")
                        :year
                        :monthnum
                        :monthname
                        :day
                        :hour
                        :minute
                        :second
                        :ext (not needed, always appended)
                        :name (original filename)
                        :dirname (name of original parent directory)
                     
                    Exif is mostly used if available

-r, --recursive     Look for files recursively in source

--only              Only files with the given extensions
                    Example: --only="jpg,gif"
                    
--only-type         Only files with the given filetype
                    Example: --type="image,video,audio" (default)
                    
--link              Create hardlink instead of moving

-v                  Show additional information
-vv                 Show even more info (result for all formatters)

-n                  Disable interaction (Will autoconfirm)

--ignore            Ignore certain file extensions
                    Example: --ignore="db,db-journal"
                    
--dry-run           Do not execute move/link

--no-exif           Do not read exif meta information

--log-path          Specify where to put mediasort.log
                    Default: null (no logging)

注意:快捷方式不能组合,-nv 不会工作。这是 CLI 库的限制。

关于

文件中的日期和时间

日期的检索顺序如下

  • exif 元信息(图像)
  • id3 元信息(视频/音频)
  • 路径中匹配模式的日期
    • YYYYMMDD_HHMMSS
    • YYYY-MM-DD HH.mm.ss
    • YYYY-MM-DD HH:mm:ss
    • YYYYMMDDHHMMSS
    • YYYYMMDD-HHMMSS

如果没有找到日期,则格式失败,文件将被跳过。

文件名冲突

当文件相同,则被忽略,否则我们将在文件名中附加索引。

逐步(内部)

- Takes two arguments
  - `source`: Read files from here
  - `destination` (optional): Directory to populate. If not set, uses `source`
- Takes several options, see list above

-  Start look for media files in source
  - Skip files if:
    - Not a media file
    - Filtered by options
    - Is in built in ignorelist:
      - .nomedia, @eaDir
  
  - Generate a name based on the `--format` option
  - Check if the generated name exists
    - Check if duplicate
    - append an available "index" to the name
    
  - Move or link the media file into destination

技巧

删除空目录

find . -type d -empty -delete

待办事项

这是我将来想做的事情,但现在我真的不需要。

  • 将代码拆分为更多文件。
  • 更多格式化程序
    • :type-s
    • :exif(ExifProp)
    • :path 完整原始路径
  • --filter=":size>10 & :name~/regex/ & :weekday=monday"
  • I18n
  • 测试 Mac (travis) / Windows (tea-ci)
  • 符号链接