예제 #1
0
    def add_directory(self):
        """Add directory to the tagger."""
        current_directory = self.config.persist["current_directory"] or QtCore.QDir.homePath()
        current_directory = find_existing_path(unicode(current_directory))

        dir_list = []
        if not self.config.setting["toolbar_multiselect"]:
            directory = QtGui.QFileDialog.getExistingDirectory(self, "", current_directory)
            if directory:
                dir_list.append(directory)
        else:
            # Use a custom file selection dialog to allow the selection of multiple directories
            file_dialog = QtGui.QFileDialog(self, "", current_directory)
            file_dialog.setFileMode(QtGui.QFileDialog.DirectoryOnly)
            if sys.platform == "darwin": # The native dialog doesn't allow selecting >1 directory
                file_dialog.setOption(QtGui.QFileDialog.DontUseNativeDialog)
            tree_view = file_dialog.findChild(QtGui.QTreeView)
            tree_view.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
            list_view = file_dialog.findChild(QtGui.QListView, "listView")
            list_view.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)

            if file_dialog.exec_() == QtGui.QDialog.Accepted:
                dir_list = file_dialog.selectedFiles()

        if len(dir_list) == 1:
            self.config.persist["current_directory"] = dir_list[0]
        elif len(dir_list) > 1:
            (parent, dir) = os.path.split(str(dir_list[0]))
            self.config.persist["current_directory"] = parent

        for directory in dir_list:
            directory = unicode(directory)
            self.tagger.add_directory(directory)
예제 #2
0
    def add_directory(self):
        """Add directory to the tagger."""
        current_directory = self.config.persist["current_directory"] or QtCore.QDir.homePath()
        current_directory = find_existing_path(unicode(current_directory))

        dir_list = []
        if not self.config.setting["toolbar_multiselect"]:
            directory = QtGui.QFileDialog.getExistingDirectory(self, "", current_directory)
            if directory:
                dir_list.append(directory)
        else:
            # Use a custom file selection dialog to allow the selection of multiple directories
            file_dialog = QtGui.QFileDialog(self, "", current_directory)
            file_dialog.setFileMode(QtGui.QFileDialog.DirectoryOnly)
            if sys.platform == "darwin": # The native dialog doesn't allow selecting >1 directory
                file_dialog.setOption(QtGui.QFileDialog.DontUseNativeDialog)
            tree_view = file_dialog.findChild(QtGui.QTreeView)
            tree_view.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
            list_view = file_dialog.findChild(QtGui.QListView, "listView")
            list_view.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)

            if file_dialog.exec_() == QtGui.QDialog.Accepted:
                dir_list = file_dialog.selectedFiles()

        if len(dir_list) == 1:
            self.config.persist["current_directory"] = dir_list[0]
        elif len(dir_list) > 1:
            (parent, dir) = os.path.split(str(dir_list[0]))
            self.config.persist["current_directory"] = parent

        for directory in dir_list:
            directory = unicode(directory)
            self.tagger.add_directory(directory)
예제 #3
0
파일: util.py 프로젝트: rdswift/picard
def find_starting_directory():
    config = get_config()
    if config.setting["starting_directory"]:
        path = config.setting["starting_directory_path"]
    else:
        path = config.persist["current_directory"] or QtCore.QDir.homePath()
    return find_existing_path(path)
예제 #4
0
    def callback(self, objs):
        album = objs[0]
        current_directory = self.config.persist[
            "current_directory"] or QtCore.QDir.homePath()
        current_directory = find_existing_path(unicode(current_directory))
        filename, selected_format = QtGui.QFileDialog.getSaveFileNameAndFilter(
            None, "", current_directory, "Cuesheet (*.cue)")
        if filename:
            filename = unicode(filename)

            currentDiscNumber = None
            idx = 0
            cuesheet = None
            for track in album.tracks:
                if not currentDiscNumber or track.metadata[
                        "discnumber"] != currentDiscNumber:
                    if cuesheet:
                        cuesheet.write()
                    currentDiscNumber = track.metadata["discnumber"]
                    cuesheet = Cuesheet(filename, currentDiscNumber)
                    cuesheet.tracks = [CuesheetTrack(cuesheet, 0)] + [
                        CuesheetTrack(cuesheet, i + 1)
                        for i, x in enumerate(album.tracks)
                        if x.metadata["discnumber"] == currentDiscNumber
                    ]
                    t = cuesheet.tracks[0]
                    t.set("PERFORMER", album.metadata["albumartist"])
                    t.set("TITLE", album.metadata["album"])
                    t.set("REM", "MUSICBRAINZ_ALBUM_ID",
                          album.metadata["musicbrainz_albumid"])
                    t.set("REM", "MUSICBRAINZ_ALBUM_ARTIST_ID",
                          album.metadata["musicbrainz_albumartistid"])
                    if "date" in album.metadata:
                        t.set("REM", "DATE", album.metadata["date"])
                    index = 0.0
                    idx = 0

                mm = index / 60.0
                ss = (mm - int(mm)) * 60.0
                ff = (ss - int(ss)) * 75.0
                index += track.metadata.length / 1000.0
                t = cuesheet.tracks[idx + 1]
                t.set("TRACK", "%02d" % (idx + 1), "AUDIO")
                t.set("PERFORMER", track.metadata["artist"])
                t.set("TITLE", track.metadata["title"])
                t.set("REM", "MUSICBRAINZ_TRACK_ID",
                      track.metadata["musicbrainz_trackid"])
                t.set("REM", "MUSICBRAINZ_ARTIST_ID",
                      track.metadata["musicbrainz_artistid"])
                t.set("INDEX", "01", "%02d:%02d:%02d" % (mm, ss, ff))
                for file in track.linked_files:
                    audio_filename = file.filename
                    if os.path.dirname(filename) == os.path.dirname(
                            audio_filename):
                        audio_filename = os.path.basename(audio_filename)
                    cuesheet.tracks[idx + 1].set("FILE", audio_filename, "MP3")
                idx += 1

            cuesheet.write()
예제 #5
0
 def _restore_state(self):
     path = self.config.persist["current_browser_path"]
     if path:
         path = find_existing_path(unicode(path))
         index = self.dirmodel.index(path)
         self.selectionModel().select(index, QtGui.QItemSelectionModel.SelectCurrent)
         self.scrollTo(index)
         self.expand(index)
예제 #6
0
    def callback(self, objs):
        album = objs[0]
        current_directory = self.config.persist[
            "current_directory"] or QtCore.QDir.homePath()
        current_directory = find_existing_path(string_(current_directory))
        filename, selected_format = QtWidgets.QFileDialog.getSaveFileName(
            None, "", current_directory, "Cuesheet (*.cue)")
        if filename:
            filename = string_(filename)
            cuesheet = Cuesheet(filename)
            #try: cuesheet.read()
            #except IOError: pass
            while len(cuesheet.tracks) <= len(album.tracks):
                track = CuesheetTrack(cuesheet, len(cuesheet.tracks))
                cuesheet.tracks.append(track)
            #if len(cuesheet.tracks) > len(album.tracks) - 1:
            #    cuesheet.tracks = cuesheet.tracks[0:len(album.tracks)+1]

            t = cuesheet.tracks[0]
            t.set("PERFORMER", album.metadata["albumartist"])
            t.set("TITLE", album.metadata["album"])
            t.set("REM", "MUSICBRAINZ_ALBUM_ID",
                  album.metadata["musicbrainz_albumid"])
            t.set("REM", "MUSICBRAINZ_ALBUM_ARTIST_ID",
                  album.metadata["musicbrainz_albumartistid"])
            if "date" in album.metadata:
                t.set("REM", "DATE", album.metadata["date"])
            index = 0.0
            for i, track in enumerate(album.tracks):
                mm = index / 60.0
                ss = (mm - int(mm)) * 60.0
                ff = (ss - int(ss)) * 75.0
                index += track.metadata.length / 1000.0
                t = cuesheet.tracks[i + 1]
                t.set("TRACK", "%02d" % (i + 1), "AUDIO")
                t.set("PERFORMER", track.metadata["artist"])
                t.set("TITLE", track.metadata["title"])
                t.set("REM", "MUSICBRAINZ_TRACK_ID",
                      track.metadata["musicbrainz_trackid"])
                t.set("REM", "MUSICBRAINZ_ARTIST_ID",
                      track.metadata["musicbrainz_artistid"])
                t.set("INDEX", "01", "%02d:%02d:%02d" % (mm, ss, ff))
                for file in track.linked_files:
                    audio_filename = file.filename
                    extension = audio_filename.split(".")[-1].lower()
                    if os.path.dirname(filename) == os.path.dirname(
                            audio_filename):
                        audio_filename = os.path.basename(audio_filename)
                    if extension in ["mp3", "mp2", "m2a"]:
                        file_type = "MP3"
                    elif extension in ["aiff", "aif", "aifc"]:
                        file_type = "AIFF"
                    else:
                        file_type = "WAVE"
                    cuesheet.tracks[i].set("FILE", audio_filename, file_type)

            cuesheet.write()
예제 #7
0
 def _restore_state(self):
     path = self.config.persist["current_browser_path"]
     if path:
         path = find_existing_path(unicode(path))
         index = self.dirmodel.index(path)
         self.selectionModel().select(
             index, QtGui.QItemSelectionModel.SelectCurrent)
         self.scrollTo(index)
         self.expand(index)
예제 #8
0
 def _restore_state(self):
     if config.setting["starting_directory"]:
         path = config.setting["starting_directory_path"]
         scrolltype = QtGui.QAbstractItemView.PositionAtTop
     else:
         path = config.persist["current_browser_path"]
         scrolltype = QtGui.QAbstractItemView.PositionAtCenter
     if path:
         index = self.model.index(find_existing_path(unicode(path)))
         self.setCurrentIndex(index)
         self.expand(index)
         self.scrollTo(index, scrolltype)
예제 #9
0
 def _restore_state(self):
     if config.setting["starting_directory"]:
         path = config.setting["starting_directory_path"]
         scrolltype = QtWidgets.QAbstractItemView.PositionAtTop
     else:
         path = config.persist["current_browser_path"]
         scrolltype = QtWidgets.QAbstractItemView.PositionAtCenter
     if path:
         index = self.model.index(find_existing_path(path))
         self.setCurrentIndex(index)
         self.expand(index)
         self.scrollTo(index, scrolltype)
예제 #10
0
 def _restore_state(self):
     config = get_config()
     if config.setting["starting_directory"]:
         path = config.setting["starting_directory_path"]
         scrolltype = QtWidgets.QAbstractItemView.ScrollHint.PositionAtTop
     else:
         path = config.persist["current_browser_path"]
         scrolltype = QtWidgets.QAbstractItemView.ScrollHint.PositionAtCenter
     if path:
         index = self.model().index(find_existing_path(path))
         self.setCurrentIndex(index)
         self.expand(index)
         self.scrollTo(index, scrolltype)
예제 #11
0
    def callback(self, objs):
        album = objs[0]
        current_directory = self.config.persist["current_directory"] or QtCore.QDir.homePath()
        current_directory = find_existing_path(unicode(current_directory))
        filename, selected_format = QtGui.QFileDialog.getSaveFileNameAndFilter(
            None, "", current_directory, "Cuesheet (*.cue)"
        )
        if filename:
            filename = unicode(filename)
            cuesheet = Cuesheet(filename)
            # try: cuesheet.read()
            # except IOError: pass
            while len(cuesheet.tracks) <= len(album.tracks):
                track = CuesheetTrack(cuesheet, len(cuesheet.tracks))
                cuesheet.tracks.append(track)
            # if len(cuesheet.tracks) > len(album.tracks) - 1:
            #    cuesheet.tracks = cuesheet.tracks[0:len(album.tracks)+1]

            t = cuesheet.tracks[0]
            t.set("PERFORMER", album.metadata["albumartist"])
            t.set("TITLE", album.metadata["album"])
            t.set("REM", "MUSICBRAINZ_ALBUM_ID", album.metadata["musicbrainz_albumid"])
            t.set("REM", "MUSICBRAINZ_ALBUM_ARTIST_ID", album.metadata["musicbrainz_albumartistid"])
            if "date" in album.metadata:
                t.set("REM", "DATE", album.metadata["date"])
            index = 0.0
            for i, track in enumerate(album.tracks):
                mm = index / 60.0
                ss = (mm - int(mm)) * 60.0
                ff = (ss - int(ss)) * 75.0
                index += track.metadata.length / 1000.0
                t = cuesheet.tracks[i + 1]
                t.set("TRACK", "%02d" % (i + 1), "AUDIO")
                t.set("PERFORMER", track.metadata["artist"])
                t.set("TITLE", track.metadata["title"])
                t.set("REM", "MUSICBRAINZ_TRACK_ID", track.metadata["musicbrainz_trackid"])
                t.set("REM", "MUSICBRAINZ_ARTIST_ID", track.metadata["musicbrainz_artistid"])
                t.set("INDEX", "01", "%02d:%02d:%02d" % (mm, ss, ff))
                for file in track.linked_files:
                    audio_filename = file.filename
                    if os.path.dirname(filename) == os.path.dirname(audio_filename):
                        audio_filename = os.path.basename(audio_filename)
                    cuesheet.tracks[i].set("FILE", audio_filename, "MP3")

            cuesheet.write()
예제 #12
0
 def add_files(self):
     """Add files to the tagger."""
     current_directory = self.config.persist["current_directory"] or QtCore.QDir.homePath()
     current_directory = find_existing_path(unicode(current_directory))
     formats = []
     extensions = []
     for exts, name in supported_formats():
         exts = ["*" + e for e in exts]
         formats.append("%s (%s)" % (name, " ".join(exts)))
         extensions.extend(exts)
     formats.sort()
     extensions.sort()
     formats.insert(0, _("All Supported Formats") + " (%s)" % " ".join(extensions))
     files = QtGui.QFileDialog.getOpenFileNames(self, "", current_directory, u";;".join(formats))
     if files:
         files = map(unicode, files)
         self.config.persist["current_directory"] = os.path.dirname(files[0])
         self.tagger.add_files(files)
예제 #13
0
 def add_files(self):
     """Add files to the tagger."""
     current_directory = self.config.persist["current_directory"] or QtCore.QDir.homePath()
     current_directory = find_existing_path(unicode(current_directory))
     formats = []
     extensions = []
     for exts, name in supported_formats():
         exts = ["*" + e for e in exts]
         formats.append("%s (%s)" % (name, " ".join(exts)))
         extensions.extend(exts)
     formats.sort()
     extensions.sort()
     formats.insert(0, _("All Supported Formats") + " (%s)" % " ".join(extensions))
     files = QtGui.QFileDialog.getOpenFileNames(self, "", current_directory, u";;".join(formats))
     if files:
         files = map(unicode, files)
         self.config.persist["current_directory"] = os.path.dirname(files[0])
         self.tagger.add_files(files)
예제 #14
0
파일: util.py 프로젝트: Hellnation13/picard
def find_starting_directory():
    if config.setting["starting_directory"]:
        path = config.setting["starting_directory_path"]
    else:
        path = config.persist["current_directory"] or QtCore.QDir.homePath()
    return find_existing_path(unicode(path))
예제 #15
0
 def _restore_state(self):
     path = config.persist["current_browser_path"]
     if path:
         index = self.model.index(find_existing_path(unicode(path)))
         self.setCurrentIndex(index)
         self.expand(index)
예제 #16
0
    def callback(self, objs):
        current_directory = (self.config.persist["current_directory"]
                             or QtCore.QDir.homePath())
        current_directory = find_existing_path(unicode(current_directory))
        # Default playlist filename set as "%albumartist% - %album%.m3u8",
        # except where "Various Artists" is suppressed
        if _debug_level > 1:
            log.debug(
                "{}: VARIOUS_ARTISTS_ID is {}, musicbrainz_albumartistid is {}"
                .format(PLUGIN_NAME, VARIOUS_ARTISTS_ID,
                        objs[0].metadata["musicbrainz_albumartistid"]))
        if objs[0].metadata["musicbrainz_albumartistid"] != VARIOUS_ARTISTS_ID:
            default_filename = get_safe_filename(
                objs[0].metadata["albumartist"] + " - " +
                objs[0].metadata["album"] + ".m3u8")
        else:
            default_filename = get_safe_filename(objs[0].metadata["album"] +
                                                 ".m3u8")
        if _debug_level > 1:
            log.debug("{}: default playlist filename sanitized to {}".format(
                PLUGIN_NAME, default_filename))
        b_filename, b_selected_format = QtGui.QFileDialog.getSaveFileNameAndFilter(
            None, "Save new playlist",
            os.path.join(current_directory, default_filename),
            "Playlist (*.m3u8 *.m3u)")
        if b_filename:
            filename = unicode(b_filename)
            playlist = Playlist(filename)
            playlist.add_header(u"#EXTM3U")

            for album in objs:
                for track in album.tracks:
                    if track.linked_files:
                        entry = PlaylistEntry(playlist, len(playlist.entries))
                        playlist.entries.append(entry)

                        # M3U EXTINF row
                        track_length_seconds = int(
                            round(track.metadata.length / 1000.0))
                        # EXTINF format assumed to be fixed as follows:
                        entry.add(
                            u"#EXTINF:{duration:d},{artist} - {title}".format(
                                duration=track_length_seconds,
                                artist=track.metadata["artist"],
                                title=track.metadata["title"]))

                        # M3U URL row - assumes only one file per track
                        audio_filename = track.linked_files[0].filename
                        if _debug_level > 1:
                            for i, file in enumerate(track.linked_files):
                                log.debug("{}: linked_file {}: {}".format(
                                    PLUGIN_NAME, i, str(file)))
                        # If playlist is in same directory as audio files, then use
                        # local (relative) pathname, otherwise use absolute pathname
                        if _debug_level > 1:
                            log.debug(
                                "{}: audio_filename: {}, selected dir: {}".
                                format(PLUGIN_NAME, audio_filename,
                                       os.path.dirname(filename)))
                        if os.path.dirname(filename) == os.path.dirname(
                                audio_filename):
                            audio_filename = os.path.basename(audio_filename)
                        entry.add(unicode(audio_filename))

            playlist.write()
예제 #17
0
 def _restore_state(self):
     path = config.persist["current_browser_path"]
     if path:
         index = self.model.index(find_existing_path(unicode(path)))
         self.setCurrentIndex(index)
         self.expand(index)
예제 #18
0
 def callback(self, objs):
     current_directory = (self.config.persist["current_directory"]
                          or QtCore.QDir.homePath())
     current_directory = find_existing_path(unicode(current_directory))
     # Default playlist filename set as "%albumartist% - %album%.m3u8",
     # except where "Various Artists" is suppressed
     if _debug_level > 1:
         log.debug("{}: VARIOUS_ARTISTS_ID is {}, musicbrainz_albumartistid is {}".format(
                 PLUGIN_NAME, VARIOUS_ARTISTS_ID,
                 objs[0].metadata["musicbrainz_albumartistid"]))
     if objs[0].metadata["musicbrainz_albumartistid"] != VARIOUS_ARTISTS_ID:
         default_filename = get_safe_filename(
             objs[0].metadata["albumartist"] + " - "
             + objs[0].metadata["album"] + ".m3u8"
         )
     else:
         default_filename = get_safe_filename(
             objs[0].metadata["album"] + ".m3u8"
         )
     if _debug_level > 1:
         log.debug("{}: default playlist filename sanitized to {}".format(
                 PLUGIN_NAME, default_filename))
     b_filename, b_selected_format = QtGui.QFileDialog.getSaveFileNameAndFilter(
         None, "Save new playlist",
         os.path.join(current_directory, default_filename),
         "Playlist (*.m3u8 *.m3u)"
     )
     if b_filename:
         filename = unicode(b_filename)
         playlist = Playlist(filename)
         playlist.add_header(u"#EXTM3U")
         
         for album in objs:
             for track in album.tracks:
                 if track.linked_files:
                     entry = PlaylistEntry(playlist, len(playlist.entries))
                     playlist.entries.append(entry)
                     
                     # M3U EXTINF row
                     track_length_seconds = int(round(track.metadata.length / 1000.0))
                     # EXTINF format assumed to be fixed as follows:
                     entry.add(u"#EXTINF:{duration:d},{artist} - {title}".format(
                         duration=track_length_seconds,
                         artist=track.metadata["artist"],
                         title=track.metadata["title"]
                         )
                     )
                     
                     # M3U URL row - assumes only one file per track
                     audio_filename = track.linked_files[0].filename
                     if _debug_level > 1:
                         for i, file in enumerate(track.linked_files):
                             log.debug("{}: linked_file {}: {}".format(
                                 PLUGIN_NAME, i, str(file)))
                     # If playlist is in same directory as audio files, then use
                     # local (relative) pathname, otherwise use absolute pathname
                     if _debug_level > 1:
                         log.debug("{}: audio_filename: {}, selected dir: {}".format(
                                 PLUGIN_NAME, audio_filename, os.path.dirname(filename)))
                     if os.path.dirname(filename) == os.path.dirname(audio_filename):
                         audio_filename = os.path.basename(audio_filename)
                     entry.add(unicode(audio_filename))
         
         playlist.write()