Giter Club home page Giter Club logo

mediasort's Introduction

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

mediasort's People

Contributors

eigan avatar wckd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

ljicas

mediasort's Issues

Config file

  • Setting format for several criterias (media-type, extension etc)
  • Override default option values
  • Api-keys for external sources #4

Movies

What I would really like is have it make links both for year and genre for movies for example
- /u/afraca @ reddit

  • Parse filenames so it can be used on external sources (themoviedb)
  • Load metadata from themoviedb (vendor lib)
    • Requires API key, need to get this via an option or config file
  • Read and write metadata on mkv, avi, mp4, ts, m2ts etc. (vendor lib?)
    • Write the api resource id into metadata
    • Write used metadata into file?
  • New variable :genre.
    • Look into using this with id3 too
  • The current :year variable needs to read from movie metadata too
  • Option to disable external sources

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.