<commit_before>"""
MakeMKV CLI Wrapper

This class acts as a python wrapper to the MakeMKV CLI.


Released under the MIT license
Copyright (c) 2012, <NAME>

@category   misc
@version    $Id: 1.2, 2013-01-20 11:08:00 CST $;
@author     <NAME> <<EMAIL>>
@license    http://opensource.org/licenses/MIT
"""

#
#   IMPORTS
#

import commands
import imdb
import os
import re

#
#   CODE
#


class makeMKV(object):

    def __init__(self):
        self.movieName = ""
        self.imdbScaper = imdb.IMDb()

    def _queueMovie(self):
        home = os.path.expanduser("~")
        if os.path.exists('%s/.makemkvautoripper' % home) == False:
            os.makedirs('%s/.makemkvautoripper' % home)

        os.chdir('%s/%s' % (self.path, self.movieName))
        for files in os.listdir("."):
            if files.endswith(".mkv"):
                movie = files
                break

        with open("%s/.makemkvautoripper/queue" % home, "a+") as myfile:
            myfile.write("%s|%s|%s|%s.mkv\n"
                %
                (self.path, self.movieName, movie, self.movieName))

    def _cleanTitle(self):
        tmpName = self.movieName
        # A little fix for extended editions (eg; Die Hard 4)
        tmpName = tmpName.title().replace("Extended_Edition", "")

        # Remove Special Edition
        tmpName = tmpName.replace("Special_Edition", "")

        # Remove Disc X from the title
        tmpName = re.sub(r"Disc_(\d)", "", tmpName)

        # Clean up the disc title so IMDb can identify it easier
        tmpName = tmpName.replace("\"", "").replace("_", " ")

        # Clean up the edges and remove whitespace
        self.movieName = tmpName.strip()

    def ripDisc(self, path, length, cache, queue):
        self.path = path
        # Start the making of the mkv
        commands.getstatusoutput(
            'makemkvcon mkv disc:%s 0 "%s/%s" --cache=%d --noscan --minlength=%d'
            %
            (self.discIndex, self.path, self.movieName, cache, length))

        # Add some checking here
        # Seriously, check to see if makemkv worked like it should :(
        if queue:
            self._queueMovie()
        return True

    def findDisc(self, output):
        # Execute the info gathering
        # Save output into /tmp/ for interpreting 3 or 4 lines later
        commands.getstatusoutput('makemkvcon -r info > %s' % output)

        # Open the info file from /tmp/
        tempFile = open(output, 'r')
        for line in tempFile.readlines():
            if line[:4] == "DRV:":
                if "/dev/" in line:
                    drive = line.split(',')
                    self.discIndex = drive[0].replace("DRV:", "")
                    self.movieName = drive[5]
                    break

        if len(self.discIndex) == 0:
            print "No disc detected"
            return False
        else:
            print "Disc detected in drive %s" % self.discIndex
            return True

    def getTitle(self):
        self._cleanTitle()

        result = self.imdbScaper.search_movie(self.movieName, results=1)

        if len(result) > 0:
            self.movieName = result[0]<commit_msg>Commiting before the big file change<commit_after>"""
MakeMKV CLI Wrapper

This class acts as a python wrapper to the MakeMKV CLI.


Released under the MIT license
Copyright (c) 2012, <NAME>

@category   misc
@version    $Id: 1.2, 2013-01-20 11:08:00 CST $;
@author     <NAME> <<EMAIL>>
@license    http://opensource.org/licenses/MIT
"""

#
#   IMPORTS
#

import commands
import imdb
import os
import re

#
#   CODE
#


class makeMKV(object):

    """ Function:   __init__
            Removes the log file and the input movie because these files are
                no longer needed by this script

        Inputs:
            log         (Str): File path of the log to remove
            oldMovie    (Str): File path of the movie to remove

        Outputs:
            None
    """
    def __init__(self):
        self.movieName = ""
        self.imdbScaper = imdb.IMDb()

    """ Function:   _queueMovie
            Removes the log file and the input movie because these files are
                no longer needed by this script

        Inputs:
            log         (Str): File path of the log to remove
            oldMovie    (Str): File path of the movie to remove

        Outputs:
            None
    """
    def _queueMovie(self):
        home = os.path.expanduser("~")
        if os.path.exists('%s/.makemkvautoripper' % home) == False:
            os.makedirs('%s/.makemkvautoripper' % home)

        os.chdir('%s/%s' % (self.path, self.movieName))
        for files in os.listdir("."):
            if files.endswith(".mkv"):
                movie = files
                break

        with open("%s/.makemkvautoripper/queue" % home, "a+") as myfile:
            myfile.write("%s|%s|%s|%s.mkv\n"
                %
                (self.path, self.movieName, movie, self.movieName))

    """ Function:   _cleanTitle
            Removes the log file and the input movie because these files are
                no longer needed by this script

        Inputs:
            log         (Str): File path of the log to remove
            oldMovie    (Str): File path of the movie to remove

        Outputs:
            None
    """
    def _cleanTitle(self):
        tmpName = self.movieName
        # A little fix for extended editions (eg; Die Hard 4)
        tmpName = tmpName.title().replace("Extended_Edition", "")

        # Remove Special Edition
        tmpName = tmpName.replace("Special_Edition", "")

        # Remove Disc X from the title
        tmpName = re.sub(r"Disc_(\d)", "", tmpName)

        # Clean up the disc title so IMDb can identify it easier
        tmpName = tmpName.replace("\"", "").replace("_", " ")

        # Clean up the edges and remove whitespace
        self.movieName = tmpName.strip()

    """ Function:   ripDisc
            Removes the log file and the input movie because these files are
                no longer needed by this script

        Inputs:
            log         (Str): File path of the log to remove
            oldMovie    (Str): File path of the movie to remove

        Outputs:
            None
    """
    def ripDisc(self, path, length, cache, queue):
        self.path = path
        # Start the making of the mkv
        commands.getstatusoutput(
            'makemkvcon mkv disc:%s 0 "%s/%s" --cache=%d --noscan --minlength=%d'
            %
            (self.discIndex, self.path, self.movieName, cache, length))

        # Add some checking here
        # Seriously, check to see if makemkv worked like it should :(
        if queue:
            self._queueMovie()
        return True

    """ Function:   findDisc
            Removes the log file and the input movie because these files are
                no longer needed by this script

        Inputs:
            log         (Str): File path of the log to remove
            oldMovie    (Str): File path of the movie to remove

        Outputs:
            None
    """
    def findDisc(self, output):
        # Execute the info gathering
        # Save output into /tmp/ for interpreting 3 or 4 lines later
        commands.getstatusoutput('makemkvcon -r info > %s' % output)

        # Open the info file from /tmp/
        tempFile = open(output, 'r')
        for line in tempFile.readlines():
            if line[:4] == "DRV:":
                if "/dev/" in line:
                    drive = line.split(',')
                    self.discIndex = drive[0].replace("DRV:", "")
                    self.movieName = drive[5]
                    break

        if len(self.discIndex) == 0:
            print "No disc detected"
            return False
        else:
            print "Disc detected in drive %s" % self.discIndex
            return True

    """ Function:   getTitle
            Removes the log file and the input movie because these files are
                no longer needed by this script

        Inputs:
            log         (Str): File path of the log to remove
            oldMovie    (Str): File path of the movie to remove

        Outputs:
            None
    """
    def getTitle(self):
        self._cleanTitle()

        result = self.imdbScaper.search_movie(self.movieName, results=1)

        if len(result) > 0:
            self.movieName = result[0]
{'fraction_non_alphanumeric': 0.1032258064516129, 'fraction_numerical': 0.007407407407407408, 'mean_word_length': 1.7608839050131926, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6561495', 'n_tokens_mistral': 2534, 'n_tokens_neox': 2335, 'n_words': 784}