eigan/mediasort 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

eigan/mediasort

Composer 安装命令:

composer require eigan/mediasort

包简介

A batch rename tool for media files

README 文档

README

Tests Coverage

Mediasort

A batch rename tool for media files (audio, video and images). Move, or create an hardlink, with a new name based on meta information extracted from the file.

Example

mediasort source/ destination/
  • destination is optional.
  • --format=":year/:month/:date :time" default format of new filenames

Common options

  • -r for recursive
  • --link for using hardlinks
  • -n for no interaction (autoconfirm)
  • -q quiet
  • See more options
Before
source
├── IMG_20170331_180220.jpg
├── IMG_20170802_183621.jpg
├── IMG_20170802_183630.jpg
├── IMG_20170802_183634.jpg
└── VID_20171002_084709.mp4
After

Files are moved into destination/ (create hardlinks with --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

Installation

See the wiki page.

Requirements

  • PHP 7.0.24+
    • ext-exif. For precise meta information (dates), and more.
    • ext-phar For composer (build from source), or to execute phar file

Arch Linux

Mediasort is available through AUR: mediasort.

Composer (global)

composer global require eigan/mediasort

Usage

Options

--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)

Note: shortcuts cannot be combined, -nv will not work. This is a limitation of the CLI library used.

About

Date and time from files

Date is retrieved from files in the following order:

  • exif meta information (image)
  • id3 meta information (video/audio)
  • Date in path matching pattern:
    • YYYYMMDD_HHMMSS
    • YYYY-MM-DD HH.mm.ss
    • YYYY-MM-DD HH:mm:ss
    • YYYYMMDDHHMMSS
    • YYYYMMDD-HHMMSS

If no dates are found, then the format fails and file is skipped.

File name collision

When a file is identical, it gets ignored, otherwise we append an index to the filename.

Step by step (internal)

- 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

Tips

Remove empty directories

find . -type d -empty -delete

Todo

These are things I would like to do sometime, but I don't really need right now.

  • Split code into more files.
  • More formatters
    • :type-s
    • :exif(ExifProp)
    • :path full original path
  • --filter=":size>10 & :name~/regex/ & :weekday=monday
  • I18n
  • Test Mac (travis) / Windows (tea-ci)
  • symlink

eigan/mediasort 适用场景与选型建议

eigan/mediasort 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 26 次下载、GitHub Stars 达 30, 最近一次更新时间为 2017 年 10 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 eigan/mediasort 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 eigan/mediasort 我们能提供哪些服务?
定制开发 / 二次开发

基于 eigan/mediasort 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 26
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 30
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 30
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2017-10-21