Skip to content

Commit

Permalink
Merge v12.1.00
Browse files Browse the repository at this point in the history
  • Loading branch information
clinton-hall committed Aug 6, 2019
2 parents 95e4c70 + ccfc3c1 commit e165bbc
Show file tree
Hide file tree
Showing 74 changed files with 1,615 additions and 443 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 12.0.10
current_version = 12.1.00
commit = True
tag = False

Expand Down
77 changes: 34 additions & 43 deletions TorrentToMedia.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
#!/usr/bin/env python
# coding=utf-8

import eol
eol.check()

import cleanup
cleanup.clean(cleanup.FOLDER_STRUCTURE)
from __future__ import (
absolute_import,
division,
print_function,
unicode_literals,
)

import datetime
import os
import sys

import eol
import cleanup
eol.check()
cleanup.clean(cleanup.FOLDER_STRUCTURE)

import core
from core import logger, main_db
from core.auto_process import comics, games, movies, music, tv
from core.auto_process import comics, games, movies, music, tv, books
from core.auto_process.common import ProcessResult
from core.plugins.plex import plex_update
from core.user_scripts import external_script
from core.utils import char_replace, convert_to_ascii, replace_links
from six import text_type

try:
text_type = unicode
except NameError:
text_type = str


def process_torrent(input_directory, input_name, input_category, input_hash, input_id, client_agent):
Expand Down Expand Up @@ -60,30 +70,25 @@ def process_torrent(input_directory, input_name, input_category, input_hash, inp
input_category = 'UNCAT'

usercat = input_category
try:
input_name = input_name.encode(core.SYS_ENCODING)
except UnicodeError:
pass
try:
input_directory = input_directory.encode(core.SYS_ENCODING)
except UnicodeError:
pass

logger.debug('Determined Directory: {0} | Name: {1} | Category: {2}'.format
(input_directory, input_name, input_category))

# auto-detect section
section = core.CFG.findsection(input_category).isenabled()
if section is None:
section = core.CFG.findsection('ALL').isenabled()
if section is None:
logger.error('Category:[{0}] is not defined or is not enabled. '
'Please rename it or ensure it is enabled for the appropriate section '
'in your autoProcessMedia.cfg and try again.'.format
(input_category))
return [-1, '']
if section is None: #Check for user_scripts for 'ALL' and 'UNCAT'
if usercat in core.CATEGORIES:
section = core.CFG.findsection('ALL').isenabled()
usercat = 'ALL'
else:
usercat = 'ALL'
section = core.CFG.findsection('UNCAT').isenabled()
usercat = 'UNCAT'
if section is None: # We haven't found any categories to process.
logger.error('Category:[{0}] is not defined or is not enabled. '
'Please rename it or ensure it is enabled for the appropriate section '
'in your autoProcessMedia.cfg and try again.'.format
(input_category))
return [-1, '']

if len(section) > 1:
logger.error('Category:[{0}] is not unique, {1} are using it. '
Expand All @@ -106,7 +111,7 @@ def process_torrent(input_directory, input_name, input_category, input_hash, inp
torrent_no_link = int(section.get('Torrent_NoLink', 0))
keep_archive = int(section.get('keep_archive', 0))
extract = int(section.get('extract', 0))
extensions = section.get('user_script_mediaExtensions', '').lower().split(',')
extensions = section.get('user_script_mediaExtensions', '')
unique_path = int(section.get('unique_path', 1))

if client_agent != 'manual':
Expand All @@ -125,10 +130,6 @@ def process_torrent(input_directory, input_name, input_category, input_hash, inp
else:
output_destination = os.path.normpath(
core.os.path.join(core.OUTPUT_DIRECTORY, input_category))
try:
output_destination = output_destination.encode(core.SYS_ENCODING)
except UnicodeError:
pass

if output_destination in input_directory:
output_destination = input_directory
Expand Down Expand Up @@ -170,10 +171,6 @@ def process_torrent(input_directory, input_name, input_category, input_hash, inp
core.os.path.join(output_destination, os.path.basename(file_path)), full_file_name)
logger.debug('Setting outputDestination to {0} to preserve folder structure'.format
(os.path.dirname(target_file)))
try:
target_file = target_file.encode(core.SYS_ENCODING)
except UnicodeError:
pass
if root == 1:
if not found_file:
logger.debug('Looking for {0} in: {1}'.format(input_name, inputFile))
Expand Down Expand Up @@ -256,6 +253,8 @@ def process_torrent(input_directory, input_name, input_category, input_hash, inp
result = comics.process(section_name, output_destination, input_name, status, client_agent, input_category)
elif section_name == 'Gamez':
result = games.process(section_name, output_destination, input_name, status, client_agent, input_category)
elif section_name == 'LazyLibrarian':
result = books.process(section_name, output_destination, input_name, status, client_agent, input_category)

plex_update(input_category)

Expand All @@ -276,13 +275,13 @@ def process_torrent(input_directory, input_name, input_category, input_hash, inp
# remove torrent
if core.USE_LINK == 'move-sym' and not core.DELETE_ORIGINAL == 1:
logger.debug('Checking for sym-links to re-direct in: {0}'.format(input_directory))
for dirpath, dirs, files in os.walk(input_directory):
for dirpath, _, files in os.walk(input_directory):
for file in files:
logger.debug('Checking symlink: {0}'.format(os.path.join(dirpath, file)))
replace_links(os.path.join(dirpath, file))
core.remove_torrent(client_agent, input_hash, input_id, input_name)

if not section_name == 'UserScript':
if section_name != 'UserScript':
# for user script, we assume this is cleaned by the script or option USER_SCRIPT_CLEAN
# cleanup our processing folders of any misc unwanted files and empty directories
core.clean_dir(output_destination, section_name, input_category)
Expand Down Expand Up @@ -350,15 +349,7 @@ def main(args):
if client_agent.lower() not in core.TORRENT_CLIENTS:
continue

try:
dir_name = dir_name.encode(core.SYS_ENCODING)
except UnicodeError:
pass
input_name = os.path.basename(dir_name)
try:
input_name = input_name.encode(core.SYS_ENCODING)
except UnicodeError:
pass

results = process_torrent(dir_name, input_name, subsection, input_hash or None, input_id or None,
client_agent)
Expand Down
35 changes: 32 additions & 3 deletions autoProcessMedia.cfg.spec
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
[Posix]
### Process priority setting for External commands (Extractor and Transcoder) on Posix (Unix/Linux/OSX) systems.
# Set the Niceness value for the nice command. These range from -20 (most favorable to the process) to 19 (least favorable to the process).
niceness = 0
# If entering an integer e.g 'niceness = 4', this is added to the nice command and passed as 'nice -n4' (Default).
# If entering a comma separated list e.g. 'niceness = nice,4' this will be passed as 'nice 4' (Safer).
niceness = nice,-n0
# Set the ionice scheduling class. 0 for none, 1 for real time, 2 for best-effort, 3 for idle.
ionice_class = 0
# Set the ionice scheduling class data. This defines the class data, if the class accepts an argument. For real time and best-effort, 0-7 is valid data.
Expand Down Expand Up @@ -282,6 +284,31 @@
##### Set to path where download client places completed downloads locally for this category
watch_dir =

[LazyLibrarian]
#### autoProcessing for LazyLibrarian
#### books - category that gets called for post-processing with LazyLibrarian
[[books]]
enabled = 0
apikey =
host = localhost
port = 5299
###### ADVANCED USE - ONLY EDIT IF YOU KNOW WHAT YOU'RE DOING ######
ssl = 0
web_root =
# Enable/Disable linking for Torrents
Torrent_NoLink = 0
keep_archive = 1
extract = 1
# Set this to minimum required size to consider a media file valid (in MB)
minSize = 0
# Enable/Disable deleting ignored files (samples and invalid media files)
delete_ignored = 0
##### Enable if LazyLibrarian is on a remote server for this category
remote_path = 0
##### Set to path where download client places completed downloads locally for this category
watch_dir =


[Network]
# Enter Mount points as LocalPath,RemotePath and separate each pair with '|'
# e.g. MountPoints = /volume1/Public/,E:\|/volume2/share/,\\NAS\
Expand Down Expand Up @@ -389,11 +416,13 @@
externalSubDir =
# hwAccel. 1 will set ffmpeg to enable hardware acceleration (this requires a recent ffmpeg)
hwAccel = 0
# generalOptions. Enter your additional ffmpeg options here with commas to separate each option/value (i.e replace spaces with commas).
# generalOptions. Enter your additional ffmpeg options (these insert before the '-i' input files) here with commas to separate each option/value (i.e replace spaces with commas).
generalOptions =
# otherOptions. Enter your additional ffmpeg options (these insert after the '-i' input files and before the output file) here with commas to separate each option/value (i.e replace spaces with commas).
otherOptions =
# outputDefault. Loads default configs for the selected device. The remaining options below are ignored.
# If you want to use your own profile, leave this blank and set the remaining options below.
# outputDefault profiles allowed: iPad, iPad-1080p, iPad-720p, Apple-TV2, iPod, iPhone, PS3, xbox, Roku-1080p, Roku-720p, Roku-480p, mkv, mp4-scene-release
# outputDefault profiles allowed: iPad, iPad-1080p, iPad-720p, Apple-TV2, iPod, iPhone, PS3, xbox, Roku-1080p, Roku-720p, Roku-480p, mkv, mkv-bluray, mp4-scene-release
outputDefault =
#### Define custom settings below.
outputVideoExtension = .mp4
Expand Down
46 changes: 46 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,42 @@ jobs:
maxParallel: 4

steps:
#- script: |
# Make sure all packages are pulled from latest
#sudo apt-get update

# Fail out if any setups fail
#set -e

# Delete old Pythons
#rm -rf $AGENT_TOOLSDIRECTORY/Python/2.7.16
#rm -rf $AGENT_TOOLSDIRECTORY/Python/3.5.7
#rm -rf $AGENT_TOOLSDIRECTORY/Python/3.7.3

# Download new Pythons
#azcopy --recursive \
#--source https://vstsagenttools.blob.core.windows.net/tools/hostedtoolcache/linux/Python/2.7.15 \
#--destination $AGENT_TOOLSDIRECTORY/Python/2.7.15

#azcopy --recursive \
#--source https://vstsagenttools.blob.core.windows.net/tools/hostedtoolcache/linux/Python/3.5.5 \
#--destination $AGENT_TOOLSDIRECTORY/Python/3.5.5

#azcopy --recursive \
#--source https://vstsagenttools.blob.core.windows.net/tools/hostedtoolcache/linux/Python/3.7.2 \
#--destination $AGENT_TOOLSDIRECTORY/Python/3.7.2

# Install new Pythons
#original_directory=$PWD
#setups=$(find $AGENT_TOOLSDIRECTORY/Python -name setup.sh)
#for setup in $setups; do
#chmod +x $setup;
#cd $(dirname $setup);
#./$(basename $setup);
#cd $original_directory;
#done;
#displayName: 'Workaround: update apt and roll back Python versions'

- task: UsePythonVersion@0
inputs:
versionSpec: '$(python.version)'
Expand All @@ -32,11 +68,21 @@ jobs:
- script: python -m pip install --upgrade pip
displayName: 'Install dependencies'

- script: sudo apt-get install ffmpeg
displayName: 'Install ffmpeg'

- script: |
pip install pytest
pytest tests --doctest-modules --junitxml=junit/test-results.xml
displayName: 'pytest'
- script: |
rm -rf .git
python cleanup.py
python TorrentToMedia.py
python nzbToMedia.py
displayName: 'Test source install cleanup'
- task: PublishTestResults@2
inputs:
testResultsFiles: '**/test-results.xml'
Expand Down
10 changes: 8 additions & 2 deletions cleanup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/usr/bin/env python

from __future__ import print_function
from __future__ import (
absolute_import,
division,
print_function,
unicode_literals,
)

import os
import subprocess
Expand All @@ -25,6 +30,7 @@

class WorkingDirectory(object):
"""Context manager for changing current working directory."""

def __init__(self, new, original=None):
self.working_directory = new
self.original_directory = os.getcwd() if original is None else original
Expand All @@ -43,7 +49,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
original_directory=self.original_directory,
error=error,
working_directory=self.working_directory,
)
),
)


Expand Down
Loading

0 comments on commit e165bbc

Please sign in to comment.