Example #1
0
import os
from pyexpander.log import get_logger


logger = get_logger('transmission')


def get_environmental_variables_from_transmission():
    """
    Return the environmental variables passed by tranmission to the script.

    :return: (full_torrent_path, torrent_name)
    """
    torrent_dir = os.getenv('TR_TORRENT_DIR')
    torrent_name = os.getenv('TR_TORRENT_NAME')

    if torrent_dir is None or torrent_name is None:
        raise Exception('Transmission environment variables were not found.')

    full_path = os.path.join(torrent_dir, torrent_name)

    logger.info('Called from transmission with torrent %s' % full_path)

    return full_path

Example #2
0
#!/usr/local/bin/python2.7
import os
import sys
import shutil

from pyexpander.extract import extract_all, cleanup_temp
from pyexpander.log import get_logger
from pyexpander.postprocess import process_folder, process_file
from pyexpander.transmission import get_environmental_variables_from_transmission


logger = get_logger('handler')


def expand_torrent(torrent_path):
    logger.info('Processing torrent %s' % torrent_path)
    torrent_path = os.path.abspath(torrent_path)

    if os.path.isdir(torrent_path):
        torrent_path = os.path.join(torrent_path, '')
        extract_all(torrent_path)
        process_folder(torrent_path)
        cleanup_temp(torrent_path)
    else:
        process_file(shutil.copy, os.path.splitext(os.path.basename(torrent_path))[0], torrent_path)

    logger.info('Done')


def expand_torrent_from_transmission():
    """
Example #3
0
import shutil
import os
import re
import subprocess
import itertools
from pyexpander import config
from pyexpander.log import get_logger


logger = get_logger('extractor')


ARCHIVE_EXTENSIONS = ['.rar', '.zip', '.7z']


def _extract(archive_path, destination):
    """
    Extract archive content to destination
    :param  archive_path:
    :type archive_path: str
    :param  destination:
    :type destination: str
    """
    # 'e': extract to current working dir
    # '-y': assume yes to all (overwrite)
    process_info = [config.EXECUTABLE, 'e', '-y', archive_path]

    logger.debug('Running %r' % process_info)

    # Change current working directory since 7Zip only works with e flag.
    output = subprocess.check_output(process_info, cwd=destination)
Example #4
0
import os
import errno
import shutil
import subprocess

from pyexpander import config
from pyexpander.categorize import get_categorized_path
from pyexpander.log import get_logger


logger = get_logger('postprocess')


def _create_extraction_path(directory_path):
    """
    Verifies that current path exists - if not, creates the path.

    :param directory_path:
    :type directory_path: str, unicode
    """
    if not os.path.exists(directory_path):
        try:
            os.makedirs(directory_path)
            logger.info("Creating directory %s" % directory_path)

        except OSError as e:
            if e.errno != errno.EEXIST:
                logger.exception("Failed to create directory %s" % directory_path, e)
                raise
            pass
Example #5
0
#!/usr/bin/python
import logging
import os
import sys

from pyexpander.extract import extract_all, cleanup_temp
from pyexpander.log import get_logger
from pyexpander.postprocess import process_folder
from pyexpander.transmission import get_environmental_variables_from_transmission

logger = get_logger('handler')


def expand_torrent(torrent_path):
    torrent_path = os.path.join(torrent_path, '')
    logger.info('Processing torrent %s' % torrent_path)

    extract_all(torrent_path)
    process_folder(torrent_path)
    cleanup_temp(torrent_path)

    logger.info('Done')


def expand_torrent_from_transmission():
    """
    This main function is designed to be called by transmission.
    """
    torrent_path = get_environmental_variables_from_transmission()

    expand_torrent(torrent_path)
Example #6
0
import sys
import os
import errno
import shutil
import subprocess

from pyexpander import config
from pyexpander.categorize import get_categorized_path
from pyexpander.log import get_logger

logger = get_logger('post_process')


def _create_extraction_path(directory_path):
    """
    Verifies that current path exists - if not, creates the path.

    :param directory_path:
    :type directory_path: str, unicode
    """
    if not os.path.exists(directory_path):
        try:
            os.makedirs(directory_path)
            logger.info("Creating directory %s" % directory_path)

        except OSError as e:
            if e.errno != errno.EEXIST:
                logger.exception(
                    "Failed to create directory %s" % directory_path, e)
                raise
            pass
Example #7
0
import os
import guessit

from pyexpander import config
from pyexpander.log import get_logger


logger = get_logger('categorize')


MUSIC_EXTENSIONS = ['.flac', '.mp3', '.ogg', '.wav']
SOFTWARE_EXTENSIONS = ['.iso', '.exe']


def get_path_video(filename):
    guess = guessit.guess_video_info(filename)

    if guess[u'type'] == u'episode':
        series = guess.get(u'series', u'').title()
        season = guess.get(u'season', u'')

        return config.TV_PATH.format(series=series, season=season)
    elif guess[u'type'] == u'movie':
        title = guess.get(u'title', u'').title()
        year = guess.get(u'year', u'')

        return config.MOVIE_PATH.format(title=title, year=year)
    else:
        return None

Example #8
0
import shutil
import os
import re
import subprocess
import itertools
from pyexpander import config
from pyexpander.log import get_logger

logger = get_logger('extractor')

ARCHIVE_EXTENSIONS = ['.rar', '.zip', '.7z']


def _extract(archive_path, destination):
    """
    Extract archive content to destination
    :param  archive_path:
    :type archive_path: str
    :param  destination:
    :type destination: str
    """
    # 'e': extract to current working dir
    # '-y': assume yes to all (overwrite)
    process_info = [config.EXECUTABLE, 'e', '-y', archive_path]

    logger.debug('Running %r' % process_info)

    # Change current working directory since 7Zip only works with e flag.
    output = subprocess.check_output(process_info, cwd=destination)

    logger.debug('Output: %s' % output)
Example #9
0
import os
from pyexpander.log import get_logger

logger = get_logger('transmission')


def get_environmental_variables_from_transmission():
    """
    Return the environmental variables passed by tranmission to the script.

    :return: (full_torrent_path, torrent_name)
    """
    torrent_dir = os.getenv('TR_TORRENT_DIR')
    torrent_name = os.getenv('TR_TORRENT_NAME')

    if torrent_dir is None or torrent_name is None:
        raise Exception('Transmission environment variables were not found.')

    full_path = os.path.realpath(os.path.join(torrent_dir, torrent_name))

    logger.info('Called from transmission with torrent %s' % full_path)

    return full_path
Example #10
0
#!/usr/bin/env python

# rename and move a list of files to their appropriate directory

import re, os
import errno
import shutil
import subprocess
from pyexpander import config
from pyexpander import categorize
from pyexpander.log import get_logger
from pyexpander import postprocess
logger = get_logger('rename')

def gen_files(path, glob):
    pattern = re.compile(glob)
    for root, dirs, files in os.walk(path):
        for f in files:
            if pattern.search(f):
                fullpath = os.path.join(root,f)
                filename, filextention = os.path.splitext(fullpath)
                yield fullpath



if __name__== "__main__":

    stats = {}
    mem_used = {}
    for origpath in gen_files("/mnt/usb/Downloads/complete/Orphan.Black.S01.720p.HDTV.x264-FF/_extracted/unpacked_1/", "mkv"):
        destpath = categorize.get_categorized_path(origpath)