Exemple #1
0
    def create(self, filename):
        """
        create mmpython information about the given file
        """
        info = mmpython.Factory().create(filename)
        if info:
            thumbnail = None
            if info.has_key('thumbnail'):
                thumbnail = info.thumbnail

            info = self.simplify(info)
            name = util.getname(filename)
            if name == name.upper() and info.has_key('type') and \
                   info['type'] in ('DVD', 'VCD'):
                name = util.getname(filename.lower())
            info['title:filename'] = name

            if info.has_key('video'):
                for video in info['video']:
                    for variable in ('width', 'height', 'length', 'aspect'):
                        if video.has_key(variable) and not \
                           (info.has_key(variable) and info[variable]):
                            info[variable] = video[variable]

            if thumbnail and config.IMAGE_USE_EXIF_THUMBNAIL and config.CACHE_IMAGES:
                util.cache_image(filename, thumbnail)
            elif config.CACHE_IMAGES and info.has_key('mime') and info['mime'] and \
                     info['mime'].startswith('image'):
                util.cache_image(filename)

            return info
        return {}
Exemple #2
0
def main():
    import optparse
    parser = optparse.OptionParser()
    parser.add_option('--ignore')
    parser.add_option('--discover', action='store_true')
    parser.add_option('--full', action='store_true')
    parser.add_option('--config')
    parser.add_option('--failfast', action='store_true')
    parser.add_option("--coverage", action="store_true")
    options, args = parser.parse_args()
    FAILING_TESTS = []
    coverage = False
    if options.coverage or os.environ.get("GEVENTTEST_COVERAGE"):
        coverage = True
        # NOTE: This must be run from the greentest directory
        os.environ['COVERAGE_PROCESS_START'] = os.path.abspath(".coveragerc")
        os.environ['PYTHONPATH'] = os.path.abspath("coveragesite") + os.pathsep + os.environ.get("PYTHONPATH", "")
        # We change directory often, use an absolute path to keep all the
        # coverage files (which will have distinct suffixes because of parallel=true in .coveragerc
        # in this directory; makes them easier to combine and use with coverage report)
        os.environ['COVERAGE_FILE'] = os.path.abspath(".") + os.sep + ".coverage"
        print("Enabling coverage to", os.environ['COVERAGE_FILE'])
    if options.config:
        config = {}
        six.exec_(open(options.config).read(), config)
        FAILING_TESTS = config['FAILING_TESTS']
    tests = discover(args, options.ignore, coverage)
    if options.discover:
        for cmd, options in tests:
            print(util.getname(cmd, env=options.get('env'), setenv=options.get('setenv')))
        print('%s tests found.' % len(tests))
    else:
        run_many(tests, expected=FAILING_TESTS, failfast=options.failfast)
Exemple #3
0
def main():
    # FIXME: transition to argparse
    import optparse # pylint:disable=deprecated-module
    parser = optparse.OptionParser()
    parser.add_option('--ignore')
    parser.add_option('--discover', action='store_true')
    parser.add_option('--full', action='store_true')
    parser.add_option('--config')
    parser.add_option('--failfast', action='store_true')
    parser.add_option("--coverage", action="store_true")
    options, args = parser.parse_args()
    FAILING_TESTS = []
    coverage = False
    if options.coverage or os.environ.get("GEVENTTEST_COVERAGE"):
        coverage = True
        # NOTE: This must be run from the greentest directory
        os.environ['COVERAGE_PROCESS_START'] = os.path.abspath(".coveragerc")
        os.environ['PYTHONPATH'] = os.path.abspath("coveragesite") + os.pathsep + os.environ.get("PYTHONPATH", "")
        # We change directory often, use an absolute path to keep all the
        # coverage files (which will have distinct suffixes because of parallel=true in .coveragerc
        # in this directory; makes them easier to combine and use with coverage report)
        os.environ['COVERAGE_FILE'] = os.path.abspath(".") + os.sep + ".coverage"
        print("Enabling coverage to", os.environ['COVERAGE_FILE'])
    if options.config:
        config = {}
        six.exec_(open(options.config).read(), config)
        FAILING_TESTS = config['FAILING_TESTS']
    tests = discover(args, options.ignore, coverage)
    if options.discover:
        for cmd, options in tests:
            print(util.getname(cmd, env=options.get('env'), setenv=options.get('setenv')))
        print('%s tests found.' % len(tests))
    else:
        run_many(tests, expected=FAILING_TESTS, failfast=options.failfast)
Exemple #4
0
def main():
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('--ignore')
    parser.add_argument('--discover', action='store_true')
    parser.add_argument('--full', action='store_true')
    parser.add_argument('--config')
    parser.add_argument('--failfast', action='store_true')
    parser.add_argument("--coverage", action="store_true")
    parser.add_argument("--quiet", action="store_true")
    parser.add_argument('tests', nargs='*')
    options = parser.parse_args()
    FAILING_TESTS = []
    coverage = False
    if options.coverage or os.environ.get("GEVENTTEST_COVERAGE"):
        coverage = True
        # NOTE: This must be run from the greentest directory
        os.environ['COVERAGE_PROCESS_START'] = os.path.abspath(".coveragerc")
        os.environ['PYTHONPATH'] = os.path.abspath(
            "coveragesite") + os.pathsep + os.environ.get("PYTHONPATH", "")
        # We change directory often, use an absolute path to keep all the
        # coverage files (which will have distinct suffixes because of parallel=true in .coveragerc
        # in this directory; makes them easier to combine and use with coverage report)
        os.environ['COVERAGE_FILE'] = os.path.abspath(
            ".") + os.sep + ".coverage"
        print("Enabling coverage to", os.environ['COVERAGE_FILE'])
    if options.config:
        config = {}
        with open(options.config) as f:
            config_data = f.read()
        six.exec_(config_data, config)
        FAILING_TESTS = config['FAILING_TESTS']

    if 'PYTHONWARNINGS' not in os.environ and not sys.warnoptions:
        # Enable default warnings such as ResourceWarning.
        # On Python 3[.6], the system site.py module has
        # "open(fullname, 'rU')" which produces the warning that
        # 'U' is deprecated, so ignore warnings from site.py
        os.environ['PYTHONWARNINGS'] = 'default,ignore:::site:'
    if 'PYTHONFAULTHANDLER' not in os.environ:
        os.environ['PYTHONFAULTHANDLER'] = 'true'

    if 'GEVENT_DEBUG' not in os.environ:
        os.environ['GEVENT_DEBUG'] = 'error'

    tests = discover(options.tests, options.ignore, coverage)
    if options.discover:
        for cmd, options in tests:
            print(
                util.getname(cmd,
                             env=options.get('env'),
                             setenv=options.get('setenv')))
        print('%s tests found.' % len(tests))
    else:
        run_many(tests,
                 expected=FAILING_TESTS,
                 failfast=options.failfast,
                 quiet=options.quiet)
Exemple #5
0
    def create(self, filename):
        """
        create mmpython information about the given file
        """
        data = os.path.split(filename)
        if len(data) == 2:
            if data[1] == '.directory':
                filename = data[0]

        info = mmpython.parse(filename)

        if info:
            thumbnail = None
            if info.has_key('thumbnail'):
                thumbnail = info.thumbnail

            info = self.simplify(info)

            name = util.getname(filename)
            if name == name.upper() and info.has_key('type') and \
                   info['type'] in ('DVD', 'VCD'):
                name = util.getname(filename.lower())
            info['title:filename'] = name

            if info.has_key('video'):
                for video in info['video']:
                    for variable in ('width', 'height', 'length', 'aspect', 'fps'):
                        if video.has_key(variable) and not \
                           (info.has_key(variable) and info[variable]):
                            info[variable] = video[variable]

            if thumbnail and config.IMAGE_USE_EXIF_THUMBNAIL and config.CACHE_IMAGES:
                util.cache_image(filename, thumbnail)
            elif config.CACHE_IMAGES and info.has_key('mime') and info['mime'] and \
                     info['mime'].startswith('image'):
                util.cache_image(filename)
            if info.has_key('media') and info['media'] == 'MEDIA_DIRECTORY':
                pass

            info = self.normalize(info)
            return info

        return {}
Exemple #6
0
def main():
    import optparse
    parser = optparse.OptionParser()
    parser.add_option('--ignore')
    parser.add_option('--discover', action='store_true')
    parser.add_option('--full', action='store_true')
    parser.add_option('--expected')
    parser.add_option('--failfast', action='store_true')
    options, args = parser.parse_args()
    options.expected = load_list_from_file(options.expected)
    if options.full:
        assert options.ignore is None, '--ignore and --full are not compatible'
        tests = full(args)
    else:
        tests = discover(args, options.ignore)
    if options.discover:
        for cmd, options in tests:
            print util.getname(cmd, env=options.get('env'), setenv=options.get('setenv'))
        print '%s tests found.' % len(tests)
    else:
        run_many(tests, expected=options.expected, failfast=options.failfast)
Exemple #7
0
    def after(self, track: BmsTrack):
        addr = self.addr
        hist = track._ptr.hist(addr)

        if hist == Visit.MIDDLE:
            raise OverlapError('%s %s - middle of command' % (getname(self), hex(addr)))

        # We are either visiting NONE or BEGIN.
        # Visit target (if necessary), then continue.

        if hist == Visit.NONE:
            track._ptr.addr = addr
        else:
            assert hist == Visit.BEGIN
Exemple #8
0
def main():
    import optparse
    parser = optparse.OptionParser()
    parser.add_option('--ignore')
    parser.add_option('--discover', action='store_true')
    parser.add_option('--full', action='store_true')
    parser.add_option('--expected')
    parser.add_option('--failfast', action='store_true')
    options, args = parser.parse_args()
    options.expected = load_list_from_file(options.expected)
    if options.full:
        assert options.ignore is None, '--ignore and --full are not compatible'
        tests = full(args)
    else:
        tests = discover(args, options.ignore)
    if options.discover:
        for cmd, options in tests:
            print util.getname(cmd,
                               env=options.get('env'),
                               setenv=options.get('setenv'))
        print '%s tests found.' % len(tests)
    else:
        run_many(tests, expected=options.expected, failfast=options.failfast)
Exemple #9
0
    def after(self, track: BmsTrack):
        addr = self.addr
        hist = track._ptr.hist(addr)

        if hist == Visit.MIDDLE:
            raise OverlapError('%s %s - middle of command' % (getname(self), hex(addr)))

        # We are either visiting NONE or BEGIN.
        # Not visited:
        #   Visit target.
        # Visited:
        # 	(addr) Check preconditions and apply postconditions.
        # 	Note that OldNote compares == None.

        if hist == Visit.NONE:
            track = BmsTrack(track._file, addr, None, track.note_history).parse()

        else:
            assert hist == Visit.BEGIN

            # **** ASSERTION ****
            # We will encounter issues if any touched notes differ from the original call.

            # TODO: We assume we're not calling into the middle of a visited section... :'(
            track = track._file.track_at[addr]

            different = (track.pre_history != track.note_history)
            if any(different & track.touched):
                LOG.error(
'''Invalid call from %06X to %06X
    new:%s
    old:%s
    out:%s
    touched:%s''', track._prev_addr, addr, track.note_history, track.pre_history, track.note_history, track.touched)

        # endif already visited

        # BMS really shouldn't be touching notes, AND leaving running notes untouched...

        if any(track.touched):
            untouched = ~track.touched
            if any(track.pre_history.astype(bool) & untouched):
                LOG.warning('Function leaves running notes untouched %s %s %s',
                            track.touched, track.pre_history, track.note_history)

        # Knowing that all "touched" entries entered identically...
        # We must apply all "touched" entries of the note history.
        track.note_history[track.touched] = track.note_history[track.touched]
Exemple #10
0
    def set_url(self, url, info=True):
        """
        Sets a new url to the item. This functions also changes other
        attributes, like file name, mode, network_play and the list of possible
        players.

        B{WARNING}: This is called whenever self.url is set, therefore it is
        strictly forbidden to set self.url directly in this function, (infinite
        recursion!). Use self.__dict__['url'] instead!
        """
        Item.set_url(self, url, info)

        # additional types of urls
        if url.startswith('dvd://') or url.startswith('vcd://'):
            self.network_play = False
            self.mimetype = self.url[:self.url.find('://')].lower()
            if self.url.find('/VIDEO_TS/') > 0:
                # dvd on harddisc
                self.filename = self.url[5:self.url.rfind('/VIDEO_TS/')]
                self.info = util.mediainfo.get(self.filename)
                self.files = FileInformation()
                self.name = self.info['title:filename']
                if not self.name:
                    self.name = util.getname(self.filename)
                self.files.append(self.filename)
            elif self.url.rfind('.iso') + 4 == self.url.rfind('/'):
                # iso
                self.filename = self.url[5:self.url.rfind('/')]
            else:
                self.filename = ''

        elif url.endswith('.iso') and self.info['mime'] == 'video/dvd':
            self.mimetype = 'dvd'
            self.mode = 'dvd'
            self.__dict__['url'] = 'dvd' + self.url[4:] + '/'

        # cover image
        if not self.image or (self.parent and self.image == self.parent.image):
            image = vfs.getoverlay(self.filename + '.raw')
            if os.path.exists(image):
                self.image = image
                self.files.image = image

        # do a new player rating based on the new url
        self.rating()
Exemple #11
0
    def set_url(self, url, info=True):
        """
        Sets a new url to the item. This functions also changes other
        attributes, like file name, mode, network_play and the list of possible
        players.

        B{WARNING}: This is called whenever self.url is set, therefore it is
        strictly forbidden to set self.url directly in this function, (infinite
        recursion!). Use self.__dict__['url'] instead!
        """
        Item.set_url(self, url, info)

        # additional types of urls
        if url.startswith('dvd://') or url.startswith('vcd://'):
            self.network_play = False
            self.mimetype = self.url[:self.url.find('://')].lower()
            if self.url.find('/VIDEO_TS/') > 0:
                # dvd on harddisc
                self.filename = self.url[5:self.url.rfind('/VIDEO_TS/')]
                self.info     = util.mediainfo.get(self.filename)
                self.files    = FileInformation()
                self.name     = self.info['title:filename']
                if not self.name:
                    self.name = util.getname(self.filename)
                self.files.append(self.filename)
            elif self.url.rfind('.iso') + 4 == self.url.rfind('/'):
                # iso
                self.filename = self.url[5:self.url.rfind('/')]
            else:
                self.filename = ''

        elif url.endswith('.iso') and self.info['mime'] == 'video/dvd':
            self.mimetype = 'dvd'
            self.mode     = 'dvd'
            self.__dict__['url'] = 'dvd' + self.url[4:] + '/'

        # cover image
        if not self.image or (self.parent and self.image == self.parent.image):
            image = vfs.getoverlay(self.filename + '.raw')
            if os.path.exists(image):
                self.image = image
                self.files.image = image

        # do a new player rating based on the new url
        self.rating()
Exemple #12
0
    def __init__(self,
                 name='',
                 playlist=None,
                 parent=None,
                 display_type=None,
                 random=False,
                 build=False,
                 autoplay=False,
                 repeat=False):
        """
        Init the playlist

            1. a filename to a playlist file (e.g. m3u)
            2. a list of items to play, this list can include
                - Items
                - filenames
                - a list (directoryname, recursive=0|1)

        @param build: create the playlist, this means unfold the directories
        """
        Item.__init__(self, parent)

        self.type = 'playlist'
        self.menuw = None
        self.name = Unicode(name)

        if isstring(playlist) and not name:
            self.name = util.getname(playlist)

        # variables only for Playlist
        self.current_item = None
        self.playlist = playlist or []
        self.autoplay = autoplay
        self.repeat = repeat
        self.display_type = display_type

        self.__build__ = False
        self.suffixlist = []
        self.get_plugins = []

        self.background_playlist = None
        if build:
            self.build()

        self.random = random
Exemple #13
0
    def set_url(self, url, info=True):
        """
        Sets a new url to the item. Always use this function and not set 'url'
        directly because this functions also changes other attributes, like
        filename, mode and network_play
        """
        Item.set_url(self, url, info)
        if url.startswith('dvd://') or url.startswith('vcd://'):
            self.network_play = False
            self.mimetype = self.url[:self.url.find('://')].lower()
            if self.url.find('/VIDEO_TS/') > 0:
                # dvd on harddisc
                self.filename = self.url[5:self.url.rfind('/VIDEO_TS/')]
                self.info = util.mediainfo.get(self.filename)
                self.files = FileInformation()
                self.name = self.info['title:filename']
                if not self.name:
                    self.name = util.getname(self.filename)
                self.files.append(self.filename)
            elif self.url.rfind('.iso') + 4 == self.url.rfind('/'):
                # iso
                self.filename = self.url[5:self.url.rfind('/')]
            else:
                self.filename = ''

        elif url.endswith('.iso') and self.info['mime'] == 'video/dvd':
            self.mimetype = 'dvd'
            self.mode = 'dvd'
            self.url = 'dvd' + self.url[4:] + '/'

        if not self.image or (self.parent and self.image == self.parent.image):
            image = vfs.getoverlay(self.filename + '.raw')
            if os.path.exists(image):
                self.image = image
                self.files.image = image

        if config.VIDEO_INTERLACING and self.info['interlaced'] \
               and not self['deinterlace']:
            # force deinterlacing
            self['deinterlace'] = 1
        else:
            self['deinterlace'] = 0
Exemple #14
0
    def __init__(self, name='', playlist=None, parent=None, display_type=None,
                 random=False, build=False, autoplay=False, repeat=False):
        """
        Init the playlist

            1. a filename to a playlist file (e.g. m3u)
            2. a list of items to play, this list can include
                - Items
                - filenames
                - a list (directoryname, recursive=0|1)

        @param build: create the playlist, this means unfold the directories
        """
        Item.__init__(self, parent)

        self.type     = 'playlist'
        self.menuw    = None
        self.name     = Unicode(name)

        if isstring(playlist) and not name:
            self.name = util.getname(playlist)

        # variables only for Playlist
        self.current_item = None
        self.playlist     = playlist or []
        self.autoplay     = autoplay
        self.repeat       = repeat
        self.display_type = display_type

        self.__build__    = False
        self.suffixlist   = []
        self.get_plugins  = []

        self.background_playlist = None
        if build:
            self.build()

        if self.name.find('Playlist') < 0:
            self.name = '%s Playlist' % self.name

        self.random = random
Exemple #15
0
def main():
    import optparse
    parser = optparse.OptionParser()
    parser.add_option('--ignore')
    parser.add_option('--discover', action='store_true')
    parser.add_option('--full', action='store_true')
    parser.add_option('--config')
    parser.add_option('--failfast', action='store_true')
    options, args = parser.parse_args()
    FAILING_TESTS = []
    if options.config:
        config = {}
        six.exec_(open(options.config).read(), config)
        FAILING_TESTS = config['FAILING_TESTS']
    tests = discover(args, options.ignore)
    if options.discover:
        for cmd, options in tests:
            print(util.getname(cmd, env=options.get('env'), setenv=options.get('setenv')))
        print('%s tests found.' % len(tests))
    else:
        run_many(tests, expected=FAILING_TESTS, failfast=options.failfast)
Exemple #16
0
def main():
    import optparse

    parser = optparse.OptionParser()
    parser.add_option("--ignore")
    parser.add_option("--discover", action="store_true")
    parser.add_option("--full", action="store_true")
    parser.add_option("--config")
    parser.add_option("--failfast", action="store_true")
    options, args = parser.parse_args()
    FAILING_TESTS = []
    if options.config:
        config = {}
        six.exec_(open(options.config).read(), config)
        FAILING_TESTS = config["FAILING_TESTS"]
    tests = discover(args, options.ignore)
    if options.discover:
        for cmd, options in tests:
            print(util.getname(cmd, env=options.get("env"), setenv=options.get("setenv")))
        print("%s tests found." % len(tests))
    else:
        run_many(tests, expected=FAILING_TESTS, failfast=options.failfast)
Exemple #17
0
def main():
    # FIXME: transition to argparse
    import optparse  # pylint:disable=deprecated-module

    parser = optparse.OptionParser()
    parser.add_option("--ignore")
    parser.add_option("--discover", action="store_true")
    parser.add_option("--full", action="store_true")
    parser.add_option("--config")
    parser.add_option("--failfast", action="store_true")
    parser.add_option("--coverage", action="store_true")
    options, args = parser.parse_args()
    FAILING_TESTS = []
    coverage = False
    if options.coverage or os.environ.get("GEVENTTEST_COVERAGE"):
        coverage = True
        # NOTE: This must be run from the greentest directory
        os.environ["COVERAGE_PROCESS_START"] = os.path.abspath(".coveragerc")
        os.environ["PYTHONPATH"] = os.path.abspath("coveragesite") + os.pathsep + os.environ.get("PYTHONPATH", "")
        # We change directory often, use an absolute path to keep all the
        # coverage files (which will have distinct suffixes because of parallel=true in .coveragerc
        # in this directory; makes them easier to combine and use with coverage report)
        os.environ["COVERAGE_FILE"] = os.path.abspath(".") + os.sep + ".coverage"
        print("Enabling coverage to", os.environ["COVERAGE_FILE"])
    if options.config:
        config = {}
        with open(options.config) as f:
            config_data = f.read()
        six.exec_(config_data, config)
        FAILING_TESTS = config["FAILING_TESTS"]
    tests = discover(args, options.ignore, coverage)
    if options.discover:
        for cmd, options in tests:
            print(util.getname(cmd, env=options.get("env"), setenv=options.get("setenv")))
        print("%s tests found." % len(tests))
    else:
        run_many(tests, expected=FAILING_TESTS, failfast=options.failfast)
Exemple #18
0
    def set_url(self, url, info=True, search_image=True):
        """
        Set a new url to the item and adjust all attributes depending
        on the url.
        """
        self.url              = url     # the url itself

        if not url:
            self.network_play = True    # network url, like http
            self.filename     = ''      # filename if it's a file:// url
            self.mode         = ''      # the type of the url (file, http, dvd...)
            self.files        = None    # FileInformation
            self.mimetype     = ''      # extention or mode
            return

        if url.find('://') == -1:
            self.url = 'file://' + url

        self.files = FileInformation()
        if self.media:
            self.files.read_only = True

        self.mode = self.url[:self.url.find('://')]

        if self.mode == 'file':
            self.network_play = False
            self.filename     = self.url[7:]
            self.files.append(self.filename)
            if search_image:
                image = util.getimage(self.filename[:self.filename.rfind('.')])
                if image:
                    self.image = image
                    self.files.image = image
                elif self.parent and self.parent.type != 'dir':
                    self.image = util.getimage(os.path.dirname(self.filename)+\
                                               '/cover', self.image)
            if config.REMOVE_COMMERCIALS:
               edlBase=self.filename[:self.filename.rfind('.')]
               edlFile=edlBase+".edl"
               self.edl_file=edlFile
               if os.path.exists(edlFile):
                  self.files.edl_file=edlFile
               else:
                  self.files.edl_file=None
            self.mimetype = self.filename[self.filename.rfind('.')+1:].lower()
            if info:
                self.info = mediainfo.get(self.filename)
                try:
                    if self.parent.DIRECTORY_USE_MEDIAID_TAG_NAMES:
                        self.name = self.info['title'] or self.name
                except:
                    pass
                if not self.name:
                    self.name = self.info['title:filename']

            if self.type == 'audio' and info:
                # Look for audio cover image by ID3 tags
                filename_array = { 'album'  : self.info['album'],
                                   'artist' : self.info['artist'] }
                for format_string in config.AUDIO_COVER_FORMAT_STRINGS:
                    filemask = format_string % filename_array
                    if format_string.startswith('/'):
                        audiocover = util.getimage(filemask)
                    else:
                        audiocover = util.getimage(os.path.dirname(self.filename)+'/'+filemask)
                    if audiocover:
                        self.image = audiocover
                        self.files.image = audiocover
                        break;

            if not self.name:
                self.name = util.getname(self.filename)
        else:
            self.network_play = True
            self.filename     = ''
            self.mimetype     = self.type
            if not self.name:
                self.name     = Unicode(self.url)
Exemple #19
0
    def __init__(self,
                 directory,
                 parent,
                 name='',
                 display_type=None,
                 add_args=None,
                 create_metainfo=True):
        self.autovars = [('num_dir_items', 0), ('show_all_items', False)]
        Playlist.__init__(self, parent=parent, display_type=display_type)
        self.type = 'dir'
        self.menu = None

        # store FileInformation for moving/copying
        self.files = FileInformation()
        if self.media:
            self.files.read_only = True
        self.files.append(directory)

        self.dir = os.path.abspath(directory)
        self.info = mediainfo.get_dir(directory)

        #FIXME This should be done in the cache create
        if not self.image:
            mminfo = mmpython.parse(directory)
            if mminfo:
                if mminfo['image']:
                    self.image = mminfo['image']
                if mminfo['title']:
                    self.title = mminfo['title']
                if mminfo['comment']:
                    self.comment = mminfo['comment']

        if name:
            self.name = Unicode(name)
        elif self.info['title:filename']:
            self.name = self.info['title:filename']
        elif self.info['title']:
            self.name = self.info['title']
        else:
            self.name = util.getname(directory, skip_ext=False)

        if add_args == None and hasattr(parent, 'add_args'):
            add_args = parent.add_args

        self.add_args = add_args

        if self.parent and hasattr(parent, 'skin_display_type'):
            self.skin_display_type = parent.skin_display_type
        elif parent:
            self.skin_display_type = parent.display_type
        else:
            self.skin_display_type = display_type

        if self['show_all_items']:
            self.display_type = None

        # set tv to video now
        if self.display_type == 'tv':
            display_type = 'video'

        # set directory variables to default
        global all_variables
        self.all_variables = copy.copy(all_variables)

        # Check mimetype plugins if they want to add something
        for p in plugin.mimetype(display_type):
            self.all_variables += p.dirconfig(self)

        # set the variables to the default values
        for var in self.all_variables:
            if hasattr(parent, var[0]):
                setattr(self, var[0], getattr(parent, var[0]))
            elif hasattr(config, var[0]):
                setattr(self, var[0], getattr(config, var[0]))
            else:
                setattr(self, var[0], False)

        self.modified_vars = []

        # Check for a cover in current dir
        if self.info['image']:
            image = self.info['image']
        else:
            image = util.getimage(os.path.join(directory, 'cover'))
        # if we have an image then use it
        if image:
            self.image = image
            self.files.image = image

        # Check for a folder.fxd in current dir
        self.folder_fxd = directory + '/folder.fxd'
        if vfs.isfile(self.folder_fxd):
            self.set_fxd_file(self.folder_fxd)

        # Check mimetype plugins if they want to add something
        for p in plugin.mimetype(display_type):
            p.dirinfo(self)

        if self.DIRECTORY_SORT_BY_DATE == 2 and self.display_type != 'tv':
            self.DIRECTORY_SORT_BY_DATE = 0

        # create some extra info
        if create_metainfo:
            self.create_metainfo()
Exemple #20
0
    def set_url(self, url, info=True, search_image=True):
        """
        Set a new url to the item and adjust all attributes depending
        on the url.
        WARNING: This is called whenever self.url is set, therefor it is
        strictly forbidden to set self.url directly in this function,
        (infinit recursion!). Use self.__dict__['url'] instead!
        """
        # set the url itself
        if url and url.find('://') == -1:
            # local url
            self.__dict__['url'] = 'file://' + url
        else:
            # some other kind of url
            self.__dict__['url'] = url

        if self.url==None:
            # reset everything to default values
            self.network_play = True
            self.filename     = ''
            self.mode         = ''
            self.files        = None
            self.mimetype     = ''
            return

        # add additional info files
        self.files = FileInformation()
        if self.media:
            self.files.read_only = True

        # determine the mode of this item
        self.mode = self.url[:self.url.find('://')]

        if self.mode == 'file':
            self.network_play = False
            self.filename     = self.url[7:]
            self.files.append(self.filename)
            self.mimetype = os.path.splitext(self.filename)[1][1:].lower()

            if search_image:
                image = util.getimage(self.filename[:self.filename.rfind('.')])
                if image:
                    self.image = image
                    self.files.image = image
                elif self.parent and self.parent.type != 'dir':
                    imagepath= os.path.dirname(self.filename)
                    imagepath= os.path.join(imagepath, 'cover')
                    self.image = util.getimage(imagepath, self.image)
            # TODO: is this the right place for this?
            if config.TV_RECORD_REMOVE_COMMERCIALS:
                edlBase=self.filename[:self.filename.rfind('.')]
                edlFile=edlBase+".edl"
                self.edl_file=edlFile
                if os.path.exists(edlFile):
                    self.files.edl_file=edlFile
                else:
                    self.files.edl_file=None

            if info:
                self.info = mediainfo.get(self.filename)
                try:
                    if self.parent.DIRECTORY_USE_MEDIAID_TAG_NAMES:
                        self.name = self.info['title'] or self.name
                except:
                    pass
                if not self.name:
                    self.name = self.info['title:filename']

            if not self.name:
                self.name = util.getname(self.filename)
        else:
            # some defaults for other url types
            self.network_play = True
            self.filename     = ''
            self.mimetype     = self.type
            if not self.name:
                self.name     = Unicode(self.url)
Exemple #21
0
    def set_url(self, url, info=True, search_image=True):
        """
        Set a new url to the item and adjust all attributes depending
        on the url.
        WARNING: This is called whenever self.url is set, therefor it is
        strictly forbidden to set self.url directly in this function,
        (infinit recursion!). Use self.__dict__['url'] instead!
        """
        # set the url itself
        if url and url.find('://') == -1:
            # local url
            self.__dict__['url'] = 'file://' + url
        else:
            # some other kind of url
            self.__dict__['url'] = url

        if self.url == None:
            # reset everything to default values
            self.network_play = True
            self.filename = ''
            self.mode = ''
            self.files = None
            self.mimetype = ''
            return

        # add additional info files
        self.files = FileInformation()
        if self.media:
            self.files.read_only = True

        # determine the mode of this item
        self.mode = self.url[:self.url.find('://')]

        if self.mode == 'file':
            self.network_play = False
            self.filename = self.url[7:]
            self.files.append(self.filename)
            self.mimetype = os.path.splitext(self.filename)[1][1:].lower()

            if search_image:
                image = util.getimage(self.filename[:self.filename.rfind('.')])
                if image:
                    self.image = image
                    self.files.image = image
                elif self.parent and self.parent.type != 'dir':
                    imagepath = os.path.dirname(self.filename)
                    imagepath = os.path.join(imagepath, 'cover')
                    self.image = util.getimage(imagepath, self.image)
            # TODO: is this the right place for this?
            if config.TV_RECORD_REMOVE_COMMERCIALS:
                edlBase = self.filename[:self.filename.rfind('.')]
                edlFile = edlBase + ".edl"
                self.edl_file = edlFile
                if os.path.exists(edlFile):
                    self.files.edl_file = edlFile
                else:
                    self.files.edl_file = None

            if info:
                self.info = mediainfo.get(self.filename)
                try:
                    if self.parent.DIRECTORY_USE_MEDIAID_TAG_NAMES:
                        self.name = self.info['title'] or self.name
                except:
                    pass
                if not self.name:
                    self.name = self.info['title:filename']

            if not self.name:
                self.name = util.getname(self.filename)
        else:
            # some defaults for other url types
            self.network_play = True
            self.filename = ''
            self.mimetype = self.type
            if not self.name:
                self.name = Unicode(self.url)