示例#1
0
 def _createFunc(parent, token):
     """This is used as createFunc-argument for Level.createWrappers."""
     if token.startswith('EXT:'):
         url = urllib.parse.unquote(token[4:]) # remove "EXT:"
         url = urls.URL(url)
         try:
             element = self.level.collect(url)
         except OSError as e:
             raise ValueError(str(e))
     else:
         element = self.level.collect(int(token))
     return Wrapper(element, parent=parent)
示例#2
0
    def load(self):
        """Load files and newfiles tables, creating the internal structure of File and Folder objects."""
        for elid, urlstring, elhash, verified in db.query(
                    'SELECT element_id, url, hash, verified FROM {p}files WHERE url LIKE ' +
                        "'{}%'".format('file://' + self.path.replace("'", "\\'"))):
            url = urls.URL(urlstring)
            if url.extension in self.extensions:
                self.addFile(url, id=elid, verified=verified, hash=elhash, store=False)

        toDelete = []
        for urlstring, elhash, verified in db.query("SELECT url, hash, verified FROM {p}newfiles "
            + "WHERE url LIKE '{}%'".format('file://' + self.path.replace("'", "\\'"))):
            url = urls.URL(urlstring)
            if url.extension in self.extensions:
                if url.path in self.files:
                    toDelete.append((urlstring,))
                    continue
                self.addFile(url, hash=elhash, verified=verified, store=False)
            else:
                toDelete.append((urlstring,))
        if len(toDelete):
            db.multiQuery('DELETE FROM {p}newfiles WHERE url=?', toDelete)
示例#3
0
def showRipMissingDialog():
    ans = list(
        db.query(
            "SELECT url, element_id FROM {p}files WHERE url LIKE 'audiocd://%'"
        ))
    from ...gui.dialogs import warning
    if len(ans) == 0:
        warning(
            translate("AudioCD Plugin", "no unripped tracks"),
            translate(
                "AudioCD Plugin",
                "Your database does not contain any unripped audio-cd tracks!")
        )
        return
    discids = {}
    for url, id in ans:
        url = urls.URL(url)
        discid, tracknr = parseNetloc(url)
        if discid not in discids:
            discids[discid] = (id, set())
        assert tracknr not in discids[discid][1]
        discids[discid][1].add(tracknr)
    from . import gui

    ans = gui.ImportAudioCDAction.askForDiscId()
    if not ans:
        return
    dev, discid, ntracks = ans
    if discid in discids:
        id, tracks = discids[discid]
        assert set(range(min(tracks), max(tracks) + 1)) == tracks
        from . import ripper
        rppr = ripper.Ripper(dev,
                             discid,
                             fromTrack=min(tracks),
                             toTrack=max(tracks))
        rppr.start()
        warning(
            translate("AudioCD Plugin", "unripped tracks found"),
            translate(
                "AudioCD Plugin",
                "The disc in the selected drive contains {} tracks "
                "that are marked as un-ripped in the database. Ripping started ..."
            ).format(len(tracks)))
示例#4
0
 def finish(self):
     elems = []
     for i, edit in enumerate(self.edits, start=1):
         url = urls.URL("audiocd://{0}.{1}{2}/{0}/{1}.flac".format(
                         self.discid, i, os.path.abspath(config.options.audiocd.rippath)))
         elem = self.level.collect(url)
         elTags = tags.Storage()
         elTags[tags.TITLE] = [edit.getValue()]
         elTags[tags.ALBUM] = [self.titleEdit.getValue()]
         elTags[tags.get('artist')] = [self.artistEdit.getValue()]
         elTags[tags.get('date')] = [self.dateEdit.getValue()]
         diff = tags.TagStorageDifference(None, elTags)
         self.level.changeTags({elem: diff})
         elems.append(elem)
     contTags = tags.Storage()
     contTags[tags.TITLE] = [self.titleEdit.getValue()]
     contTags[tags.ALBUM] = [self.titleEdit.getValue()]
     contTags[tags.get('date')] = [self.dateEdit.getValue()]
     contTags[tags.get('artist')] = [self.artistEdit.getValue()]
     cont = self.level.createContainer(contents=elems, type=ContainerType.Album,
                                       domain=domains.default(), tags=contTags)
     self.container = cont
     self.accept()
示例#5
0
def fillReleaseForDisc(MBrelease, discid):
    """Given a stub Release object *MBrelease* (as created by findReleasesForDiscid) and a disc id,
    creates recordings, works etc. for the given disc.
    """
    release = query("release", MBrelease.mbid,
                    ("recordings", )).find("release")

    pos, MBmedium = MBrelease.mediumForDiscid(discid)
    MBmedium.currentDiscid = discid
    from .elements import Recording, Medium
    # find the medium in the xml tree
    for medium in release.iterfind('medium-list/medium'):
        if int(medium.findtext('position')) == pos:
            break
    for track in medium.iterfind('track-list/track'):
        recording = track.find('recording')
        tracknr = int(track.findtext('number'))
        MBrec = Recording(recording.get("id"), int(track.findtext("position")),
                          MBmedium, tracknr)
        MBrec.tags.add("title", recording.findtext("title"))
        MBrec.backendUrl = urls.URL("audiocd://{0}.{1}{2}/{0}/{1}.flac".format(
            discid, tracknr, os.path.abspath(config.options.audiocd.rippath)))
    for _, MBrec in sorted(MBmedium.children.items()):
        MBrec.lookupInfo()
    MBmedium.insertWorks()
    if len(MBrelease.children) == 1:
        logging.debug(__name__,
                      'single child release -> removing release container')
        del MBrelease.children[pos]
        for p, child in MBmedium.children.items():
            MBrelease.insertChild(p, child)
        MBrelease.passTags(excludes=['title'])
    for p in list(MBrelease.children.keys()):
        if isinstance(MBrelease.children[p],
                      Medium) and MBrelease.children[p] != MBmedium:
            MBrelease.children[p].ignore = True