Git Product home page Git Product logo

media-sort's Introduction

media-sort

GoDoc CI

A command-line tool and Go (golang) library which categorizes provided files and directories by moving them into to a structured directory tree, using various live sources.

Install

Binaries

Releases Releases

See the latest release or download and install it now with curl https://i.jpillora.com/media-sort! | bash

Source

$ go get -v github.com/jpillora/media-sort

Features

  • Cross platform single binary
  • No dependencies
  • Easily create a Plex-compatible directory structure
  • Integration with uTorrent and qbittorrent "Run on Completion" option

Quick use

$ curl https://i.jpillora.com/media-sort! | bash
Installing jpillora/media-sort v2.4.3.....
######################################################################## 100.0%
Installed at /usr/local/bin/media-sort

Test run media-sort (read-only mode)

$ cd my-media/
$ media-sort --dry-run --recursive .
2016/01/30 09:35:47 [Dryrun]
2016/01/30 09:35:47 Searching dick van dyke show (series)
2016/01/30 09:35:47 [#1/1] dick-van-dyke-show.s01e10.[Awesome-Audio]-[Super-Quality]-[Name-of-Encoder].mp4
  └─> The Dick Van Dyke Show S01E10.mp4

CLI Usage

$ media-sort --help

  Usage: media-sort [options] <target> [target] ...

  media-sort categorizes the provided files and directories (targets) by
  moving them into to a structured directory tree, sorting is currently
  performed using TVMaze, MovieDB and Google.

  Options:
  --tv-dir, -t              tv series base directory (defaults to current directory)
  --movie-dir, -m           movie base directory (defaults to current directory)
  --tv-template             tv series path template
  --movie-template          movie path template
  --extensions, -e          types of files that should be sorted (default mp4,m4v,avi,mkv,mpeg,mpg,mov,webm)
  --concurrency, -c         search concurrency [warning] setting this too high can cause rate-limiting errors (default 6)
  --file-limit, -f          maximum number of files to search (default 1000)
  --num-dirs, -n            number of directories to include in search (default 0 where -1 means all dirs)
  --accuracy-threshold, -a  filename match accuracy threshold (default 95)
  --min-file-size           minimum file size (default 25MB)
  --recursive, -r           also search through subdirectories
  --dry-run, -d             perform sort but don't actually move any files
  --skip-hidden, -s         skip dot files
  --skip-subs               skip subtitles (srt files)
  --action                  filesystem action used to sort files (copy|link|move, default move)
  --hard-link, -h           use hardlinks instead of symlinks (forces --action link)
  --overwrite, -o           overwrites duplicates
  --overwrite-if-larger     overwrites duplicates if the new file is larger
  --watch, -w               watch the specified directories for changes and re-sort on change
  --watch-delay             delay before next sort after a change (default 3s)
  --verbose, -v             verbose logs
  --version                 display version
  --help                    display help

  by default, tv series are moved to:
    ./<title> S<season>E<episode>.<ext>
  and movies are moved to:
    ./<title> (<year>).<ext>

  to modify the these paths, you can use the --tv-template and
  --movie-template options. These options describe the new file path for
  tv series and movies using Go template syntax. You can find the
  default values here:
    https://godoc.org/github.com/jpillora/media-sort/sort#pkg-variables
  and you can view all possible template variables here:
    https://godoc.org/github.com/jpillora/media-sort/sort#Result

  Version:
    X.Y.Z

  Read more:
    github.com/jpillora/media-sort

Programmatic Use

See https://godoc.org/github.com/jpillora/media-sort

The API has 3 layers:

  1. An explicit search: mediasearch.Search(query, year, mediatype string) (mediasearch.Result, error) Returns search result
  2. A path string correction (using Search): mediasort.Sort(path string) (*mediasort.Result, error) Attempts to extract search query information from the path string, returns result which can be used to format a new path or result.PrettyPath() can be used.
  3. A filesystem correction (using Sort): mediasort.FileSystemSort(config mediasort.Config) error Attempts to sort all paths provided in config.Targets, when successful - results are formatted and renamed to use the newly formatted path.

media-sort's People

Contributors

codeaholics avatar izissise avatar jawira avatar jpillora avatar rotsix 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

media-sort's Issues

--tv-template and --movie-template examples

In reading your documentation, I see that you have these values, but I am unsure how to utilize them.

/go/bin/media-sort --tv-template "./<title>/<title> SE." -w -r --tv-dir /data/tv --movie-dir /data/movie /data/completed

This gave me:

2016/07/31 05:08:51 [#20/24] /data/completed/MYSHOW - The Complete Season 7 [HDTV]/MYSHOW S07E20.mp4
└─> File already exists '/data/tv/.--title---title- S-season-E-episode-.-ext-' (try setting --overwrite)

If you could give an example for how to create the template, that would be splendid.

Thanks!

option to use folder names instead of file names

hello,

i would prefer an option to switch to parent directory name for search and rename.

scene releases are named in a short version, so media-sort could not find the right information.

for example:

2016/11/24 14:52:20 [#29/52] Mr.Right.2015.German.720p.BluRay.x264-ENCOUNTERS/encounters-mrri_720p.mkv
└─> No results (Google search failed)

filename: encounters-mrri_720p.mkv -> no chance to get the right information
parent dir name: Mr.Right.2015.German.720p.BluRay.x264-ENCOUNTERS -> all information are here

with correct file names it works like a charm:

2016/11/24 14:52:20 [#32/52] Pixels.2015.German.DTS.DL.720p.BluRay.x264-HQX/Pixels.2015.German.DTS.DL.720p.BluRay.x264-HQX.mkv
└─> Pixels (2015).mkv

So i use at the moment a work arround via bash, but it is an ugly way to do this:

find . -type f -not -name test.sh | while read file
do
    dirname="$(dirname "$file")"
    new_name="${dirname##*/}"
    file_ext=${file##*.}
    if [ -n "$file_ext" -a  -n "$dirname" -a -n "$new_name" ]
    then
        echo "mv '$file' '$dirname/$new_name.$file_ext'"
    fi
done

No sortable files found

Not sure if this is an issue, or just my ignorance. But I run this against a directory containing .wav and .mp3 files and I get this:
No sortable files found (1064 files checked

My command line is media-sort -r -e -d Music

tv show & movie detection becomes bad

media-sort detection is actually not working as in the past.

For example:

The.Originals.S04E01.German.DL.DUBBED.720p.BluRay.x264-AIDA.mkv 
[...]
The.Originals.S04E08.German.DL.DUBBED.720p.BluRay.x264-AIDA.mkv

detection for The Originals worked 2 months ago perfect. Actually detection not working. Even for many movies. I updated media-sort to 2.2.0 because of omdb api key change.

Is this a problem with omdb change and what is a acceptable solution for this?

media-sort --version
2.2.0
media-sort -v -a 90 --dry-run --recursive .
2017/10/03 17:14:51 scanning targets...
2017/10/03 17:14:51 scanning: .
2017/10/03 17:14:51 skip non-regular file: The.Originals
2017/10/03 17:14:51 skip non-regular file: .
2017/10/03 17:14:51 scanned targets. found #2
2017/10/03 17:14:51 sorting files...
2017/10/03 17:14:51 [Dryrun]
2017/10/03 17:14:51 Searching the originals (series)
2017/10/03 17:14:51 [#2/2] The.Originals/The.Originals.S04E10.mkv
  └─> No results (closest result was 'Origins: The Journey of Humankind' with an accuracy score of 75)
2017/10/03 17:14:51 [#1/2] The.Originals/The.Originals.S04E09.German.DL.DUBBED.720p.BluRay.x264-AIDA.mkv
  └─> Invalid result type:

2017/10/03 17:16:41 scanning targets...
2017/10/03 17:16:41 scanning: .
2017/10/03 17:16:41 skip non-regular file: .
2017/10/03 17:16:41 scanned targets. found #3
2017/10/03 17:16:41 sorting files...
2017/10/03 17:16:41 [Dryrun]
2017/10/03 17:16:41 Searching wonder woman (movie) from 2017
2017/10/03 17:16:41 Searching transformers 5 the last knight webrip ld german
2017/10/03 17:16:41 Searching das belko experiment german dl ac3 dubbed
2017/10/03 17:16:42 [#3/3] Wonder.Woman.2017.German.DTS.DL.720p.BluRay.x264-Pate.mkv
  └─> No results (closest result was 'Wonder Woman: Molded from Clay' with an accuracy score of 83)
2017/10/03 17:16:42 [#1/3] Das.Belko.Experiment.German.DL.AC3.Dubbed.720p.BluRay.x264-PsO.mkv
  └─> No results (Google search failed)
2017/10/03 17:16:42 [#2/3] Transformers.5.The.Last.Knight.WEBRip.LD.German.x264.iNTERNAL-PsO.mkv
  └─> No results (closest result was 'Transformers: The Last Knight' with an accuracy score of 81)

Filter issues

Hello,
Im not sure if this is a feature or a request but when matching certain movies special characters get wiped instead of being replaced and that really lowers match score

example:
'Sedm pěstí - Spiritual Kung-Fu(1978)(Remastered)' -> 'sedm p st spiritual kung fu 1978 remastered'
but instead you could output
'Sedm pěstí - Spiritual Kung-Fu(1978)(Remastered)' -> 'sedm pesti spiritual kung fu 1978'

that example shows my next issue/request

remastered can be stripped from names as it does not help on lookups

Thanks again, Otherwise a great tool

media-sort not compatible with ARM architecture

I am trying to use media-sort on my raspberry pi 4, but after successful installation, when I try to run media-sort, I get the following error:

-bash: /usr/local/bin/media-sort: cannot execute binary file: Exec format error

Name Generation

For easier traversals of directories on my CLI I like to have file/directory names with '.' in place of whitespace (i.e. the.simpsons).

Is there a way to alter the 'name' variable such that whitespace is replaced by another character?

Example of Plex-compatible directory structure?

Hello,

I'm not familiar with go templating syntax. Could you provide an example for generating a Plex-compatible directory structure?

I'm passing "{{ .Name }}/{{ .Name }} S{{ printf \"%02d\" .Season }}E{{ printf \"%02d\" .Episode }}" but slashes are converted to -.

SNAP Package

Hi there, do you have any interest in offering a snap package? If so, I can assist in getting one build and wiring it up to your repo to auto-build, etc.

Regards,

Dustin

Recursively search for subtitles

Some movies when packages keep their subtitles in a Subs directory, especially those packaged by RARBG, for example:

ls Hotel.Transylvania.2012.1080p.BluRay.x265-RARBG/*
Hotel.Transylvania.2012.1080p.BluRay.x265-RARBG/Hotel.Transylvania.2012.1080p.BluRay.x265-RARBG.mp4

Hotel.Transylvania.2012.1080p.BluRay.x265-RARBG/Subs:
23_English.srt

Is it possible to give the option to recursively search for subtitle files and parse them as if they were in the movie's directory?

Copy file support

Hello there, great project really enjoying things so far.

I've noticed that when processing files the default is to move (which is fine), but I'd like an option to be able to copy files instead so I'm able to leave them seeding in my torrent client. I just plan on just skipping files that have already been processed.

Is this a possibility?

Anime filename support

Hello, me again.

I'm having an issue sorting some anime filenames, this has happened a couple of times and is caused by the naming convention some anime releases have.

An example filename would be:

[Hakata Ramen] Dr. Stone (Season 1) [1080p x265]/[Hakata Ramen] Dr. Stone 12 [1080p x265].mkv

The releaser in brackets and the lack of series number in the filename is causing the lookup to be incorrect.
If I remove the releaser and add a series number with mmv "\[Hakata Ramen\] Dr. Stone *" "Dr. Stone S01E#1" the detection works fine.

Help generating path name

Hello,

while looking for an automatic media file renamer, I came across this great command line tool. I am almost sure that I can do everything I need with this. However, the documentation is too scarce and there are too few examples.

MY wish for a movie template path:
/my/path/movies/{char}/Movie (Year)/Movie.ext

If first char of the source is one of A to Z (or a-z) then add this char, if its a digit add a hash tag # and if something else add a underscore.

I tried something like as movie template but I don't know the syntax:

/my/path/Movies/{{ if .Name[0:1] >= 'A' And .Name[0:1] <= 'Z' }} Then {{ .Name[0:1] }} Else {{ # }}/{{ .Name }} ({{ .Year }})/{{ .Name }}.{{ .Ext }}

How could this be done?
What if I need further help? Is this the right way to ask for help or is there another way I have overlooked?

Thanks in advance :-)

Kind regards
Bjoern

Folder Permissioning

Just wondering if there's a way to alter the script that generates sub-directories to have different permissions (i.e. read/write, read only, etc)

go get fails

go get -v github.com/jpillora/media-sort
go: finding github.com/jpillora/media-sort latest
go get: github.com/jpillora/[email protected] requires
        github.com/jpillora/[email protected]: invalid version: unknown revision 3f7962811f23

mediasort.invalidChars is too aggressive

Hey there.

The regular expression in charge of invalid characters removal (this one) is a bit too aggressive for some characters such as accentuated ones, cedilla, amperstand, etc.

A dummy way around would be to include these characters in the invalidChars regexp.
A prettier solution is to use the unicode character property class which seems to be included in Go regexp module.

What do you think about it?

Edit: related class is \p{L}

Search results seems poor for obvious titles

Even w/ the accurate turned way down it seems to fail for results I'd think would be pretty easy

2.4.2root@vault:/mnt/user/Media/temp# /usr/local/bin/media-sort --verbose --accuracy-threshold 50 --recursive   --overwrite-if-larger --movie-dir . .
2020/03/23 08:14:35 scanning targets...
2020/03/23 08:14:35 scanning: .
2020/03/23 08:14:35 skip non-regular file: .
2020/03/23 08:14:35 scanned targets. found #1
2020/03/23 08:14:35 sorting files...
2020/03/23 08:14:35 Searching transformers age of extinction
2020/03/23 08:14:35 [#1/1] Transformers: Age of Extinction.mp4
  └─> No results (Google search failed)
root@vault:/mnt/user/Media/temp#

I also noticed that it only appears to be searching google and not IMDB or anything... Am I doing anything wrong?

Fix go get by removing broken v2 tags

Background

The github.com/jpillora/media-sort uses Go modules and the current release version is v2. And it’s module path is "github.com/jpillora/media-sort", instead of "github.com/jpillora/media-sort/v2". It must comply with the specification of "Releasing Modules for v2 or higher" available in the Modules documentation. Quoting the specification:

A package that has opted in to modules must include the major version in the import path to import any v2+ modules
To preserve import compatibility, the go command requires that modules with major version v2 or later use a module path with that major version as the final element. For example, version v2.0.0 of example.com/m must instead use module path example.com/m/v2.
https://github.com/golang/go/wiki/Modules#releasing-modules-v2-or-higher

Steps to Reproduce

GO111MODULE=on, run go get targeting any version >= v2.3.0 of the jpillora/media-sort:

$ go get github.com/jpillora/[email protected]
go: finding github.com/jpillora/media-sort v2.3.0
go: finding github.com/jpillora/media-sort v2.3.0
go get github.com/jpillora/[email protected]: github.com/jpillora/[email protected]: invalid version: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v2

SO anyone using Go modules will not be able to easily use any newer version of jpillora/media-sort.

Solution

1. Kill the go.mod files, rolling back to GOPATH.

This would push them back to not being managed by Go modules (instead of incorrectly using Go modules).
Ensure compatibility for downstream module-aware projects and module-unaware projects projects

2. Fix module path to strictly follow SIV rules.

Patch the go.mod file to declare the module path as github.com/jpillora/media-sort/v2 as per the specs. And adjust all internal imports.
The downstream projects might be negatively affected in their building if they are module-unaware (Go versions older than 1.9.7 and 1.10.3; Or use third-party dependency management tools, such as: Dep, glide,govendor…).

If you don't want to break the above repos. This method can provides better backwards-compatibility.
Release a v2 or higher module through the major subdirectory strategy: Create a new v2 subdirectory (github.com/jpillora/media-sort/v2) and place a new go.mod file in that subdirectory. The module path must end with /v2. Copy or move the code into the v2 subdirectory. Update import statements within the module to also use /v2 (import "github.com/jpillora/media-sort/v2/…"). Tag the release with v2.x.y.

3. Suggest your downstream module users use hash instead of a version tag.

If the standard rule of go modules conflicts with your development mode. Or not intended to be used as a library and does not make any guarantees about the API. So you can’t comply with the specification of "Releasing Modules for v2 or higher" available in the Modules documentation.
Regardless, since it's against one of the design choices of Go, it'll be a bit of a hack. Instead of go get github.com/jpillora/media-sort@version-tag, module users need to use this following way to get the jpillora/media-sort:
(1) Search for the tag you want (in browser)
(2) Get the commit hash for the tag you want
(3) Run go get github.com/jpillora/media-sort@commit-hash
(4) Edit the go.mod file to put a comment about which version you actually used
This will make it difficult for module users to get and upgrade jpillora/media-sort.

Summary

You can make a choice to fix DM issues by balancing your own development schedules/mode against the affects on the downstream projects.

For this issue, Solution 2 can maximize your benefits and with minimal impacts to your downstream projects the ecosystem.

References

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.