Skip to content

Commit

Permalink
completion: is_movie check
Browse files Browse the repository at this point in the history
  • Loading branch information
pyroscope committed Aug 22, 2017
1 parent d67f6f8 commit d126133
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
27 changes: 26 additions & 1 deletion docs/examples/completion-path.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,36 @@ set_target_path() {
*hdtv*|*pdtv*) target="TV" ;;
*.s[0-9][0-9].*) target="TV" ;;
*.s[0-9][0-9]e[0-9][0-9].*) target="TV" ;;
*rip.x264*) target="Movies/$month" ;;
*pdf|*epub|*ebook*) target="eBooks/$month" ;;
esac

test -z "$target" && is_movie "$name" && target="Movies/$month" || :
} # set_target_path


is_movie() {
python - "$@" <<'EOF'
import re
import sys
pattern = re.compile(
r"^(?P<title>.+?)[. ](?P<year>\d{4})"
r"(?:[._ ](?P<release>UNRATED|REPACK|INTERNAL|PROPER|LIMITED|RERiP))*"
r"(?:[._ ](?P<format>480p|576p|720p|1080p|1080i|2160p))?"
r"(?:[._ ](?P<source>BDRip|BRRip|HDRip|DVDRip|PAL|NTSC|WebRip|WEB-DL|Blu-ray|BluRay|BD25|BD50))"
r"(?:[._ ](?P<sound1>MP3|AC3|AAC|FLAC|DTS(?:-HD)?))?"
r"(?:[._ ](?P<codec>xvid|divx|avc|x264|hevc|h265))"
r"(?:[._ ](?P<sound2>MP3|AC3|AAC|FLAC|DTS(?:-HD)?))?"
r"(?:[-.](?P<group>.+?))"
r"(?P<extension>\.avi|\.mkv|\.m4v)?$", re.I
)
title = ' '.join(sys.argv[1:])
sys.exit(not pattern.match(title))
EOF
} # is_movie


# Print installation instructions when called with "-h"
if test "$1" = "-h" -o "$1" = "--help"; then
echo "$(basename $0) – Determine a dynamic rTorrent completion path"
Expand Down
13 changes: 12 additions & 1 deletion docs/use-cases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,18 @@ of the script:
Change it according to your preferences. If you don't assign a value to ``target``,
the item is not moved and remains in its default download location for later manual moving.

The script needs these commands added to your ``rtorrent.rc`` or
The ``is_movie`` helper function uses an inline Python script to check for
typical names of movie releases using a regular expression:

.. literalinclude:: examples/completion-path.sh
:language: python
:start-after: python -
:end-before: EOF

The ``is_movie`` check is done *after* the more reliable name checks.

For the script to be called and used as part of completion moving,
these commands need to be added to your ``rtorrent.rc`` or
``config.d/move_on_completion.rc`` (see :ref:`drop-in-config` on how to get a ``config.d`` directory):

.. literalinclude:: examples/completion-path.sh
Expand Down

0 comments on commit d126133

Please sign in to comment.