Ejemplo n.º 1
0
    def ShowAlbumView(self, newalbums):
        self.cli.ShowCursor(False)
        self.cli.ClearScreen()
        self.cli.SetCursor(1, 1)
        self.cli.SetColor("1;30", "40")
        self.cli.PrintText("Press Ctrl-D to exit without any changes.")

        # Calculate the positions of the UI element
        listx = 1
        listy = 3
        listw = self.maxw - 2  # -2 for some space around
        listh = self.maxh - 6  # -6 for info on top and the button bar below

        # List Views
        albumview = AlbumView("New Albums", listx, listy, listw, listh)
        albumview.SetData(newalbums)

        # Buttons
        buttons = ButtonView(align="middle")
        buttons.AddButton("↑", "Go up")
        buttons.AddButton("↓", "Go down")
        buttons.AddButton("↵", "Select for Import")

        # Draw once
        buttons.Draw(0, self.maxh - 2, self.maxw)

        while True:
            # Show everything
            albumview.Draw()
            self.cli.FlushScreen()

            # Handle keys
            key = self.cli.GetKey()
            if key == "Ctrl-D":
                return None

            elif key == "enter":
                return albumview.GetSelectedData()

            else:
                albumview.HandleKey(key)
Ejemplo n.º 2
0
class genres(MDBModule):
    def __init__(self, config, database):
        MDBModule.__init__(self)

        self.db  = database
        self.cfg = config


    @staticmethod
    def MDBM_CreateArgumentParser(parserset, modulename):
        parser = parserset.add_parser(modulename, help="Manage genres using a CLI GUI")
        parser.set_defaults(module=modulename)
        return parser


    def ShowUI(self):
        cli  = Text()
        cli.ShowCursor(False)
        cli.ClearScreen()
        cli.SetCursor(1, 1)
        cli.SetColor("1;30", "40")
        cli.PrintText("New sub genre belong to selected main genre.  Ctrl-D to exit.")

        maxw, maxh = cli.GetScreenSize()

        # The GUI must have two lists: main genre, sub genre
        # main and sub genre shall be encapsulated by a frame
        listwidth   = maxw // 2 - 1           # - 1 for some space around
        listystart  = 3
        listheight  = maxh - (listystart + 3)   # +3 for a ButtonView
        list1xstart = 1
        list2xstart = 2 + listwidth

        # List Views
        self.genreview    = GenreView   (self.cfg, self.db, 
                "Main Genre", list1xstart, listystart, listwidth, listheight)
        self.subgenreview = SubGenreView(self.cfg, self.db, self.genreview, 
                "Sub Genre",  list2xstart, listystart, listwidth, listheight)

        # Buttons
        self.buttons = ButtonView(align="middle")
        self.buttons.AddButton("a", "Add new tag")
        self.buttons.AddButton("e", "Edit tag")
        self.buttons.AddButton("r", "Remove tag")
        self.buttons.AddButton("↹", "Select list")

        # Composition
        tabgroup = TabGroup()
        tabgroup.AddPane(self.genreview)
        tabgroup.AddPane(self.subgenreview)

        # Draw once
        self.buttons.Draw(0, maxh-2, maxw)


        key = " "
        selectedmaingenre = 0   # trace selected main genre to update subgenre view
        while key != "Ctrl-D":
            # Show everything
            self.genreview.Draw()
            self.subgenreview.Draw()
            cli.FlushScreen()

            # Handle keys
            key = cli.GetKey()
            tabgroup.HandleKey(key)

            genre = self.genreview.GetSelectedData()
            if genre["id"] != selectedmaingenre:
                selectedmaingenre = genre["id"]
                self.subgenreview.UpdateView()


        cli.ClearScreen()
        cli.SetCursor(0,0)
        cli.ShowCursor(True)
        return


    # return exit-code
    def MDBM_Main(self, args):

        self.ShowUI()

        # Update caches with the new tags
        pipe = NamedPipe(self.cfg.server.fifofile)
        pipe.WriteLine("refresh")

        return 0
Ejemplo n.º 3
0
    def ShowImportDialog(self, albumpath):
        self.cli.ShowCursor(False)
        self.cli.ClearScreen()
        self.cli.SetColor("1;30", "40")
        self.cli.SetCursor(1, 1)
        self.cli.PrintText("Press Ctrl-D to exit without any changes.")
        self.cli.SetCursor(1, 2)
        self.cli.PrintText(
            "\033[1;31m✘\033[1;30m marks invalid data, \033[1;32m✔\033[1;30m marks valid data."
        )
        self.cli.SetCursor(1, 3)
        self.cli.PrintText("MusicDB file naming scheme:")
        self.cli.SetCursor(3, 4)
        self.cli.PrintText(
            "{artistname}/{albumrelease} - {albumname}/{songnumber} {songname}.{extension}"
        )
        self.cli.SetCursor(3, 5)
        self.cli.PrintText(
            "{artistname}/{albumrelease} - {albumname}/{cdnumber}-{songnumber} {songname}.{extension}"
        )

        # Calculate the positions of the UI element
        headh = 5  # n lines high headline
        pathh = 2
        dialogx = 1
        dialogy = 2 + headh
        dialogw = self.maxw - 2
        dialogh = 9
        listx = 1
        listy = dialogy + dialogh + 1
        listw = self.maxw - 2
        listh = self.maxh - (headh + dialogh + pathh + 3 * 2)
        pathx = dialogx + 1
        pathw = dialogw - 2
        pathy = listy + listh + 1

        # List Views
        songview = SongView(self.cfg, albumpath, "New Songs", listx, listy,
                            listw, listh)
        albumdialog = Dialog("Album Import", dialogx, dialogy, dialogw,
                             dialogh)
        albumdialog.RemoveButton("Cancel")
        albumdialog.RemoveButton("Commit")

        artistinput = FileNameInput()
        nameinput = FileNameInput()
        releaseinput = TextInput()
        origininput = TextInput()
        artworkinput = BoolInput()
        musicaiinput = BoolInput()
        lyricsinput = BoolInput()

        albumdialog.AddInput("Artist name:", artistinput,
                             "Correct name of the album artist")
        albumdialog.AddInput("Album name:", nameinput,
                             "Correct name of the album (no release year)")
        albumdialog.AddInput("Release date:", releaseinput,
                             "Year with 4 digits like \"2017\"")
        albumdialog.AddInput(
            "Origin:", origininput,
            "\"iTunes\", \"bandcamp\", \"CD\", \"internet\", \"music163\"")
        albumdialog.AddInput("Import artwork:", artworkinput,
                             "Import the artwork to MusicDB")
        albumdialog.AddInput("Import lyrics:", lyricsinput,
                             "Try to import lyrics from file")
        albumdialog.AddInput("Predict genre:", musicaiinput,
                             "Runs MusicAI to predict the song genres")

        # Initialize dialog
        albumdirname = os.path.split(albumpath)[1]
        artistdirname = os.path.split(albumpath)[0]
        metadata = self.GetAlbumMetadata(albumpath)
        if metadata:
            origin = str(metadata["origin"])
        else:
            origin = "Internet"
        analresult = self.fs.AnalyseAlbumDirectoryName(albumdirname)
        if analresult:
            release = str(analresult["release"])
            albumname = analresult["name"]
        else:
            # suggest the release date from meta data - the user can change when it's wrong
            if metadata:
                release = str(metadata["releaseyear"])
            else:
                release = "20??"
            albumname = albumdirname

        artistinput.SetData(artistdirname)
        nameinput.SetData(albumname)
        releaseinput.SetData(release)
        origininput.SetData(origin)
        artworkinput.SetData(True)

        if self.cfg.debug.disableai:
            musicaiinput.SetData(False)
        else:
            musicaiinput.SetData(True)

        if metadata["lyrics"]:
            lyricsinput.SetData(True)
        else:
            lyricsinput.SetData(False)

        # Initialize list
        songview.UpdateUI()

        # Buttons
        buttons = ButtonView(align="middle")
        buttons.AddButton("↹", "Select list")
        buttons.AddButton("W", "Rename files Write to database")

        # Composition
        tabgroup = TabGroup()
        tabgroup.AddPane(albumdialog)
        tabgroup.AddPane(songview)

        # Draw once
        buttons.Draw(0, self.maxh - 2, self.maxw)

        while True:
            artistname = artistinput.GetData()
            albumname = nameinput.GetData()
            releasedate = releaseinput.GetData()
            origin = origininput.GetData()
            artwork = artworkinput.GetData()
            lyrics = lyricsinput.GetData()
            musicai = musicaiinput.GetData()

            # Show everything
            songview.Draw()
            albumdialog.Draw()
            self.ShowArtistValidation(artistname, pathx, pathy, pathw)
            self.ShowAlbumValidation(artistname, albumname, releasedate, pathx,
                                     pathy + 1, pathw)
            self.cli.FlushScreen()

            # Handle keys
            key = self.cli.GetKey()
            if key == "Ctrl-D":
                return None

            elif key == "W":
                # Returns a dicrionary
                data = {}
                data["oldalbumpath"] = albumpath
                data["artistname"] = artistname
                data["albumname"] = albumname
                data["releasedate"] = releasedate
                data["origin"] = origin
                data["runartwork"] = artwork
                data["runlyrics"] = lyrics
                data["runmusicai"] = musicai
                data["songs"] = songview.GetData()
                return data

            else:
                tabgroup.HandleKey(key)
Ejemplo n.º 4
0
class moods(MDBModule):
    def __init__(self, config, database):
        MDBModule.__init__(self)

        self.db = database
        self.cfg = config

    @staticmethod
    def MDBM_CreateArgumentParser(parserset, modulename):
        parser = parserset.add_parser(modulename,
                                      help="Manage mood-tags using a CLI GUI")
        parser.set_defaults(module=modulename)
        return parser

    def ShowUI(self):
        cli = Text()
        cli.ShowCursor(False)
        cli.ClearScreen()
        cli.SetCursor(1, 1)
        cli.SetColor("1;30", "40")
        cli.PrintText("Ctrl-D to exit.")

        maxw, maxh = cli.GetScreenSize()

        # Calculate the positions of the UI elements
        gridx = 1
        gridy = 3
        gridw = maxw - 2  # -2 for some space around
        gridh = 2 + 2 * 3  # 2 for the frame + 2 rows with height 3
        listx = 1
        listy = gridy + gridh + 1  # start where the grind ends + 1 space
        listw = maxw - 2  # -2 for some space around
        listh = maxh - (listy + 3)  # +3 for the button bar below

        # List Views
        self.moodlist = MoodView(self.cfg, self.db, "Mood list", listx, listy,
                                 listw, listh)
        self.moodgrid = MoodGrid(self.cfg, self.db, "Mood grid", gridx, gridy,
                                 gridw, gridh)

        self.moodgrid.moodlistcrossref = self.moodlist
        self.moodlist.moodgridcrossref = self.moodgrid

        # Buttons
        self.buttons = ButtonView(align="middle")
        self.buttons.AddButton("a", "Add new tag")
        self.buttons.AddButton("e", "Edit tag")
        self.buttons.AddButton("r", "Remove tag")
        self.buttons.AddButton("↹", "Select view")

        # Composition
        tabgroup = TabGroup()
        tabgroup.AddPane(self.moodlist)
        tabgroup.AddPane(self.moodgrid)

        # Draw once
        self.buttons.Draw(0, maxh - 2, maxw)

        key = " "
        while key != "Ctrl-D":
            # Show everything
            self.moodlist.Draw()
            self.moodgrid.Draw()
            cli.FlushScreen()

            # Handle keys
            key = cli.GetKey()
            tabgroup.HandleKey(key)

        cli.ClearScreen()
        cli.SetCursor(0, 0)
        cli.ShowCursor(True)
        return

    # return exit-code
    def MDBM_Main(self, args):

        self.ShowUI()

        # Update caches with the new tags
        pipe = NamedPipe(self.cfg.server.fifofile)
        pipe.WriteLine("refresh")

        return 0
Ejemplo n.º 5
0
    def ShowUI(self):
        cli  = Text()
        cli.ShowCursor(False)
        cli.ClearScreen()
        maxw, maxh = cli.GetScreenSize()

        # List Views
        self.orphanpathview  = OrphanPathView("Orphan Paths", x=1, y=3, w=maxw//2-1, h=maxh-6)
        self.orphanpathview.SetData(self.newartists, self.newalbums, self.newsongs)

        self.orphanentryview = OrphanEntryView("Orphan DB Entries", x=maxw//2+1, y=3, w=maxw//2-1, h=maxh-6)
        self.orphanentryview.SetData(self.lostartists, self.lostalbums, self.lostsongs)

        # Buttons
        lbuttons = ButtonView(align="left")
        lbuttons.AddButton("a", "Add path to database")
        lbuttons.AddButton("↑", "Go up")
        lbuttons.AddButton("↓", "Go down")
        
        mbuttons = ButtonView(align="middle")
        mbuttons.AddButton("u", "Update database entry path")

        rbuttons = ButtonView(align="right")
        rbuttons.AddButton("↑", "Go up")
        rbuttons.AddButton("↓", "Go down")
        rbuttons.AddButton("r", "Remove song from database")
        
        bbuttons = ButtonView() # bottom-buttons
        bbuttons.AddButton("c", "Check again")
        bbuttons.AddButton("↹", "Select list")
        bbuttons.AddButton("q", "Quit")
        
        # Draw ButtonViews
        w = (maxw // 3) - 2
        lbuttons.Draw(2,         1,      w)
        mbuttons.Draw(maxw//3,   1,      w)
        rbuttons.Draw(2*maxw//3, 1,      w)
        bbuttons.Draw(2,         maxh-2, maxw)

        # Draw Lists
        self.orphanpathview.Draw()
        self.orphanentryview.Draw()

        # Create Tab group
        tabgroup = TabGroup()
        tabgroup.AddPane(self.orphanpathview)
        tabgroup.AddPane(self.orphanentryview)

        key = " "
        while key != "q" and key != "Ctrl-D":
            cli.FlushScreen()
            key = cli.GetKey()
            tabgroup.HandleKey(key)

            # Update Views
            if key == "c":
                self.UpdateUI()

            # Update Database
            if key == "u":
                newdata = self.orphanpathview.GetSelectedData()
                olddata = self.orphanentryview.GetSelectedData()

                # check if both are songs, albums or artists
                if newdata[0] != olddata[0]:
                    continue
                target  = newdata[0]
                newpath = newdata[1]
                entryid = olddata[1]["id"]
                self.UpdateDatabase(target, entryid, newpath)
                self.UpdateUI()

            # Add To Database
            if key == "a":
                newdata = self.orphanpathview.GetSelectedData()

                target  = newdata[0]
                newpath = newdata[1]
                self.AddToDatabase(target, newpath)

            # Remove From Database
            if key == "r":
                data = self.orphanentryview.GetSelectedData()

                target   = data[0]
                targetid = data[1]["id"]
                self.RemoveFromDatabase(target, targetid)
                self.UpdateUI()


        cli.ClearScreen()
        cli.SetCursor(0,0)
        cli.ShowCursor(True)
        return