示例#1
0
def getDevices():
    db = Amarok.checkAndGetDB()
    query = "SELECT id,lastmountpoint FROM devices"
    uni.printForDevelopers("Query - getDevices : " + query)
    db.query(query)
    r = db.store_result()
    return r.fetch_row(0)
示例#2
0
def deleteAlbum(_albumId):
    db = Amarok.checkAndGetDB()
    queryUpdate = "DELETE FROM albums WHERE id=%s" % (_albumId)
    uni.printForDevelopers("Query - deleteAlbum : " + queryUpdate)
    db.query(queryUpdate)
    db.commit()
    return True
示例#3
0
def changeArtistWithAnother(_currentArtistId, _artistWillBeSelectedId):
    db = Amarok.checkAndGetDB()
    queryUpdate1 = "UPDATE tracks SET artist=%s WHERE artist=%s" % (_artistWillBeSelectedId, _currentArtistId)
    uni.printForDevelopers("Query - changeArtistWithAnother - queryUpdate1 : " + queryUpdate1)
    db.query(queryUpdate1)
    db.commit()
    try:
        db = Amarok.checkAndGetDB()
        queryUpdate2 = "UPDATE albums SET artist=%s WHERE artist=%s" % (_artistWillBeSelectedId, _currentArtistId)
        uni.printForDevelopers("Query - changeArtistWithAnother - queryUpdate2 : " + queryUpdate2)
        db.query(queryUpdate2)

        db.commit()
    except Amarok.getMySQLModule().IntegrityError as error:
        db = Amarok.checkAndGetDB()
        db.query("SELECT * FROM albums WHERE name IN (SELECT name FROM albums WHERE artist=%s) AND artist=%s" % (
                _artistWillBeSelectedId, _currentArtistId))
        r = db.store_result()
        rows = r.fetch_row(0)
        for row in rows:
            currentAlbumId = row[0]
            currentAlbumName = row[1]
            db = Amarok.checkAndGetDB()
            db.query("SELECT * FROM albums WHERE name='%s' AND artist=%s" % (currentAlbumName, _artistWillBeSelectedId))
            r = db.store_result()
            srows = r.fetch_row(0)
            if len(srows) > 0:
                albumWillBeSelectedId = srows[0][0]
                changeAlbumWithAnother(currentAlbumId, albumWillBeSelectedId)
                deleteAlbum(currentAlbumId)
    return True
示例#4
0
def getAllMusicFilePathsByAlbumArtistId(_artistId):
    db = Amarok.checkAndGetDB()
    query = """
SELECT
    REPLACE(
        CONCAT(
            CASE WHEN devices.lastmountpoint IS NOT NULL THEN devices.lastmountpoint ELSE '' END,
            SUBSTRING( urls.rpath , 2 )),
        CONCAT('/',
                CONCAT( CASE WHEN devices.lastmountpoint IS NOT NULL THEN devices.lastmountpoint ELSE '' END,
                    SUBSTRING( urls.rpath , 2 )))
    , '') AS 'filePath'
FROM tracks
INNER JOIN urls ON urls.id = tracks.url
LEFT JOIN devices ON devices.id = urls.deviceid
LEFT JOIN albums ON albums.id = tracks.album
LEFT JOIN artists albumartists ON albumartists.id = albums.artist
WHERE albums.artist=""" + str(_artistId) + " ORDER BY filePath "
    uni.printForDevelopers("Query - getAllMusicFilePathsByArtistId : " + query)
    db.query(query)
    r = db.store_result()
    musicFileValues = []
    rows = r.fetch_row(0)
    for row in rows:
        musicFileValues.append(row[0])
    return musicFileValues
示例#5
0
def getAllArtistsValues(_filter=""):
    db = Amarok.checkAndGetDB()
    _filter = str(_filter).strip()
    query = """
SELECT DISTINCT
artists.id,
artists.name
FROM tracks
INNER JOIN urls ON urls.id = tracks.url
LEFT JOIN devices ON devices.id = urls.deviceid
LEFT JOIN artists ON artists.id = tracks.artist
LEFT JOIN albums ON albums.id = tracks.album
LEFT JOIN artists albumartists ON albumartists.id = albums.artist
LEFT JOIN years ON years.id = tracks.year
LEFT JOIN genres ON genres.id = tracks.genre
LEFT JOIN images ON images.id = albums.image
LEFT JOIN statistics ON statistics.url = tracks.url
LEFT JOIN lyrics ON lyrics.url = urls.id
"""
    query += getSQLConditionByFilter(_filter, True) + " ORDER BY artists.name "
    uni.printForDevelopers("Query - getAllArtistsValues : " + query)
    db.query(query)
    r = db.store_result()
    musicFileValues = []
    rows = r.fetch_row(0)
    for row in rows:
        musicFileValues.append({})
        musicFileValues[-1]["id"] = row[0]
        musicFileValues[-1]["name"] = row[1]
    return musicFileValues
示例#6
0
def getOrInsertGenre(_genre):
    db = Amarok.checkAndGetDB()
    for sqlCommand in Databases.getAmendedSQLSelectOrInsertAndSelectQueries("genres", "id", {
        "name": "'" + Databases.correctForSql(_genre) + "'"}):
        uni.printForDevelopers("Query - getOrInsertGenre : " + sqlCommand)
        db.query(sqlCommand)
    r = db.store_result()
    return str(r.fetch_row(0)[0][0])
示例#7
0
def getOrInsertAlbum(_album, _artistId):
    db = Amarok.checkAndGetDB()
    for sqlCommand in Databases.getAmendedSQLSelectOrInsertAndSelectQueries("albums", "id", {
        "name": "'" + Databases.correctForSql(_album) + "'", "artist": "'" + _artistId + "'"}):
        uni.printForDevelopers("Query - getOrInsertAlbum : " + sqlCommand)
        db.query(sqlCommand)
    r = db.store_result()
    return str(r.fetch_row(0)[0][0])
示例#8
0
def getArtistId(_artist):
    db = Amarok.checkAndGetDB()
    query = "SELECT id FROM artists WHERE name='%s'" % (Databases.correctForSql(_artist))
    uni.printForDevelopers("Query - getArtistId : " + query)
    db.query(query)
    r = db.store_result()
    rows = r.fetch_row(0)
    if len(rows) > 0:
        return str(rows[0][0])
    return None
示例#9
0
def getArtistName(_artistId):
    db = Amarok.checkAndGetDB()
    query = "SELECT name FROM artists WHERE id=%s" % _artistId
    uni.printForDevelopers("Query - getArtistName : " + query)
    db.query(query)
    r = db.store_result()
    musicFileValues = []
    rows = r.fetch_row(0)
    if len(rows) > 0:
        return str(rows[0][0])
    return None
示例#10
0
def getAllMusicFileValuesWithNames(_filter="", _artistId=None):
    db = Amarok.checkAndGetDB()
    query = """
SELECT tracks.id,
    REPLACE(
        CONCAT(CASE WHEN devices.lastmountpoint IS NOT NULL THEN devices.lastmountpoint ELSE '' END,
            SUBSTRING( urls.rpath , 2 )),
        CONCAT('/',
                CONCAT(CASE WHEN devices.lastmountpoint IS NOT NULL THEN devices.lastmountpoint ELSE '' END,
                    SUBSTRING( urls.rpath , 2 )))
    , '') AS 'filePath',
tracks.title,
tracks.artist AS 'artistId',
tracks.album AS 'albumId',
albums.artist AS 'albumArtistId',
tracks.year AS 'yearId',
tracks.genre AS 'genreId',
tracks.tracknumber AS 'trackNumber',
tracks.comment AS 'comment',
artists.name AS 'artist',
albums.name AS 'album',
albumartists.name AS 'albumArtist',
years.name AS 'year',
genres.name AS 'genre',
images.path AS 'imagePath',
statistics.rating,
lyrics.lyrics
FROM tracks
INNER JOIN urls ON urls.id = tracks.url
LEFT JOIN devices ON devices.id = urls.deviceid
LEFT JOIN artists ON artists.id = tracks.artist
LEFT JOIN albums ON albums.id = tracks.album
LEFT JOIN artists albumartists ON albumartists.id = albums.artist
LEFT JOIN years ON years.id = tracks.year
LEFT JOIN genres ON genres.id = tracks.genre
LEFT JOIN images ON images.id = albums.image
LEFT JOIN statistics ON statistics.url = tracks.url
LEFT JOIN lyrics ON lyrics.url = urls.id
"""
    isAddWhere = True
    if _artistId:
        query += " WHERE (tracks.artist=" + str(_artistId) + " OR albums.artist=" + str(_artistId) + ") "
        isAddWhere = False
    query += getSQLConditionByFilter(_filter, isAddWhere) + " ORDER BY filePath "
    uni.printForDevelopers("Query - getAllMusicFileValuesWithNames : " + query)
    c = db.cursor(Amarok.getCursors().DictCursor)
    c.execute(query)
    musicFileValues = []
    for rows in c.fetchall():
        musicFileValues.append({})
        for key in rows.keys():
            musicFileValues[-1][key] = Databases.correctForUser(rows[key])
    return musicFileValues
示例#11
0
def getDirectoriesAndValues(_filter=""):
    db = Amarok.checkAndGetDB()
    query = """
SELECT DISTINCT
REPLACE(
    CONCAT(CASE WHEN devices.lastmountpoint IS NOT NULL THEN devices.lastmountpoint ELSE '' END,
        SUBSTRING(urls.rpath , 2)),
    CONCAT('/',
        SUBSTRING_INDEX(
            CONCAT(CASE WHEN devices.lastmountpoint IS NOT NULL THEN devices.lastmountpoint ELSE '' END,
                SUBSTRING(urls.rpath , 2)),
            '/' , -1))
, '') AS 'dirPath',
images.path AS 'imagePath',
artists.name AS 'artistName',
albums.name AS 'albumName',
years.name AS 'yearName',
genres.name AS 'genreName'
FROM tracks
LEFT JOIN urls ON urls.id = tracks.url
LEFT JOIN devices ON devices.id = urls.deviceid
LEFT JOIN artists ON artists.id = tracks.artist
LEFT JOIN albums ON albums.id = tracks.album
LEFT JOIN years ON years.id = tracks.year
LEFT JOIN genres ON genres.id = tracks.genre
LEFT JOIN images ON images.id = albums.image
LEFT JOIN artists albumartists ON albumartists.id = albums.artist
LEFT JOIN statistics ON statistics.url = tracks.url
WHERE images.path IS NOT NULL AND images.path NOT LIKE 'amarok-sqltrackuid:%'
"""
    query += getSQLConditionByFilter(_filter, False) + " ORDER BY dirPath "
    uni.printForDevelopers("Query - getDirectoriesAndValues : " + query)
    db.query(query)
    r = db.store_result()
    directoriesValues = {}
    rows = r.fetch_row(0)
    for row in rows:
        if row[0] not in directoriesValues:
            directoriesValues[row[0]] = {"coverPath": [], "artist": [], "album": [], "year": [], "genre": []}
        directoriesValues[row[0]]["coverPath"].append(row[1])
        directoriesValues[row[0]]["artist"].append(row[2])
        directoriesValues[row[0]]["album"].append(row[3])
        directoriesValues[row[0]]["year"].append(row[4])
        directoriesValues[row[0]]["genre"].append(row[5])
    return directoriesValues
示例#12
0
def changeArtistValue(_values):
    if len(_values) > 1:
        db = Amarok.checkAndGetDB()
        try:
            queryUpdate = "UPDATE artists SET name='%s' WHERE id=%s" % (
                Databases.correctForSql(_values["name"]), _values["id"])
            uni.printForDevelopers("Query - changeArtistValue : " + queryUpdate)
            db.query(queryUpdate)
            db.commit()
            return [_values["name"],
                    getAllMusicFilePathsByArtistId(_values["id"]),
                    getAllMusicFilePathsByAlbumArtistId(_values["id"])]
        except Amarok.getMySQLModule().IntegrityError as error:
            returnValues = [_values["name"],
                            getAllMusicFilePathsByArtistId(_values["id"]),
                            getAllMusicFilePathsByAlbumArtistId(_values["id"])]
            changeArtistWithAnother(_values["id"], getArtistId(_values["name"]))
            deleteArtist(_values["id"])
            return returnValues
    return None
示例#13
0
def getOrInsertDirectory(_directory, _deviceId):
    _deviceId = str(_deviceId)
    if _directory[-1] != "/": _directory += "/"
    if _directory[0] != ".": _directory = "." + _directory
    db = Amarok.checkAndGetDB()
    sqlSelectCommand = "SELECT id FROM directories WHERE deviceid=" + _deviceId + " AND dir='" + Databases.correctForSql(
        _directory) + "'"
    uni.printForDevelopers("Query - getOrInsertDirectory - sqlSelectCommand - 1 : " + sqlSelectCommand)
    db.query(sqlSelectCommand)
    r = db.store_result()
    rows = r.fetch_row(0)
    if len(rows) == 0:
        sqlInsertCommand = "INSERT INTO directories(deviceid,dir) VALUES (" + _deviceId + ",'" + Databases.correctForSql(
            _directory) + "')"
        uni.printForDevelopers("Query - getOrInsertDirectory - sqlInsertCommand : " + sqlInsertCommand)
        db.query(sqlInsertCommand)
        uni.printForDevelopers("Query - getOrInsertDirectory - sqlSelectCommand - 2 : " + sqlSelectCommand)
        db.query(sqlSelectCommand)
        r = db.store_result()
        rows = r.fetch_row(0)
    return rows[0][0]
示例#14
0
def changeTag(_values):
    if len(_values) > 1:
        path = _values["path"]
        db = Amarok.checkAndGetDB()
        querySelect = """
        SELECT trackId,albumArtistId,urlId FROM (
            SELECT tracks.id AS 'trackId',
                REPLACE(
                    CONCAT(CASE WHEN devices.lastmountpoint IS NOT NULL THEN devices.lastmountpoint ELSE '' END,
                        SUBSTRING( urls.rpath , 2 )),
                    CONCAT('/',
                            CONCAT(CASE WHEN devices.lastmountpoint IS NOT NULL THEN devices.lastmountpoint ELSE '' END,
                                SUBSTRING( urls.rpath , 2 )))
                , '') AS 'filePath',
            albums.artist AS 'albumArtistId',
            urls.id AS 'urlId'
            FROM tracks
            INNER JOIN urls ON urls.id = tracks.url
            LEFT JOIN devices ON devices.id = urls.deviceid
            LEFT JOIN albums ON albums.id = tracks.album
            LEFT JOIN artists albumartists ON albumartists.id = albums.artist
        ) as valueTable WHERE filePath = '%s'
        """ % Databases.correctForSql(path)
        uni.printForDevelopers("Query - changeTag - querySelect : " + querySelect)
        db.query(querySelect)
        r = db.store_result()
        rows = r.fetch_row(0)
        if len(rows) == 0:
            return None
        trackId = str(rows[0][0])
        albumArtistId = str(rows[0][1])
        urlId = str(rows[0][2])
        db = Amarok.checkAndGetDB()
        query = " "
        if "artist" in _values:
            query += ", artist=" + getOrInsertArtist(_values["artist"])
        if "albumArtist" in _values:
            albumArtistId = getOrInsertArtist(_values["albumArtist"])
            query += ", artist=" + albumArtistId
        if "title" in _values:
            query += ", title='" + Databases.correctForSql(_values["title"]) + "' "
        if "album" in _values:
            query += ", album=" + getOrInsertAlbum(_values["album"], albumArtistId)
        if "trackNum" in _values:
            query += ", tracknumber=" + Databases.correctForSql(_values["trackNum"], "int")
        if "year" in _values:
            query += ", year=" + getOrInsertYear(_values["year"])
        if "genre" in _values:
            query += ", genre=" + getOrInsertGenre(_values["genre"])
        if "firstComment" in _values:
            query += ", comment='" + Databases.correctForSql(_values["firstComment"]) + "' "
        if "firstLyrics" in _values:
            lyricQuery = ("INSERT INTO lyrics(url,lyrics) VALUES (" + urlId + ",'" + Databases.correctForSql(
                 _values["firstLyrics"]) + "') ON DUPLICATE KEY UPDATE lyrics=VALUES(lyrics) ")
            uni.printForDevelopers("Query - changeTag - lyricQuery : " + lyricQuery)
            db.query(lyricQuery)
        if query.strip() != "":
            query = query[2:] # for first ","
            queryUpdate = "UPDATE tracks SET %s WHERE id=%s" % (query, trackId)
            uni.printForDevelopers("Query - changeTag - queryUpdate : " + queryUpdate)
            db.query(queryUpdate)
        db.commit()
    return True
示例#15
0
    def closeEvent(self, _event):
        try:
            if uni.isRaisedAnError is False:
                if uni.isContinueThreadAction():
                    uni.cancelThreadAction()
                    _event.ignore()
            uni.isStartedCloseProcess = True
            uni.printForDevelopers("Started closeEvent")
            MApplication.setQuitOnLastWindowClosed(True)
            try:
                self.PlayerBar.MusicPlayer.stop()
            except:
                pass
            Details.closeAllDialogs()
            uni.printForDevelopers("Closed Dialogs")
            if uni.isRaisedAnError is False:
                if self.Table.checkUnSavedValues() is False:
                    uni.isStartedCloseProcess = False
                    uni.printForDevelopers("Close ignored")
                    _event.ignore()
            uni.printForDevelopers("Before self.doBeforeCloseProcesses")
            if self.doBeforeCloseProcesses() is False:
                _event.ignore()
                return None
            uni.printForDevelopers("After self.doBeforeCloseProcesses")
            if isActivePyKDE4:
                uni.printForDevelopers("Before Save KDE Configs")
                kconf = MGlobal.config()
                kconfGroup = MConfigGroup(kconf, "DirectoryOperator")
                self.FileManager.dirOperator.writeConfig(kconfGroup)
                self.FileManager.actCollection.writeSettings(kconfGroup)
                uni.printForDevelopers("After Save KDE Configs")
            uni.printForDevelopers("Before Save Configs")
            uni.setMySetting(self.Table.hiddenTableColumnsSettingKey,
                             self.Table.hiddenTableColumns)
            Bars.setAllBarsStyleToMySettings()
            Records.setRecordType(1)
            fu.writeToBinaryFile(
                fu.joinPath(fu.pathOfSettingsDirectory, "LastState"), self.saveState())
            Records.restoreRecordType()
            geometry = [self.geometry().x(), self.geometry().y(), self.geometry().width(),
                        self.geometry().height()]
            uni.setMySetting("MainWindowGeometries", geometry)
            uni.setMySetting("lastDirectory", self.FileManager.currentDirectory)
            uni.setMySetting("isMainWindowMaximized", self.isMaximized())
            uni.setMySetting("isShowAdvancedSelections", self.SpecialTools.isShowAdvancedSelections)
            uni.setMySetting("tableType", uni.tableType)
            uni.setMySetting("activeTabNoOfSpecialTools", self.SpecialTools.tabwTabs.currentIndex())
            uni.saveSettings()
            Settings.saveUniversalSettings()
            if uni.isActiveAmarok and uni.getBoolValue("amarokIsUseHost") is False:
                import Amarok

                uni.printForDevelopers("Before Amarok.stopEmbeddedDB")
                Amarok.stopEmbeddedDB()
                uni.printForDevelopers("After Amarok.stopEmbeddedDB")
            uni.printForDevelopers("After Save Configs")
            uni.printForDevelopers("Before self.doAfterCloseProcesses")
            self.doAfterCloseProcesses()
            uni.printForDevelopers("After self.doAfterCloseProcesses")
        except:
            if ReportBug.isClose is False:
                ReportBug.ReportBug()
                _event.ignore()
示例#16
0
    if float(sys.version[:3]) < 3.0:
        reload(sys)
        sys.setdefaultencoding("utf-8")
except:
    pass

import Core

if Core.checkMandatoryModules():
    from Core.MyObjects import *
    import FileUtils as fu

    fu.initStartupVariables()
    from Core import Universals as uni

    uni.printForDevelopers("Before CommandLineOptions")
    from Core import CommandLineOptions
    uni.printForDevelopers("Before CommandLineOptions.checkCommandLineOptions")
    if CommandLineOptions.checkCommandLineOptions():
        from Core import ReportBug

        uni.printForDevelopers("Before Settings")
        from Core import Settings

        uni.printForDevelopers("Before Settings.checkSettings")
        Settings.checkSettings()
        uni.printForDevelopers("Before uni.fillMySettings")
        uni.fillMySettings()
        if isActivePyKDE4:
            uni.printForDevelopers("ActivePyKDE4")
            appName = "HamsiManager"
示例#17
0
 def __init__(self):
     MMainWindow.__init__(self, None)
     uni.printForDevelopers("Started __init__")
     self.setObjectName("RealMainWindow")
     setMainWindow(self)
     self.isLockedMainForm = False
     self.Menu = None
     self.Table = None
     self.CentralWidget = MWidget()
     self.createMainLayout()
     uni.printForDevelopers("Before Bars.Bars")
     uni.printForDevelopers("Before Bars.StatusBar")
     self.StatusBar = StatusBar.StatusBar(self)
     uni.printForDevelopers("Before Bars.MenuBar")
     self.Menu = MenuBar.MenuBar(self)
     uni.printForDevelopers("Before Bars.ToolsBar")
     self.ToolsBar = ToolsBar.ToolsBar(self)
     uni.printForDevelopers("Before Bars.TableToolsBar")
     self.TableToolsBar = TableToolsBar.TableToolsBar(self)
     uni.printForDevelopers("Before Bars.refreshBars")
     Bars.refreshBars()
     uni.printForDevelopers("Before FileManager.FileManager")
     self.FileManager = FileManager.FileManager(self)
     uni.printForDevelopers("After FileManager.FileManager")
     self.setMainLayout()
     self.setCentralWidget(self.CentralWidget)
     self.setMenuBar(self.Menu)
     self.setStatusBar(self.StatusBar)
     uni.printForDevelopers("Before Menu.refreshForTableType")
     self.Menu.refreshForTableType()
     uni.printForDevelopers("Before Bars.getAllBarsStyleFromMySettings")
     Bars.getAllBarsStyleFromMySettings()
     self.setCorner(Mt.TopLeftCorner, Mt.LeftDockWidgetArea)
     self.setCorner(Mt.BottomLeftCorner, Mt.LeftDockWidgetArea)
     uni.printForDevelopers("End of __init__")
示例#18
0
def changeAlbumWithAnother(_currentAlbumId, _albumWillBeSelectedId):
    db = Amarok.checkAndGetDB()
    queryUpdate = "UPDATE tracks SET album=%s WHERE album=%s" % (_albumWillBeSelectedId, _currentAlbumId)
    uni.printForDevelopers("Query - changeAlbumWithAnother : " + queryUpdate)
    db.query(queryUpdate)
    db.commit()
示例#19
0
def getUtf8Data(_key):
    unicodeData = ""
    try:
        if _key == "replacementChars":
            unicodeData = {
                "Ý": "İ",
                "ý": "ı",
                "þ": "ş",
                "Ð": "ğ",
                "Þ": "Ş",
                "Ü": "Ü",
                "ü": "ü",
                "Ä°Å": "İ",
                "Ç": "ç",
                "ı": "ı",
                "ç": "ç",
                "ö": "ö",
                "Ä°": "İ",
                "Ö": "Ö",
                "Í": "Ö",
                "³": "ü",
                "ğ": "ğ",
                "Ş": "Ş",
                "ş": "ş",
                "”": "ö",
                "™": "Ö",
                "˜": "İ",
                "¦": "ı",
                "": "I",
                "Ä°": "İ",
                "ý": "ı",
                "Ý": "i",
                "�": "İ",
                "": "ü",
                "š": "Ü",
                "€": "Ç",
                "‡": "ç",
                "§": "ğ",
                "¦": "Ğ",
                "äŸ": "ğ",
                "Ğ": "Ğ",
                "ð": "ğ",
                "ã": "ğ",
                "Ð": "Ğ",
                "ð": "ğ",
                "ž": "Ş",
                "Þ": "Ş",
                "Ÿ": "ş",
                "åž": "ş",
                "ãž": "ş",
                "åŸ": "ş",
                "þ": "ş",
                "ã¾": "ş",
                "_": " "
            }
        elif _key == "upright":
            return "│"
        elif _key == "upright+right":
            return "├"
        elif _key == "up+right":
            return "└"
        elif _key == "little+I":
            return "ı"
        elif _key == "":
            return ""
    except Exception as err:
        uni.printForDevelopers(str(err))
    return unicodeData
示例#20
0
 def doAfterRunProcessesStep2(self):
     for command in uni.runAfter:
         action = command["action"]
         action(*command["args"], **command["kwargs"])
         uni.printForDevelopers(str(command))