Example #1
0
    def getNewSongs(self, lib, conn):
        newSongIds = []
        query = "added:" + str(date.year) + "-" + str(date.month) + "-" + str(date.day)
        try:
            items = _do_query(lib, query, False, False)
        except:
            return []
        #get the songs list from the tuple
        songs = items[0]
        self._log.info(u'----Locating:-----')
        for item in songs:
            if not item: # skip empty lists
                continue
            self._log.info(u'{0.title} by {0.artist} on album {0.album} in beets is:', item)
            searchQuery = item.title + " " + item.artist
            reply = conn.search3(searchQuery, artistCount=1, albumCount=1, songCount=1)
            #peel back the artist and album layers to get the song id
            searchResult = reply.get("searchResult3")
            song = searchResult.get("song")
            song = song[0] #peel back the list
            self._log.info(u'{} by {} on album {} in airsonic', song.get("title"), song.get("artist"), song.get("album"))
            songId = song.get("id")
            newSongIds.append(songId)

        return newSongIds
Example #2
0
 def read_advisory(self, lib, opts, args):
     self.config.set_args(opts)
     query = decargs(args)
     items, _ = _do_query(lib, query, None, False)
     if not items:
         print_(u'No items matched the specified query: {0}.'.format(' '.join(query)))
         return
     self.read_items(lib, items, pretend=opts.pretend)
Example #3
0
 def check_do_query(self,
                    num_items,
                    num_albums,
                    q=(),
                    album=False,
                    also_items=True):
     items, albums = commands._do_query(self.lib, q, album, also_items)
     self.assertEqual(len(items), num_items)
     self.assertEqual(len(albums), num_albums)
Example #4
0
    def modify_items(self, lib, mods, dels, query, write, move, album,
                     confirm):
        """Modifies matching items according to user-specified assignments and
        deletions.

        `mods` is a dictionary of field and value pairse indicating
        assignments. `dels` is a list of fields to be deleted.
        """
        # Parse key=value specifications into a dictionary.
        model_cls = library.Album if album else library.Item

        # Get the items to modify.
        items, albums = _do_query(lib, query, album, False)
        objs = albums if album else items

        reconfirm = self.check_sanity(mods, dels, objs, album)
        if reconfirm:
            confirm = True

        # Apply changes *temporarily*, preview them, and collect modified
        # objects.
        print_(u'Modifying {0} {1}s.'.format(len(objs),
                                             u'album' if album else u'item'))
        changed = []
        for obj in objs:
            obj_mods = {}
            for key, value in mods.items():
                value = obj.evaluate_template(value)
                obj_mods[key] = model_cls._parse(key, value)

            if print_and_modify(obj, obj_mods, dels) and obj not in changed:
                changed.append(obj)

        # Still something to do?
        if not changed:
            print_(u'No changes to make.')
            return

        # Confirm action.
        if confirm:
            if write and move:
                extra = u', move and write tags'
            elif write:
                extra = u' and write tags'
            elif move:
                extra = u' and move'
            else:
                extra = u''

            changed = ui.input_select_objects(
                u'Really modify%s' % extra, changed,
                lambda o: print_and_modify(o, mods, dels))

        # Apply changes to database and files
        with lib.transaction():
            for obj in changed:
                obj.try_sync(write, move)
Example #5
0
    def _edit_command(self, lib, opts, args):
        """The CLI command function for the `beet edit` command.
        """
        # Get the objects to edit.
        query = ui.decargs(args)
        items, albums = _do_query(lib, query, opts.album, False)
        objs = albums if opts.album else items
        if not objs:
            ui.print_(u'Nothing to edit.')
            return

        # Get the fields to edit.
        if opts.all:
            fields = None
        else:
            fields = self._get_fields(opts.album, opts.field)
        self.edit(opts.album, objs, fields)
Example #6
0
    def _edit_command(self, lib, opts, args):
        """The CLI command function for the `beet edit` command.
        """
        # Get the objects to edit.
        query = ui.decargs(args)
        items, albums = _do_query(lib, query, opts.album, False)
        objs = albums if opts.album else items
        if not objs:
            ui.print_("Nothing to edit.")
            return

        # Get the fields to edit.
        if opts.all:
            fields = None
        else:
            fields = self._get_fields(opts.album, opts.field)
        self.edit(opts.album, objs, fields)
Example #7
0
 def test_query_empty_album(self):
     with self.assertRaises(ui.UserError):
         commands._do_query(self.lib, (), True)
Example #8
0
 def test_query_empty(self):
     with self.assertRaises(ui.UserError):
         commands._do_query(self.lib, (), False)
Example #9
0
 def check_do_query(self, num_items, num_albums,
                    q=(), album=False, also_items=True):
     items, albums = commands._do_query(
         self.lib, q, album, also_items)
     self.assertEqual(len(items), num_items)
     self.assertEqual(len(albums), num_albums)
Example #10
0
 def test_query_empty_album(self):
     with self.assertRaises(ui.UserError):
         commands._do_query(self.lib, (), True)
Example #11
0
 def test_query_empty(self):
     with self.assertRaises(ui.UserError):
         commands._do_query(self.lib, (), False)