Ejemplo n.º 1
0
    def __init__(self, folder, data_callback, error_callback=None):
        self.data = {}
        self.files = path.find_files(folder)
        self.data_callback = data_callback
        self.error_callback = error_callback
        self.loop = gobject.MainLoop()

        self.fakesink = gst.element_factory_make('fakesink')
        self.fakesink.set_property('signal-handoffs', True)
        self.fakesink.connect('handoff', self.process_handoff)

        self.uribin = gst.element_factory_make('uridecodebin')
        self.uribin.set_property(
            'caps', gst.Caps(b'audio/x-raw-int; audio/x-raw-float'))
        self.uribin.connect('pad-added', self.process_new_pad)

        self.pipe = gst.element_factory_make('pipeline')
        self.pipe.add(self.uribin)
        self.pipe.add(self.fakesink)

        bus = self.pipe.get_bus()
        bus.add_signal_watch()
        bus.connect('message::application', self.process_application)
        bus.connect('message::tag', self.process_tags)
        bus.connect('message::error', self.process_error)
Ejemplo n.º 2
0
    def __init__(self, base_dir, data_callback, error_callback=None):
        self.data = {}
        self.files = path.find_files(base_dir)
        self.data_callback = data_callback
        self.error_callback = error_callback
        self.loop = gobject.MainLoop()

        self.fakesink = gst.element_factory_make('fakesink')
        self.fakesink.set_property('signal-handoffs', True)
        self.fakesink.connect('handoff', self.process_handoff)

        self.uribin = gst.element_factory_make('uridecodebin')
        self.uribin.set_property(
            'caps', gst.Caps(b'audio/x-raw-int; audio/x-raw-float'))
        self.uribin.connect('pad-added', self.process_new_pad)

        self.pipe = gst.element_factory_make('pipeline')
        self.pipe.add(self.uribin)
        self.pipe.add(self.fakesink)

        bus = self.pipe.get_bus()
        bus.add_signal_watch()
        bus.connect('message::application', self.process_application)
        bus.connect('message::tag', self.process_tags)
        bus.connect('message::error', self.process_error)
Ejemplo n.º 3
0
 def scan(self, path):
     paths = path_lib.find_files(path_to_data_dir(path))
     uris = (path_lib.path_to_uri(p) for p in paths)
     scanner = scan.Scanner()
     for uri in uris:
         key = uri[len('file://'):]
         try:
             self.data[key] = scanner.scan(uri)
         except exceptions.ScannerError as error:
             self.errors[key] = error
Ejemplo n.º 4
0
    def __init__(self, folder, data_callback, error_callback=None):
        self.files = find_files(folder)
        self.data_callback = data_callback
        self.error_callback = error_callback
        self.loop = gobject.MainLoop()

        fakesink = gst.element_factory_make('fakesink')

        self.uribin = gst.element_factory_make('uridecodebin')
        self.uribin.set_property('caps', gst.Caps('audio/x-raw-int'))
        self.uribin.connect('pad-added', self.process_new_pad,
            fakesink.get_pad('sink'))

        self.pipe = gst.element_factory_make('pipeline')
        self.pipe.add(self.uribin)
        self.pipe.add(fakesink)

        bus = self.pipe.get_bus()
        bus.add_signal_watch()
        bus.connect('message::tag', self.process_tags)
        bus.connect('message::error', self.process_error)
Ejemplo n.º 5
0
    def __init__(self, folder, data_callback, error_callback=None):
        self.uris = [path_to_uri(f) for f in find_files(folder)]
        self.data_callback = data_callback
        self.error_callback = error_callback
        self.loop = gobject.MainLoop()

        fakesink = gst.element_factory_make('fakesink')

        self.uribin = gst.element_factory_make('uridecodebin')
        self.uribin.set_property('caps', gst.Caps('audio/x-raw-int'))
        self.uribin.connect('pad-added', self.process_new_pad,
            fakesink.get_pad('sink'))

        self.pipe = gst.element_factory_make('pipeline')
        self.pipe.add(self.uribin)
        self.pipe.add(fakesink)

        bus = self.pipe.get_bus()
        bus.add_signal_watch()
        bus.connect('message::tag', self.process_tags)
        bus.connect('message::error', self.process_error)
Ejemplo n.º 6
0
    def __init__(self, folder, data_callback, error_callback=None):
        self.data = {}
        self.files = path.find_files(folder)
        self.data_callback = data_callback
        self.error_callback = error_callback
        self.loop = gobject.MainLoop()

        self.fakesink = gst.element_factory_make("fakesink")
        self.fakesink.set_property("signal-handoffs", True)
        self.fakesink.connect("handoff", self.process_handoff)

        self.uribin = gst.element_factory_make("uridecodebin")
        self.uribin.set_property("caps", gst.Caps(b"audio/x-raw-int"))
        self.uribin.connect("pad-added", self.process_new_pad)

        self.pipe = gst.element_factory_make("pipeline")
        self.pipe.add(self.uribin)
        self.pipe.add(self.fakesink)

        bus = self.pipe.get_bus()
        bus.add_signal_watch()
        bus.connect("message::application", self.process_application)
        bus.connect("message::tag", self.process_tags)
        bus.connect("message::error", self.process_error)
Ejemplo n.º 7
0
 def find(self, value):
     return list(path.find_files(path_to_data_dir(value)))
Ejemplo n.º 8
0
 def find(self, value):
     return list(path.find_files(path_to_data_dir(value)))
Ejemplo n.º 9
0
 def find(self, path):
     return list(find_files(path_to_data_dir(path)))
Ejemplo n.º 10
0
    def run(self, args, config):
        media_dir = config['local']['media_dir']
        scan_timeout = config['local']['scan_timeout']
        flush_threshold = config['local']['scan_flush_threshold']
        excluded_file_extensions = config['local']['excluded_file_extensions']
        excluded_file_extensions = set(
            file_ext.lower() for file_ext in excluded_file_extensions)

        library = _get_library(args, config)

        uri_path_mapping = {}
        uris_in_library = set()
        uris_to_update = set()
        uris_to_remove = set()

        num_tracks = library.load()
        logger.info('Checking %d tracks from library.', num_tracks)

        for track in library.begin():
            uri_path_mapping[track.uri] = translator.local_track_uri_to_path(
                track.uri, media_dir)
            try:
                stat = os.stat(uri_path_mapping[track.uri])
                if int(stat.st_mtime) > track.last_modified:
                    uris_to_update.add(track.uri)
                uris_in_library.add(track.uri)
            except OSError:
                logger.debug('Missing file %s', track.uri)
                uris_to_remove.add(track.uri)

        logger.info('Removing %d missing tracks.', len(uris_to_remove))
        for uri in uris_to_remove:
            library.remove(uri)

        logger.info('Checking %s for unknown tracks.', media_dir)
        for relpath in path.find_files(media_dir):
            uri = translator.path_to_local_track_uri(relpath)
            file_extension = os.path.splitext(relpath)[1]

            if file_extension.lower() in excluded_file_extensions:
                logger.debug('Skipped %s: File extension excluded.', uri)
                continue

            if uri not in uris_in_library:
                uris_to_update.add(uri)
                uri_path_mapping[uri] = os.path.join(media_dir, relpath)

        logger.info('Found %d unknown tracks.', len(uris_to_update))
        logger.info('Scanning...')

        uris_to_update = sorted(uris_to_update)[:args.limit]

        scanner = scan.Scanner(scan_timeout)
        progress = _Progress(flush_threshold, len(uris_to_update))

        for uri in uris_to_update:
            try:
                data = scanner.scan(path.path_to_uri(uri_path_mapping[uri]))
                track = scan.audio_data_to_track(data).copy(uri=uri)
                library.add(track)
                logger.debug('Added %s', track.uri)
            except exceptions.ScannerError as error:
                logger.warning('Failed %s: %s', uri, error)

            if progress.increment():
                progress.log()
                if library.flush():
                    logger.debug('Progress flushed.')

        progress.log()
        library.close()
        logger.info('Done scanning.')
        return 0
Ejemplo n.º 11
0
 def scan(self, path):
     paths = path_lib.find_files(path_to_data_dir(path))
     uris = (path_lib.path_to_uri(p) for p in paths)
     scanner = Scanner(uris, self.data_callback, self.error_callback)
     scanner.start()
Ejemplo n.º 12
0
 def find(self, path):
     return list(find_files(path_to_data_dir(path)))
Ejemplo n.º 13
0
 def find(self, path):
     media_dir = path_to_data_dir(path)
     for path in path_lib.find_files(media_dir):
         yield os.path.join(media_dir, path)
Ejemplo n.º 14
0
 def find(self, path):
     media_dir = path_to_data_dir(path)
     for path in path_lib.find_files(media_dir):
         yield os.path.join(media_dir, path)
Ejemplo n.º 15
0
    def run(self, args, config):
        media_dir = config['local']['media_dir']
        scan_timeout = config['local']['scan_timeout']
        flush_threshold = config['local']['scan_flush_threshold']
        excluded_file_extensions = config['local']['excluded_file_extensions']
        excluded_file_extensions = set(
            file_ext.lower() for file_ext in excluded_file_extensions)

        library = _get_library(args, config)

        uri_path_mapping = {}
        uris_in_library = set()
        uris_to_update = set()
        uris_to_remove = set()

        num_tracks = library.load()
        logger.info('Checking %d tracks from library.', num_tracks)

        for track in library.begin():
            uri_path_mapping[track.uri] = translator.local_track_uri_to_path(
                track.uri, media_dir)
            try:
                stat = os.stat(uri_path_mapping[track.uri])
                if int(stat.st_mtime) > track.last_modified:
                    uris_to_update.add(track.uri)
                uris_in_library.add(track.uri)
            except OSError:
                logger.debug('Missing file %s', track.uri)
                uris_to_remove.add(track.uri)

        logger.info('Removing %d missing tracks.', len(uris_to_remove))
        for uri in uris_to_remove:
            library.remove(uri)

        logger.info('Checking %s for unknown tracks.', media_dir)
        for relpath in path.find_files(media_dir):
            uri = translator.path_to_local_track_uri(relpath)
            file_extension = os.path.splitext(relpath)[1]

            if file_extension.lower() in excluded_file_extensions:
                logger.debug('Skipped %s: File extension excluded.', uri)
                continue

            if uri not in uris_in_library:
                uris_to_update.add(uri)
                uri_path_mapping[uri] = os.path.join(media_dir, relpath)

        logger.info('Found %d unknown tracks.', len(uris_to_update))
        logger.info('Scanning...')

        uris_to_update = sorted(uris_to_update)[:args.limit]

        scanner = scan.Scanner(scan_timeout)
        progress = _Progress(flush_threshold, len(uris_to_update))

        for uri in uris_to_update:
            try:
                data = scanner.scan(path.path_to_uri(uri_path_mapping[uri]))
                track = scan.audio_data_to_track(data).copy(uri=uri)
                library.add(track)
                logger.debug('Added %s', track.uri)
            except exceptions.ScannerError as error:
                logger.warning('Failed %s: %s', uri, error)

            if progress.increment():
                progress.log()
                if library.flush():
                    logger.debug('Progress flushed.')

        progress.log()
        library.close()
        logger.info('Done scanning.')
        return 0
Ejemplo n.º 16
0
 def find(self, path):
     return list(find_files(data_folder(path)))