Exemplo n.º 1
0
    def _set_subtitles_in_database(self, source, mapping):
        ''' Setup subtitles preferences in database for direct play and direct stream scenarios.
            Check path, file, get idFile to assign settings to.

            mapping originates from set_external_subs
        '''
        default = xmls.default_settings_default()
        full_path = self.info['Path']
        default['AudioStream'] = max(self.info['AudioStreamIndex'] - 1, -1)
        default['SubtitlesOn'] = int(
            self.info['SubtitleStreamIndex'] != -1
            and self.info['SubtitleStreamIndex'] is not None)

        if default['SubtitlesOn']:
            if mapping:

                for sub in mapping:

                    if mapping[sub] == self.info['SubtitleStreamIndex']:
                        default['SubtitleStream'] = sub

                        break
                else:
                    default['SubtitleStream'] = max(
                        self.info['SubtitleStreamIndex'] -
                        self._get_streams(source) + len(mapping), -1)
            else:
                default['SubtitleStream'] = max(
                    self.info['SubtitleStreamIndex'] -
                    self._get_streams(source), -1)
        else:
            default['SubtitleStream'] = -1

        if '\\' in full_path:
            path, file = full_path.rsplit('\\', 1)
            path += "\\"
        else:
            path, file = full_path.rsplit('/', 1)
            path += "/"
            file = file.split('?', 1)[0]

        LOG.debug("Finding: %s / %s", path, file)
        try:
            with database.Database('video') as kodidb:

                db = kodi.Kodi(kodidb.cursor)
                default['PathId'] = db.add_path(path)
                default['FileId'] = db.add_file(file, default['PathId'])
                db.add_settings(*values(default, QU.update_settings_obj))
                LOG.debug(default)

        except Exception:
            pass
Exemplo n.º 2
0
    def set_subtitles_in_database(self, source, mapping=None):
        ''' Setup subtitles preferences in database for direct play and direct stream scenarios.
            Check path, file, get idFile to assign settings to.

            mapping originates from set_external_subs
        '''
        try:
            if self.info['Method'] != 'DirectPlay':
                raise Exception("Unsupported")

            default = objects.utils.default_settings_default()
            full_path = self.info['Path']
            stream = {
                'AudioStream':
                max((self.info['AudioStreamIndex'] or -1) - 1, -1),
                'SubtitlesOn':
                int(self.info['SubtitleStreamIndex'] is not None
                    and self.info['SubtitleStreamIndex'] != -1)
            }
            if stream['SubtitlesOn']:
                if mapping:

                    for sub in mapping:

                        if mapping[sub] == self.info['SubtitleStreamIndex']:
                            stream['SubtitleStream'] = sub

                            break
                    else:
                        stream['SubtitleStream'] = max(
                            self.info['SubtitleStreamIndex'] -
                            self._get_streams(source) + len(mapping), -1)
                else:
                    stream['SubtitleStream'] = max(
                        self.info['SubtitleStreamIndex'] -
                        self._get_streams(source), -1)
            else:
                stream['SubtitleStream'] = -1

            if '\\' in full_path:
                path, file = full_path.rsplit('\\', 1)
                path += "\\"
            else:
                path, file = full_path.rsplit('/', 1)
                path += "/"
                file = file.split('?', 1)[0]

            LOG.debug("Finding: %s / %s", path, file)

            with database.Database('video') as kodidb:

                db = kodi.Kodi(kodidb.cursor)
                stream['PathId'] = db.add_path(path)
                stream['FileId'] = db.add_file(file, stream['PathId'])
                current = db.get_settings(stream['FileId'])

                if current:
                    current = list(current)
                    current.pop(6)
                    current.insert(6, stream['AudioStream'])
                    current.pop(7)
                    current.insert(7, stream['SubtitleStream'])
                    current.pop(9)
                    current.insert(9, stream['SubtitlesOn'])
                    db.add_settings(*current)
                elif not default:
                    raise Exception("Default values not found")
                else:
                    default.update(stream)
                    db.add_settings(*values(default, QU.update_settings_obj))

            self.info['Item']['PlaybackInfo']['AutoSwitched'] = True
        except Exception:
            self.info['Item']['PlaybackInfo']['AutoSwitched'] = False