Пример #1
0
    def get_disc_info(self):
        """
            Returns information about the selected disc

            Inputs:
                None

            Outputs:
                None
        """

        cmd = [
            '%smakemkvcon' % self.makemkvconPath, '-r', 'info',
            'disc:%d' % self.discIndex,
            '--minlength=%d' % self.minLength,
            '--messages=%s' % self.makemkvMessages
        ]

        if self.threaded is True:
            (errors, results, returncode) = guihelper.streamingsubprocess(
                cmd, self.outHandle,
                QtCore.SIGNAL('shell_line(PyQt_PyObject)'))
        else:
            proc = subprocess.Popen(cmd,
                                    stderr=subprocess.PIPE,
                                    stdout=subprocess.PIPE)

            (results, errors) = proc.communicate()
            returncode = proc.returncode

        if returncode is not 0:
            self.log.error("MakeMKV (get_disc_info) returned status code: %d" %
                           returncode)

        if errors is not None:
            if len(errors) is not 0:
                self.log.error("MakeMKV encountered the following error: ")
                self.log.error(errors)
                return False

        foundtitles = int(self._read_mkv_messages("TCOUNT")[0])

        self.log.debug("MakeMKV found {} titles".format(foundtitles))

        if foundtitles > 0:
            for titleNo in set(self._read_mkv_messages("TINFO")):

                durTemp = self._read_mkv_messages("TINFO", titleNo, 9)[0]
                x = time.strptime(durTemp, '%H:%M:%S')
                titleDur = datetime.timedelta(
                    hours=x.tm_hour, minutes=x.tm_min,
                    seconds=x.tm_sec).total_seconds()

                print 'Checking titleDur and type', self.vidType, titleDur, self.maxLength

                if self.vidType == "tv" and titleDur > self.maxLength:
                    self.log.debug(
                        "Excluding Title No.: {}, Title: {}. Exceeds maxLength"
                        .format(titleNo,
                                self._read_mkv_messages("TINFO", titleNo, 27)))
                    continue

                if self.vidType == "movie" and not re.search(
                        '00',
                        self._read_mkv_messages("TINFO", titleNo, 27)[0]):
                    self.log.debug(
                        "Excluding Title No.: {}, Title: {}. Only want first title"
                        .format(titleNo,
                                self._read_mkv_messages("TINFO", titleNo, 27)))
                    continue

                self.log.debug(
                    "MakeMKV title info: Disc Title: {}, Title No.: {}, Title: {}, "
                    .format(self._read_mkv_messages("CINFO", 2), titleNo,
                            self._read_mkv_messages("TINFO", titleNo, 27)))

                title = self._read_mkv_messages("TINFO", titleNo, 27)[0]

                self.saveFiles.append({
                    'index': titleNo,
                    'title': title,
                    'dur': titleDur
                })
        else:
            pass
Пример #2
0
    def rip_disc(self, path, titleIndex):
        """
            Passes in all of the arguments to makemkvcon to start the ripping
                of the currently inserted DVD or BD

            Inputs:
                path    (Str):  Where the video will be saved to
                output  (Str):  Temp file to save output to

            Outputs:
                Success (Bool)
        """
        self.path = path

        fullpath = '%s/%s' % (self.path, self.vidName)

        cmd = [
            '%smakemkvcon' % self.makemkvconPath, 'mkv',
            'disc:%d' % self.discIndex, titleIndex, fullpath,
            '--cache=%d' % self.cacheSize, '--noscan',
            '--minlength=%d' % self.minLength
        ]

        if self.threaded is True:
            (errors, results, returncode) = guihelper.streamingsubprocess(
                cmd, self.outHandle,
                QtCore.SIGNAL('shell_line(PyQt_PyObject)'))
        else:
            proc = subprocess.Popen(cmd,
                                    stderr=subprocess.PIPE,
                                    stdout=subprocess.PIPE)

            (results, errors) = proc.communicate()
            returncode = proc.returncode

        if returncode is not 0:
            self.log.error("MakeMKV (rip_disc) returned status code: %d" %
                           returncode)

        if errors is not None:
            if len(errors) is not 0:
                self.log.error("MakeMKV encountered the following error: ")
                self.log.error(errors)
                return False

        checks = 0

        lines = results.split("\n")
        for line in lines:
            if "skipped" in line:
                continue

            badstrings = ["failed", "Fail", "error"]

            if any(x in line.lower() for x in badstrings):
                if self.ignore_region and "RPC protection" in line:
                    self.log.warn(line)
                else:
                    self.log.error(line)
                    return False

            if "Copy complete" in line:
                checks += 1

            if "titles saved" in line:
                checks += 1

        if checks >= 2:
            return True
        else:
            return False
Пример #3
0
    def find_disc(self):
        """
            Use makemkvcon to list all DVDs or BDs inserted
            If more then one disc is inserted, use the first result

            Inputs:
                output  (Str): Temp file to save output to

            Outputs:
                Success (Bool)
        """
        drives = []
        cmd = ['%smakemkvcon' % self.makemkvconPath, '-r', 'info', 'disc:-1']

        if self.threaded is True:
            (errors, results, returncode) = guihelper.streamingsubprocess(
                cmd, self.outHandle,
                QtCore.SIGNAL('shell_line(PyQt_PyObject)'))
        else:
            proc = subprocess.Popen(cmd,
                                    stderr=subprocess.PIPE,
                                    stdout=subprocess.PIPE)

            (results, errors) = proc.communicate()
            returncode = proc.returncode

        if returncode is not 0:
            self.log.error("MakeMKV (find_disc) returned status code: %d" %
                           returncode)

        if errors is not None:
            if len(errors) is not 0:
                self.log.error("MakeMKV encountered the following error: ")
                self.log.error(errors)
                return []

        if "This application version is too old." in results:
            self.log.error(
                "Your MakeMKV version is too old."
                "Please download the latest version at http://www.makemkv.com"
                " or enter a registration key to continue using MakeMKV.")

            return []

        # Passed the simple tests, now check for disk drives
        lines = results.split("\n")
        for line in lines:
            if line[:4] == "DRV:":
                if (self.os == 'Unix' and "/dev/" in line) or (self.os
                                                               == 'win32'):
                    out = line.split(',')

                    if len(str(out[5])) > 3:

                        drives.append({
                            "discIndex": out[0].replace("DRV:", ""),
                            "discTitle": out[5],
                            "location": out[6]
                        })

        return drives
Пример #4
0
    def get_disc_info(self):
        """
            Returns information about the selected disc

            Inputs:
                None

            Outputs:
                None
        """

        cmd = [
                '%smakemkvcon' % self.makemkvconPath,
                '-r',
                'info',
                'disc:%d' % self.discIndex,
                '--minlength=%d' % self.minLength,
                '--messages=%s' % self.makemkvMessages
            ]
        
        if self.threaded is True:
            (errors, results, returncode) = guihelper.streamingsubprocess(cmd, self.outHandle, QtCore.SIGNAL('shell_line(PyQt_PyObject)'))
        else:
            proc = subprocess.Popen(
                cmd,
                stderr=subprocess.PIPE,
                stdout=subprocess.PIPE
            )
            
            (results, errors) = proc.communicate()
            returncode = proc.returncode

        if returncode is not 0:
            self.log.error(
                "MakeMKV (get_disc_info) returned status code: %d" % returncode)

        if errors is not None:
            if len(errors) is not 0:
                self.log.error("MakeMKV encountered the following error: ")
                self.log.error(errors)
                return False

        foundtitles = int(self._read_mkv_messages("TCOUNT")[0])

        self.log.debug("MakeMKV found {} titles".format(foundtitles))

        if foundtitles > 0:
            for titleNo in set(self._read_mkv_messages("TINFO")):

                durTemp = self._read_mkv_messages("TINFO", titleNo, 9)[0]
                x = time.strptime(durTemp, '%H:%M:%S')
                titleDur = datetime.timedelta(
                    hours=x.tm_hour,
                    minutes=x.tm_min,
                    seconds=x.tm_sec
                ).total_seconds()

                print 'Checking titleDur and type', self.vidType, titleDur, self.maxLength

                if self.vidType == "tv" and titleDur > self.maxLength:
                    self.log.debug("Excluding Title No.: {}, Title: {}. Exceeds maxLength".format(
                        titleNo,
                        self._read_mkv_messages("TINFO", titleNo, 27)
                    ))
                    continue

                if self.vidType == "movie" and not re.search('00', self._read_mkv_messages("TINFO", titleNo, 27)[0]):
                    self.log.debug("Excluding Title No.: {}, Title: {}. Only want first title".format(
                        titleNo,
                        self._read_mkv_messages("TINFO", titleNo, 27)
                    ))
                    continue

                self.log.debug("MakeMKV title info: Disc Title: {}, Title No.: {}, Title: {}, ".format(
                    self._read_mkv_messages("CINFO", 2),
                    titleNo,
                    self._read_mkv_messages("TINFO", titleNo, 27)
                ))

                title = self._read_mkv_messages("TINFO", titleNo, 27)[0]

                self.saveFiles.append({
                    'index': titleNo,
                    'title': title,
                    'dur': titleDur
                })
        else:
            pass
Пример #5
0
    def find_disc(self):
        """
            Use makemkvcon to list all DVDs or BDs inserted
            If more then one disc is inserted, use the first result

            Inputs:
                output  (Str): Temp file to save output to

            Outputs:
                Success (Bool)
        """
        drives = []
        cmd = ['%smakemkvcon' % self.makemkvconPath, '-r', 'info', 'disc:-1']

        if self.threaded is True:
            (errors, results, returncode) = guihelper.streamingsubprocess(cmd, self.outHandle, QtCore.SIGNAL('shell_line(PyQt_PyObject)'))
        else:
            proc = subprocess.Popen(
                cmd,
                stderr=subprocess.PIPE,
                stdout=subprocess.PIPE
            )
            
            (results, errors) = proc.communicate()
            returncode = proc.returncode

        if returncode is not 0:
            self.log.error(
                "MakeMKV (find_disc) returned status code: %d" % returncode)

        if errors is not None:
            if len(errors) is not 0:
                self.log.error("MakeMKV encountered the following error: ")
                self.log.error(errors)
                return []

        if "This application version is too old." in results:
            self.log.error("Your MakeMKV version is too old."
                           "Please download the latest version at http://www.makemkv.com"
                           " or enter a registration key to continue using MakeMKV.")

            return []

        # Passed the simple tests, now check for disk drives
        lines = results.split("\n")
        for line in lines:
            if line[:4] == "DRV:":
                if (self.os == 'Unix' and "/dev/" in line) or (self.os == 'win32'):
                    out = line.split(',')

                    if len(str(out[5])) > 3:

                        drives.append(
                            {
                                "discIndex": out[0].replace("DRV:", ""),
                                "discTitle": out[5],
                                "location": out[6]
                            }
                        )

        return drives
Пример #6
0
    def rip_disc(self, path, titleIndex):
        """
            Passes in all of the arguments to makemkvcon to start the ripping
                of the currently inserted DVD or BD

            Inputs:
                path    (Str):  Where the video will be saved to
                output  (Str):  Temp file to save output to

            Outputs:
                Success (Bool)
        """
        self.path = path

        fullpath = '%s/%s' % (self.path, self.vidName)

        cmd = [
                '%smakemkvcon' % self.makemkvconPath,
                'mkv',
                'disc:%d' % self.discIndex,
                titleIndex,
                fullpath,
                '--cache=%d' % self.cacheSize,
                '--noscan',
                '--minlength=%d' % self.minLength
            ]

        if self.threaded is True:
            (errors, results, returncode) = guihelper.streamingsubprocess(cmd, self.outHandle, QtCore.SIGNAL('shell_line(PyQt_PyObject)'))
        else:
            proc = subprocess.Popen(
                cmd,
                stderr=subprocess.PIPE,
                stdout=subprocess.PIPE
            )
            
            (results, errors) = proc.communicate()
            returncode = proc.returncode

        if returncode is not 0:
            self.log.error(
                "MakeMKV (rip_disc) returned status code: %d" % returncode)

        if errors is not None:
            if len(errors) is not 0:
                self.log.error("MakeMKV encountered the following error: ")
                self.log.error(errors)
                return False

        checks = 0

        lines = results.split("\n")
        for line in lines:
            if "skipped" in line:
                continue

            badstrings = [
                "failed",
                "Fail",
                "error"
            ]

            if any(x in line.lower() for x in badstrings):
                if self.ignore_region and "RPC protection" in line:
                    self.log.warn(line)
                else:
                    self.log.error(line)
                    return False

            if "Copy complete" in line:
                checks += 1

            if "titles saved" in line:
                checks += 1

        if checks >= 2:
            return True
        else:
            return False
Пример #7
0
    def compress(self, nice, args, dbvideo, outHandle=None, threaded=False):
        """
            Passes the necessary parameters to HandBrake to start an encoding
            Assigns a nice value to allow give normal system tasks priority

            Inputs:
                nice    (Int): Priority to assign to task (nice value)
                args    (Str): All of the handbrake arguments taken from the
                                settings file
                output  (Str): File to log to. Used to see if the job completed
                                successfully

            Outputs:
                Bool    Was convertion successful
        """
        if outHandle is not None:
            print 'set out handle'
            self.outHandle = outHandle

        checks = 0

        # Check if TV show is already named
        c = re.compile('-[ ]{0,1}[0-9]{0,1}x[0-999][ ]{0,1}-')
        m = c.findall(dbvideo.vidname)

        if (dbvideo.vidtype == "tv") and m is None:
            # Query the SQLite database for similar titles (TV Shows)
            vidname = re.sub(r'D(\d)', '', dbvideo.vidname)
            vidqty = database.search_video_name(vidname)
            if vidqty == 0:
                vidname = "%sE1.%s" % (vidname, self.vformat)
            else:
                vidname = "%sE%s.%s" % (vidname, str(vidqty + 1), self.vformat)
        else:
            # ToDo: Add regex search for Rental or Rental NA at END of str
            vidname = "%s.%s" % (dbvideo.vidname, self.vformat)

        invid = "%s/%s" % (dbvideo.path, dbvideo.filename)
        outvid = "%s/%s" % (dbvideo.path, vidname)

        if self.os == 'win32':
            cmd = '{0}HandBrakeCLI.exe --verbose -i "{1}" -o "{2}" {3}'.format(
                self.compressionPath,
                invid,
                outvid,
                ' '.join(args)
            )
            
            with open(self.tmpFolder+'\\tmp.cmd', 'wb+') as f:
                f.write(cmd)

            # cmd = [self.tmpFolder+'\\tmp.cmd']

        elif self.os == 'Unix':
            cmd = 'nice -n {0} {1}HandBrakeCLI --verbose -i "{2}" -o "{3}" {4}'.format(
                nice,
                self.compressionPath,
                invid,
                outvid,
                ' '.join(args)
            )

        if threaded is True:
            print 'calling threaded subprocess'
            print cmd
            self.display('Testing Handbrake outHandle')
            (errors, results, returncode) = guihelper.streamingsubprocess(cmd, self.outHandle, QtCore.SIGNAL('shell_line(PyQt_PyObject)'))
        else:
            proc = subprocess.Popen(
                cmd,
                stderr=subprocess.PIPE,
                stdout=subprocess.PIPE,
                shell=True
            )
            
            (errors, results) = proc.communicate()
            returncode = proc.returncode
        
        self.display('{} done w/ return code {}'.format(vidname, returncode))
        if returncode is not 0:
            self.log.error(
                "HandBrakeCLI (compress) returned status code: %d" % returncode)

        if results is not None and len(results) is not 0:
            lines = results.split("\n")
            for line in lines:
                if "Encoding: task" not in line:
                    self.log.debug(line.strip())

                if "average encoding speed for job" in line:
                    checks += 1
                    self.display('Avg speed check')

                if "Encode done!" in line:
                    checks += 1
                    self.display('Encode done! check')

                if "ERROR" in line and "opening" not in line:
                    self.log.error(
                        "HandBrakeCLI encountered the following error: ")
                    self.log.error(line)
                    self.display('Handbrake error detected')

                    return False

        if checks >= 2:
            self.log.debug("HandBrakeCLI Completed successfully")
            self.display('{} info: {}'.format(vidname, 'Success!'))

            database.update_video(
                dbvideo, 6, filename="%s" % (
                    vidname
                ))

            return True
        else:
            self.display('{} info: {}'.format(vidname, 'Some error!'))
            return False
Пример #8
0
    def compress(self, nice, args, dbvideo, outHandle=None, threaded=False):
        """
            Passes the necessary parameters to HandBrake to start an encoding
            Assigns a nice value to allow give normal system tasks priority

            Inputs:
                nice    (Int): Priority to assign to task (nice value)
                args    (Str): All of the handbrake arguments taken from the
                                settings file
                output  (Str): File to log to. Used to see if the job completed
                                successfully

            Outputs:
                Bool    Was convertion successful
        """
        if outHandle is not None:
            print 'set out handle'
            self.outHandle = outHandle

        checks = 0

        # Check if TV show is already named
        c = re.compile('-[ ]{0,1}[0-9]{0,1}x[0-999][ ]{0,1}-')
        m = c.findall(dbvideo.vidname)

        if (dbvideo.vidtype == "tv") and m is None:
            # Query the SQLite database for similar titles (TV Shows)
            vidname = re.sub(r'D(\d)', '', dbvideo.vidname)
            vidqty = database.search_video_name(vidname)
            if vidqty == 0:
                vidname = "%sE1.%s" % (vidname, self.vformat)
            else:
                vidname = "%sE%s.%s" % (vidname, str(vidqty + 1), self.vformat)
        else:
            # ToDo: Add regex search for Rental or Rental NA at END of str
            vidname = "%s.%s" % (dbvideo.vidname, self.vformat)

        invid = "%s/%s" % (dbvideo.path, dbvideo.filename)
        outvid = "%s/%s" % (dbvideo.path, vidname)

        if self.os == 'win32':
            cmd = '{0}HandBrakeCLI.exe --verbose -i "{1}" -o "{2}" {3}'.format(
                self.compressionPath, invid, outvid, ' '.join(args))

            with open(self.tmpFolder + '\\tmp.cmd', 'wb+') as f:
                f.write(cmd)

            # cmd = [self.tmpFolder+'\\tmp.cmd']

        elif self.os == 'Unix':
            cmd = 'nice -n {0} {1}HandBrakeCLI --verbose -i "{2}" -o "{3}" {4}'.format(
                nice, self.compressionPath, invid, outvid, ' '.join(args))

        if threaded is True:
            print 'calling threaded subprocess'
            print cmd
            self.display('Testing Handbrake outHandle')
            (errors, results, returncode) = guihelper.streamingsubprocess(
                cmd, self.outHandle,
                QtCore.SIGNAL('shell_line(PyQt_PyObject)'))
        else:
            proc = subprocess.Popen(cmd,
                                    stderr=subprocess.PIPE,
                                    stdout=subprocess.PIPE,
                                    shell=True)

            (errors, results) = proc.communicate()
            returncode = proc.returncode

        self.display('{} done w/ return code {}'.format(vidname, returncode))
        if returncode is not 0:
            self.log.error("HandBrakeCLI (compress) returned status code: %d" %
                           returncode)

        if results is not None and len(results) is not 0:
            lines = results.split("\n")
            for line in lines:
                if "Encoding: task" not in line:
                    self.log.debug(line.strip())

                if "average encoding speed for job" in line:
                    checks += 1
                    self.display('Avg speed check')

                if "Encode done!" in line:
                    checks += 1
                    self.display('Encode done! check')

                if "ERROR" in line and "opening" not in line:
                    self.log.error(
                        "HandBrakeCLI encountered the following error: ")
                    self.log.error(line)
                    self.display('Handbrake error detected')

                    return False

        if checks >= 2:
            self.log.debug("HandBrakeCLI Completed successfully")
            self.display('{} info: {}'.format(vidname, 'Success!'))

            database.update_video(dbvideo, 6, filename="%s" % (vidname))

            return True
        else:
            self.display('{} info: {}'.format(vidname, 'Some error!'))
            return False