Example #1
0
def showExists(title, path):
    dbShowID = None
    try:
        con, cursor = openDB(SHDBPATH, 'TVShows')

        title = stringUtils.invCommas(title)

        cursor.execute(
            "SELECT id, showTitle FROM shows WHERE showTitle LIKE '{}';".
            format(title))
        dbShow = cursor.fetchone()

        if dbShow is None:
            path = fileSys.completePath(
                path) if DATABASE_MYSQL == "false" else fileSys.completePath(
                    path).replace('\\', '\\\\')
            path = stringUtils.invCommas(path)
            cursor.execute(
                "INSERT INTO shows (showTitle, filePath) VALUES ('{}', '{}');".
                format(title, path))
            con.commit()
            dbShowID = cursor.lastrowid
        else:
            dbShowID = dbShow[0]
    finally:
        cursor.close()
        con.close()

    return dbShowID
Example #2
0
def movieExists(title, path):
    dbMovieID = None
    try:
        con, cursor = openDB(MODBPATH, 'Movies')

        title = stringUtils.invCommas(title)

        cursor.execute(
            "SELECT id, title FROM movies WHERE title LIKE '{}';".format(
                title))
        dbMovie = cursor.fetchone()

        if dbMovie is None:
            path = fileSys.completePath(
                path) if DATABASE_MYSQL == "false" else fileSys.completePath(
                    path).replace('\\', '\\\\')
            path = stringUtils.invCommas(path)
            cursor.execute(
                "INSERT INTO movies (title, filePath) VALUES ('{}', '{}');".
                format(title, path))
            con.commit()
            dbMovieID = cursor.lastrowid
        else:
            dbMovieID = dbMovie[0]
    finally:
        cursor.close()
        con.close()

    return dbMovieID
Example #3
0
def getPlayedURLResumePoint(args):
    urlResumePoint = None

    try:
        con, cursor = openDB(KMODBPATH, 'KMovies')

        query = "SELECT timeInSeconds, totalTimeInSeconds, idBookmark FROM bookmark INNER JOIN files on files.idFile = bookmark.idFile"
        if (args.get('url', None)):
            url = stringUtils.invCommas(args.get('url'))
            query += "  WHERE files.strFilename LIKE '{}';".format(url)
        else:
            filename = stringUtils.invCommas(args.get('filename'))
            path = stringUtils.invCommas(args.get('path'))
            query += " INNER JOIN path on path.idPath = files.idPath WHERE files.strFilename LIKE '{}' AND path.strPath LIKE '{}';".format(
                filename, path)

        cursor.execute(query)
        urlResumePoint = cursor.fetchone()
    finally:
        cursor.close()
        con.close()

    return urlResumePoint
Example #4
0
def getKodiEpisodeID(sTVShowTitle, iSeason, iEpisode):
    dbEpisode = None

    try:
        con, cursor = openDB(KMODBPATH, 'KMovies')

        sTVShowTitle = stringUtils.invCommas(sTVShowTitle)

        # episode.c00 = title; episode.c05 = aired; episode.c12 = season; episode.c13 = episode; tvshow.c00 = title
        query = "SELECT episode.idEpisode, episode.idFile, episode.c00, episode.c05 FROM episode INNER JOIN tvshow ON tvshow.idShow = episode.idShow WHERE episode.c12 = {} and episode.c13 = {} and tvshow.c00 LIKE '{}';"

        cursor.execute(query.format(iSeason, iEpisode, sTVShowTitle))
        dbEpisode = cursor.fetchone()
    finally:
        cursor.close()
        con.close()

    return dbEpisode
Example #5
0
def getKodiMovieID(sTitle):
    dbMovie = None

    try:
        con, cursor = openDB(KMODBPATH, 'KMovies')

        sTitle = stringUtils.invCommas(sTitle)

        # c00 = title; c14 = genre
        cursor.execute(
            "SELECT idMovie, idFile, premiered, c14 FROM movie WHERE c00 LIKE '{}';"
            .format(sTitle))
        dbMovie = cursor.fetchone()
    finally:
        cursor.close()
        con.close()

    return dbMovie
Example #6
0
def writeSong(iPathID, iAlbumID, strArtist, strTitle, iDuration, iTrack,
              tFileModTime):
    tDateAdded = datetime.datetime.fromtimestamp(
        tFileModTime) if tFileModTime else datetime.datetime.now()
    strDateAdded = tDateAdded.strftime("%Y-%m-%d %H:%M:%S")
    iYear = int(datetime.datetime.now().strftime("%Y"))
    artistCol = "strArtistDisp" if kodi_version >= 18 else "strArtists"
    strTitle = stringUtils.invCommas(strTitle)
    strFileName = stringUtils.cleanStrmFilesys(strTitle)
    strFileName += ".strm"

    selectQuery = "SELECT idSong FROM song WHERE {} LIKE '{}' AND strTitle LIKE '{}';"
    selectArgs = (artistCol, strArtist, strTitle)
    insertQuery = "INSERT INTO song (iYear, dateAdded, idAlbum, idPath, " + artistCol + ", strTitle, strFileName, iTrack, strGenres, iDuration, iTimesPlayed, iStartOffset, iEndOffset, userrating, comment, mood, votes)"
    insertQuery += " VALUES ({}, '{}', {}, {}, '{}', '{}', '{}', {}, '{}', {}, {}, {}, {}, {}, '{}', '{}', {});"
    insertArgs = (iYear, strDateAdded, iAlbumID, iPathID, strArtist, strTitle,
                  strFileName, iTrack, 'osmosis', iDuration, 0, 0, 0, 0,
                  'osmosis', 'osmosis', 0)

    return manageDbRecord(selectQuery, selectArgs, insertQuery, insertArgs)
Example #7
0
def getPlayedURLResumePoint(url):
    urlResumePoint = None

    try:
        con, cursor = openDB(KMODBPATH, 'KMovies')

        url = stringUtils.invCommas(url)

        cursor.execute(
            "SELECT idFile FROM files WHERE strFilename LIKE '{}';".format(
                url))
        dbfile = cursor.fetchone()

        if dbfile:
            dbfileID = dbfile[0]
            cursor.execute(
                "SELECT timeInSeconds, totalTimeInSeconds, idBookmark FROM bookmark WHERE idFile = {};"
                .format(dbfileID))
            urlResumePoint = cursor.fetchone()
    finally:
        cursor.close()
        con.close()

    return urlResumePoint