Ejemplo n.º 1
0
        def embed_func(lib, opts, args):
            if opts.file:
                imagepath = normpath(opts.file)
                if not os.path.isfile(syspath(imagepath)):
                    raise ui.UserError(u'image file {0} not found'.format(
                        displayable_path(imagepath)
                    ))

                items = lib.items(decargs(args))

                # Confirm with user.
                if not opts.yes and not _confirm(items, not opts.file):
                    return

                for item in items:
                    art.embed_item(self._log, item, imagepath, maxwidth, None,
                                   compare_threshold, ifempty)
            else:
                albums = lib.albums(decargs(args))

                # Confirm with user.
                if not opts.yes and not _confirm(albums, not opts.file):
                    return

                for album in albums:
                    art.embed_album(self._log, album, maxwidth, False,
                                    compare_threshold, ifempty)
                    self.remove_artfile(album)
Ejemplo n.º 2
0
        def embed_func(lib, opts, args):
            if opts.file:
                imagepath = normpath(opts.file)
                if not os.path.isfile(syspath(imagepath)):
                    raise ui.UserError(u'image file {0} not found'.format(
                        displayable_path(imagepath)))

                items = lib.items(decargs(args))

                # Confirm with user.
                if not opts.yes and not _confirm(items, not opts.file):
                    return

                for item in items:
                    art.embed_item(self._log, item, imagepath, maxwidth, None,
                                   compare_threshold, ifempty)
            else:
                albums = lib.albums(decargs(args))

                # Confirm with user.
                if not opts.yes and not _confirm(albums, not opts.file):
                    return

                for album in albums:
                    art.embed_album(self._log, album, maxwidth, False,
                                    compare_threshold, ifempty)
                    self.remove_artfile(album)
Ejemplo n.º 3
0
 def embed_art(self, item, path):
     album = item.get_album()
     if album and album.artpath:
         self._log.debug("Embedding art from {} into {}".format(
             displayable_path(album.artpath),
             displayable_path(path)))
         art.embed_item(self._log, item, album.artpath,
                        itempath=path)
Ejemplo n.º 4
0
 def sync_art(self, item, path):
     """ Embed artwork in the destination file.
     """
     album = item.get_album()
     if album:
         if album.artpath and os.path.isfile(syspath(album.artpath)):
             self._log.debug("Embedding art from {} into {}".format(
                 displayable_path(album.artpath), displayable_path(path)))
             art.embed_item(self._log, item, album.artpath, itempath=path)
Ejemplo n.º 5
0
 def embed_func(lib, opts, args):
     if opts.file:
         imagepath = normpath(opts.file)
         if not os.path.isfile(syspath(imagepath)):
             raise ui.UserError(u"image file {0} not found".format(displayable_path(imagepath)))
         for item in lib.items(decargs(args)):
             art.embed_item(self._log, item, imagepath, maxwidth, None, compare_threshold, ifempty)
     else:
         for album in lib.albums(decargs(args)):
             art.embed_album(self._log, album, maxwidth, False, compare_threshold, ifempty)
             self.remove_artfile(album)
Ejemplo n.º 6
0
 def embed_func(lib, opts, args):
     if opts.file:
         imagepath = normpath(opts.file)
         if not os.path.isfile(syspath(imagepath)):
             raise ui.UserError(u'image file {0} not found'.format(
                 displayable_path(imagepath)))
         for item in lib.items(decargs(args)):
             art.embed_item(self._log, item, imagepath, maxwidth, None,
                            compare_threshold, ifempty)
     else:
         for album in lib.albums(decargs(args)):
             art.embed_album(self._log, album, maxwidth, False,
                             compare_threshold, ifempty)
Ejemplo n.º 7
0
        def embed_func(lib, opts, args):
            if opts.file:
                imagepath = normpath(opts.file)
                if not os.path.isfile(syspath(imagepath)):
                    raise ui.UserError(u'image file {0} not found'.format(
                        displayable_path(imagepath)))
                for item in lib.items(decargs(args)):
                    art.embed_item(self._log, item, imagepath, maxwidth, None,
                                   compare_threshold, ifempty)
            else:
                for album in lib.albums(decargs(args)):
                    art.embed_album(self._log, album, maxwidth, False,
                                    compare_threshold, ifempty)

                    if remove_art_file and album.artpath is not None:
                        if os.path.isfile(album.artpath):
                            self._log.debug(
                                u'Removing album art file '
                                u'for {0}', album)
                            os.remove(album.artpath)
                            album.artpath = None
                            album.store()
Ejemplo n.º 8
0
        def embed_func(lib, opts, args):
            if opts.file:
                imagepath = normpath(opts.file)
                if not os.path.isfile(syspath(imagepath)):
                    raise ui.UserError(u'image file {0} not found'.format(
                        displayable_path(imagepath)
                    ))
                for item in lib.items(decargs(args)):
                    art.embed_item(self._log, item, imagepath, maxwidth, None,
                                   compare_threshold, ifempty)
            else:
                for album in lib.albums(decargs(args)):
                    art.embed_album(self._log, album, maxwidth, False,
                                    compare_threshold, ifempty)

                    if remove_art_file and album.artpath is not None:
                        if os.path.isfile(album.artpath):
                            self._log.debug(u'Removing album art file '
                                            u'for {0}', album)
                            os.remove(album.artpath)
                            album.artpath = None
                            album.store()
Ejemplo n.º 9
0
    def convert_item(self, dest_dir, keep_new, path_formats, fmt, pretend=False):
        command, ext = get_format(fmt)
        item, original, converted = None, None, None
        while True:
            item = yield (item, original, converted)
            dest = item.destination(basedir=dest_dir, path_formats=path_formats)

            # When keeping the new file in the library, we first move the
            # current (pristine) file to the destination. We'll then copy it
            # back to its old path or transcode it to a new path.
            if keep_new:
                original = dest
                converted = item.path
                if should_transcode(item, fmt):
                    converted = replace_ext(converted, ext)
            else:
                original = item.path
                if should_transcode(item, fmt):
                    dest = replace_ext(dest, ext)
                converted = dest

            # Ensure that only one thread tries to create directories at a
            # time. (The existence check is not atomic with the directory
            # creation inside this function.)
            if not pretend:
                with _fs_lock:
                    util.mkdirall(dest)

            if os.path.exists(util.syspath(dest)):
                self._log.info("Skipping {0} (target file exists)", util.displayable_path(item.path))
                continue

            if keep_new:
                if pretend:
                    self._log.info("mv {0} {1}", util.displayable_path(item.path), util.displayable_path(original))
                else:
                    self._log.info("Moving to {0}", util.displayable_path(original))
                    util.move(item.path, original)

            if should_transcode(item, fmt):
                try:
                    self.encode(command, original, converted, pretend)
                except subprocess.CalledProcessError:
                    continue
            else:
                if pretend:
                    self._log.info("cp {0} {1}", util.displayable_path(original), util.displayable_path(converted))
                else:
                    # No transcoding necessary.
                    self._log.info("Copying {0}", util.displayable_path(item.path))
                    util.copy(original, converted)

            if pretend:
                continue

            # Write tags from the database to the converted file.
            item.try_write(path=converted)

            if keep_new:
                # If we're keeping the transcoded file, read it again (after
                # writing) to get new bitrate, duration, etc.
                item.path = converted
                item.read()
                item.store()  # Store new path and audio data.

            if self.config["embed"]:
                album = item.get_album()
                if album and album.artpath:
                    self._log.debug("embedding album art from {}", util.displayable_path(album.artpath))
                    art.embed_item(self._log, item, album.artpath, itempath=converted)

            if keep_new:
                plugins.send("after_convert", item=item, dest=dest, keepnew=True)
            else:
                plugins.send("after_convert", item=item, dest=converted, keepnew=False)
Ejemplo n.º 10
0
    def convert_item(self,
                     dest_dir,
                     keep_new,
                     path_formats,
                     fmt,
                     pretend=False):
        command, ext = get_format(fmt)
        item, original, converted = None, None, None
        while True:
            item = yield (item, original, converted)
            dest = item.destination(basedir=dest_dir,
                                    path_formats=path_formats)

            # When keeping the new file in the library, we first move the
            # current (pristine) file to the destination. We'll then copy it
            # back to its old path or transcode it to a new path.
            if keep_new:
                original = dest
                converted = item.path
                if should_transcode(item, fmt):
                    converted = replace_ext(converted, ext)
            else:
                original = item.path
                if should_transcode(item, fmt):
                    dest = replace_ext(dest, ext)
                converted = dest

            # Ensure that only one thread tries to create directories at a
            # time. (The existence check is not atomic with the directory
            # creation inside this function.)
            if not pretend:
                with _fs_lock:
                    util.mkdirall(dest)

            if os.path.exists(util.syspath(dest)):
                self._log.info(u'Skipping {0} (target file exists)',
                               util.displayable_path(item.path))
                continue

            if keep_new:
                if pretend:
                    self._log.info(u'mv {0} {1}',
                                   util.displayable_path(item.path),
                                   util.displayable_path(original))
                else:
                    self._log.info(u'Moving to {0}',
                                   util.displayable_path(original))
                    util.move(item.path, original)

            if should_transcode(item, fmt):
                try:
                    self.encode(command, original, converted, pretend)
                except subprocess.CalledProcessError:
                    continue
            else:
                if pretend:
                    self._log.info(u'cp {0} {1}',
                                   util.displayable_path(original),
                                   util.displayable_path(converted))
                else:
                    # No transcoding necessary.
                    self._log.info(u'Copying {0}',
                                   util.displayable_path(item.path))
                    util.copy(original, converted)

            if pretend:
                continue

            # Write tags from the database to the converted file.
            item.try_write(path=converted)

            if keep_new:
                # If we're keeping the transcoded file, read it again (after
                # writing) to get new bitrate, duration, etc.
                item.path = converted
                item.read()
                item.store()  # Store new path and audio data.

            if self.config['embed']:
                album = item.get_album()
                if album and album.artpath:
                    self._log.debug('embedding album art from {}',
                                    util.displayable_path(album.artpath))
                    art.embed_item(self._log,
                                   item,
                                   album.artpath,
                                   itempath=converted)

            if keep_new:
                plugins.send('after_convert',
                             item=item,
                             dest=dest,
                             keepnew=True)
            else:
                plugins.send('after_convert',
                             item=item,
                             dest=converted,
                             keepnew=False)
Ejemplo n.º 11
0
 def embed_art(self, item, path):
     album = item.get_album()
     if album and album.artpath:
         self._log.debug("Embedding art from {} into {}".format(
             displayable_path(album.artpath), displayable_path(path)))
         art.embed_item(self._log, item, album.artpath, itempath=path)
Ejemplo n.º 12
0
    def convert_item(self,
                     dest_dir,
                     keep_new,
                     path_formats,
                     fmt,
                     pretend=False,
                     link=False,
                     hardlink=False):
        """A pipeline thread that converts `Item` objects from a
        library.
        """
        command, ext = get_format(fmt)
        item, original, converted = None, None, None
        while True:
            item = yield (item, original, converted)
            dest = item.destination(basedir=dest_dir,
                                    path_formats=path_formats)

            # When keeping the new file in the library, we first move the
            # current (pristine) file to the destination. We'll then copy it
            # back to its old path or transcode it to a new path.
            if keep_new:
                original = dest
                converted = item.path
                if should_transcode(item, fmt):
                    converted = replace_ext(converted, ext)
            else:
                original = item.path
                if should_transcode(item, fmt):
                    dest = replace_ext(dest, ext)
                converted = dest

            # Ensure that only one thread tries to create directories at a
            # time. (The existence check is not atomic with the directory
            # creation inside this function.)
            if not pretend:
                with _fs_lock:
                    util.mkdirall(dest)

            if os.path.exists(util.syspath(dest)):
                self._log.info('Skipping {0} (target file exists)',
                               util.displayable_path(item.path))
                continue

            if keep_new:
                if pretend:
                    self._log.info('mv {0} {1}',
                                   util.displayable_path(item.path),
                                   util.displayable_path(original))
                else:
                    self._log.info('Moving to {0}',
                                   util.displayable_path(original))
                    util.move(item.path, original)

            if should_transcode(item, fmt):
                linked = False
                try:
                    self.encode(command, original, converted, pretend)
                except subprocess.CalledProcessError:
                    continue
            else:
                linked = link or hardlink
                if pretend:
                    msg = 'ln' if hardlink else ('ln -s' if link else 'cp')

                    self._log.info('{2} {0} {1}',
                                   util.displayable_path(original),
                                   util.displayable_path(converted), msg)
                else:
                    # No transcoding necessary.
                    msg = 'Hardlinking' if hardlink \
                        else ('Linking' if link else 'Copying')

                    self._log.info('{1} {0}', util.displayable_path(item.path),
                                   msg)

                    if hardlink:
                        util.hardlink(original, converted)
                    elif link:
                        util.link(original, converted)
                    else:
                        util.copy(original, converted)

            if pretend:
                continue

            id3v23 = self.config['id3v23'].as_choice([True, False, 'inherit'])
            if id3v23 == 'inherit':
                id3v23 = None

            # Write tags from the database to the converted file.
            item.try_write(path=converted, id3v23=id3v23)

            if keep_new:
                # If we're keeping the transcoded file, read it again (after
                # writing) to get new bitrate, duration, etc.
                item.path = converted
                item.read()
                item.store()  # Store new path and audio data.

            if self.config['embed'] and not linked:
                album = item._cached_album
                if album and album.artpath:
                    self._log.debug('embedding album art from {}',
                                    util.displayable_path(album.artpath))
                    art.embed_item(self._log,
                                   item,
                                   album.artpath,
                                   itempath=converted,
                                   id3v23=id3v23)

            if keep_new:
                plugins.send('after_convert',
                             item=item,
                             dest=dest,
                             keepnew=True)
            else:
                plugins.send('after_convert',
                             item=item,
                             dest=converted,
                             keepnew=False)
Ejemplo n.º 13
0
 def embed_art(item, path):
     album = item.get_album()
     if album and album.artpath:
         art.embed_item(log, item, album.artpath, itempath=path)
Ejemplo n.º 14
0
 def embed_art(item, path):
     album = item.get_album()
     if album and album.artpath:
         art.embed_item(log, item, album.artpath,
                        itempath=path)