Beispiel #1
0
def setNewest(compList=False):
    Log('updating new seasons', xbmc.LOGDEBUG)
    if not compList:
        compList = getCategories()
    catList = compList['tv_shows']
    db.waitforDB(tvDB)
    c = tvDB.cursor()
    db.cur_exec(c, 'drop table if exists categories')
    db.cur_exec(c, 'create table categories(title TEXT, asins TEXT)')
    db.cur_exec(c, 'update seasons set recent=null')
    count = 1
    for catid in catList:
        if catid == 'PrimeTVRecentlyAdded':
            for asin in catList[catid]:
                seasonasin = lookupTVdb(asin, rvalue='seasonasin')
                if not seasonasin:
                    seasonasin = asin

                db.cur_exec(c,
                            "update seasons set recent=? where asin like (?)",
                            (count, '%' + seasonasin + '%'))
                count += 1
        else:
            db.cur_exec(c, 'insert ignore into categories values (?,?)',
                        [catid, catList[catid]])
    tvDB.commit()
Beispiel #2
0
def fixTitles():
    Log('fixing titles', xbmc.LOGDEBUG)
    c = tvDB.cursor()
    for asins, title in db.cur_exec(c, 'select asin, seriestitle from shows').fetchall():
        for asin in asins.split(','):
            db.cur_exec(c, 'update seasons set seriestitle = (?) where seriesasin = (?)', (title, asin))
            db.cur_exec(c, 'update episodes set seriestitle = (?) where seriesasin = (?)', (title, asin))
Beispiel #3
0
def fixGenres():
    Log('fixing genres', xbmc.LOGDEBUG)
    c = tvDB.cursor()
    seasons = db.cur_exec(c, 'select distinct seriestitle,genres from seasons where genres is not null').fetchall()
    for series, genres in seasons:
        db.cur_exec(c, "update seasons set genres=? where seriestitle=? and genres is null", (genres, series))
        db.cur_exec(c, "update shows set genres=? where seriestitle=? and genres is null", (genres, series))
Beispiel #4
0
def fixGenres():
    Log('fixing genres', xbmc.LOGDEBUG)
    c = tvDB.cursor()
    seasons = db.cur_exec(c, 'select distinct seriestitle,genres from seasons where genres is not null').fetchall()
    for series, genres in seasons:
        db.cur_exec(c, "update seasons set genres=? where seriestitle=? and genres is null", (genres, series))
        db.cur_exec(c, "update shows set genres=? where seriestitle=? and genres is null", (genres, series))
Beispiel #5
0
def fixDBLShows():
    Log('fixing double shows', xbmc.LOGDEBUG)
    c = tvDB.cursor()
    allseries = []
    for asin, seriestitle in db.cur_exec(
            c, 'select asin,seriestitle from shows').fetchall():
        flttitle = cleanTitle(seriestitle)
        addlist = True
        index = 0
        for asinlist, titlelist, fltlist in allseries:
            if flttitle == fltlist:
                allseries.pop(index)
                allseries.insert(index,
                                 [asinlist + ',' + asin, titlelist, fltlist])
                db.cur_exec(
                    c,
                    'delete from shows where seriestitle = (?) and asin = (?)',
                    (seriestitle, asin))
                addlist = False
            index += 1
        if addlist:
            allseries.append([asin, seriestitle, flttitle])

    for asinlist, titlelist, fltlist in allseries:
        db.cur_exec(c, "update shows set asin = (?) where seriestitle = (?)",
                    (asinlist, titlelist))
Beispiel #6
0
def lookupTVdb(value, rvalue='distinct *', tbl='episodes', name='asin', single=True, exact=False):
    db.waitforDB(tvDB)
    c = tvDB.cursor()
    value = value.decode('utf-8')
    if not db.cur_exec(c, 'counttables', (tbl,)).fetchone():
        return '' if single else []

    sqlstring = 'select %s from %s where %s ' % (rvalue, tbl, name)
    retlen = len(rvalue.split(','))
    if not exact:
        value = "%{0}%".format(value)
        sqlstring += 'like (?)'
    else:
        sqlstring += '= (?)'
    if db.cur_exec(c, sqlstring, (value,)).fetchall():
        result = db.cur_exec(c, sqlstring, (value,)).fetchall()
        if single:
            if len(result[0]) > 1:
                return result[0]
            return result[0][0]
        else:
            return result
    if (retlen < 2) and single:
        return None
    return (None,) * retlen
Beispiel #7
0
def lookupMoviedb(value,
                  rvalue='distinct *',
                  name='asin',
                  single=True,
                  exact=False,
                  table='movies'):
    db.waitforDB(MovieDB)
    c = MovieDB.cursor()
    if not db.cur_exec(c, 'counttables', (table, )).fetchone():
        return '' if single else []

    sqlstring = 'select %s from %s where %s ' % (rvalue, table, name)
    retlen = len(rvalue.split(','))
    if not exact:
        value = b"%{0}%".format(value)
        sqlstring += 'like (?)'
    else:
        sqlstring += '= (?)'
    if db.cur_exec(c, sqlstring, (value, )).fetchall():
        result = db.cur_exec(c, sqlstring, (value, )).fetchall()
        if single:
            if len(result[0]) > 1:
                return result[0]
            return result[0][0]
        else:
            return result
    if (retlen < 2) and single:
        return None
    return (None, ) * retlen
Beispiel #8
0
def fixTitles():
    Log('fixing titles', xbmc.LOGDEBUG)
    c = tvDB.cursor()
    for asins, title in db.cur_exec(c, 'select asin, seriestitle from shows').fetchall():
        for asin in asins.split(','):
            db.cur_exec(c, 'update seasons set seriestitle = (?) where seriesasin = (?)', (title, asin))
            db.cur_exec(c, 'update episodes set seriestitle = (?) where seriesasin = (?)', (title, asin))
Beispiel #9
0
def fixHDshows():
    Log('fixing HD infos', xbmc.LOGDEBUG)
    c = tvDB.cursor()
    db.cur_exec(c, "update shows set isHD=?", (False,))
    HDseasons = db.cur_exec(c, 'select distinct seriestitle from seasons where isHD = (?)', (True,)).fetchall()
    for series in HDseasons:
        db.cur_exec(c, "update shows set isHD=? where seriestitle=?", (True, series[0]))
Beispiel #10
0
def fixHDshows():
    Log('fixing HD infos', xbmc.LOGDEBUG)
    c = tvDB.cursor()
    db.cur_exec(c, "update shows set isHD=?", (False,))
    HDseasons = db.cur_exec(c, 'select distinct seriestitle from seasons where isHD = (?)', (True,)).fetchall()
    for series in HDseasons:
        db.cur_exec(c, "update shows set isHD=? where seriestitle=?", (True, series[0]))
Beispiel #11
0
def fixStars():
    Log('fixing stars', xbmc.LOGDEBUG)
    c = tvDB.cursor()
    series = db.cur_exec(c, 'select seriestitle from shows where votes = 0').fetchall()
    for title in series:
        title = title[0]
        stars = db.cur_exec(c, 'select avg(stars) from seasons where seriestitle like ? and votes != 0', (title,)).fetchone()[0]
        if stars:
            db.cur_exec(c, 'update shows set stars = (?) where seriestitle = (?)', (stars, title))
Beispiel #12
0
def fixStars():
    Log('fixing stars', xbmc.LOGDEBUG)
    c = tvDB.cursor()
    series = db.cur_exec(c, 'select seriestitle from shows where votes = 0').fetchall()
    for title in series:
        title = title[0]
        stars = db.cur_exec(c, 'select avg(stars) from seasons where seriestitle like ? and votes != 0', (title,)).fetchone()[0]
        if stars:
            db.cur_exec(c, 'update shows set stars = (?) where seriestitle = (?)', (stars, title))
Beispiel #13
0
def loadTVShowdb(filterobj=None, value=None, sortcol=None):
    db.waitforDB(tvDB)
    c = tvDB.cursor()
    if filterobj:
        value = '%' + value + '%'
        return db.cur_exec(c, 'select distinct * from shows where %s like (?)' % filterobj, (value,))
    elif sortcol:
        return db.cur_exec(c, 'select distinct * from shows where %s is not null order by %s asc' % (sortcol, sortcol))
    else:
        return db.cur_exec(c, 'select distinct * from shows order by seriestitle asc')
Beispiel #14
0
def updateEpisodes():
    Log('updateing num of epsiodes', xbmc.LOGDEBUG)
    c = tvDB.cursor()
    shows = db.cur_exec(c, 'select distinct asin from shows where episodetotal = 0').fetchall()
    for asin in shows:
        asinn = asin[0]
        nums = 0
        for sasin in asinn.split(','):
            nums += int((db.cur_exec(c, "select count(*) from episodes where seriesasin like ?", (sasin,)).fetchone())[0])
        db.cur_exec(c, "update shows set episodetotal=? where asin=?", (nums, asinn))
Beispiel #15
0
def updateEpisodes():
    Log('updateing num of epsiodes', xbmc.LOGDEBUG)
    c = tvDB.cursor()
    shows = db.cur_exec(c, 'select distinct asin from shows where episodetotal = 0').fetchall()
    for asin in shows:
        asinn = asin[0]
        nums = 0
        for sasin in asinn.split(','):
            nums += int((db.cur_exec(c, "select count(*) from episodes where seriesasin like ?", (sasin,)).fetchone())[0])
        db.cur_exec(c, "update shows set episodetotal=? where asin=?", (nums, asinn))
Beispiel #16
0
def loadTVShowdb(filterobj=None, value=None, sortcol=None):
    db.waitforDB(tvDB)
    c = tvDB.cursor()
    if filterobj:
        value = "%{0}%".format(value.decode('utf-8'))
        return db.cur_exec(c, 'select distinct * from shows where %s like (?)' % filterobj, (value,))
    elif sortcol:
        return db.cur_exec(c, 'select distinct * from shows where %s is not null order by %s asc' % (sortcol, sortcol))
    else:
        return db.cur_exec(c, 'select distinct * from shows order by seriestitle asc')
Beispiel #17
0
def loadTVSeasonsdb(seriesasin=None, sortcol=None, seasonasin=None):
    db.waitforDB(tvDB)
    c = tvDB.cursor()
    if seriesasin:
        return db.cur_exec(c, 'select distinct * from seasons where seriesasin = (?)', (seriesasin,))
    if seasonasin:
        seasonasin = '%' + seasonasin + '%'
        return db.cur_exec(c, 'select distinct * from seasons where asin like (?)', (seasonasin,))
    elif sortcol:
        return db.cur_exec(c, 'select distinct * from seasons where %s is not null order by %s asc' % (sortcol, sortcol))
    else:
        return db.cur_exec(c, 'select distinct * from seasons')
Beispiel #18
0
def loadTVSeasonsdb(seriesasin=None, sortcol=None, seasonasin=None):
    db.waitforDB(tvDB)
    c = tvDB.cursor()
    if seriesasin:
        return db.cur_exec(c, 'select distinct * from seasons where seriesasin = (?)', (seriesasin,))
    if seasonasin:
        seasonasin = '%' + seasonasin + '%'
        return db.cur_exec(c, 'select distinct * from seasons where asin like (?)', (seasonasin,))
    elif sortcol:
        return db.cur_exec(c, 'select distinct * from seasons where %s is not null order by %s asc' % (sortcol, sortcol))
    else:
        return db.cur_exec(c, 'select distinct * from seasons')
Beispiel #19
0
def addDB(table, data):
    c = tvDB.cursor()
    columns = {'shows': 22, 'seasons': 24, 'episodes': 23}
    query = '?,' * columns[table]
    num = db.cur_exec(c, 'insert ignore into %s values (%s)' % (table, query[0:-1]), data).rowcount

    if not num and table == 'seasons':
        oldepi = db.cur_exec(c, 'select episodetotal from seasons where asin=(?)', (data[0],)).fetchall()[0][0]
        Log('Updating show %s season %s (O:%s N:%s)' % (data[3], data[2], oldepi, data[13]), xbmc.LOGDEBUG)
        num = db.cur_exec(c, 'update seasons set episodetotal=(?) where asin=(?)', (data[13], data[0])).rowcount

    if num:
        tvDB.commit()
    c.close()
    return num
Beispiel #20
0
def addDB(table, data):
    c = tvDB.cursor()
    columns = {'shows': 22, 'seasons': 24, 'episodes': 23}
    query = '?,' * columns[table]
    num = db.cur_exec(c, 'insert ignore into %s values (%s)' % (table, query[0:-1]), data).rowcount

    if not num and table == 'seasons':
        oldepi = db.cur_exec(c, 'select episodetotal from seasons where asin=(?)', (data[0],)).fetchall()[0][0]
        Log('Updating show %s season %s (O:%s N:%s)' % (data[3], data[2], oldepi, data[13]), xbmc.LOGDEBUG)
        num = db.cur_exec(c, 'update seasons set episodetotal=(?) where asin=(?)', (data[13], data[0])).rowcount

    if num:
        tvDB.commit()
    c.close()
    return num
Beispiel #21
0
def loadTVEpisodesdb(seriestitle):
    db.waitforDB(tvDB)
    c = tvDB.cursor()
    return db.cur_exec(
        c,
        'select distinct * from episodes where seasonasin = (?) order by episode',
        (seriestitle, ))
Beispiel #22
0
def getMovieTypes(col):
    db.waitforDB(MovieDB)
    c = MovieDB.cursor()
    items = db.cur_exec(c, 'select distinct %s from movies' % col)
    l = getTypes(items, col)
    c.close()
    return l
Beispiel #23
0
def getShowTypes(col):
    db.waitforDB(tvDB)
    c = tvDB.cursor()
    items = db.cur_exec(c, 'select distinct %s from shows' % col)
    l = getTypes(items, col)
    c.close()
    return l
Beispiel #24
0
def updateMoviedb(asin, col, value):
    db.waitforDB(MovieDB)
    c = MovieDB.cursor()
    asin = '%' + asin + '%'
    sqlquery = 'update movies set %s=? where asin like (?)' % col
    result = db.cur_exec(c, sqlquery, (value, asin)).rowcount
    return result
Beispiel #25
0
def getIMDbID(asins, title):
    url = imdbid = None
    db.waitforDB(tvDB)
    c = tvDB.cursor()
    for asin in asins.split(','):
        asin = '%' + asin + '%'
        url = db.cur_exec(c, 'select imdburl from seasons where seriesasin like (?) and imdburl is not null',
                          (asin,)).fetchone()
        if url:
            url = url[0]
            break
    if not url:
        while not imdbid:
            data = getURL('http://www.omdbapi.com/?type=series&t=' + urllib.quote_plus(title))
            if data['Response'] == 'True':
                imdbid = data['imdbID']
            else:
                oldtitle = title
                if title.count(' - '):
                    title = title.split(' - ')[0]
                elif title.count(': '):
                    title = title.split(': ')[0]
                elif title.count('?'):
                    title = title.replace('?', '')
                if title == oldtitle:
                    imdbid = na
    else:
        imdbid = re.compile('/title/(.+?)/', re.DOTALL).findall(url)
    Log(imdbid + asins.split(',')[0])
    return imdbid
Beispiel #26
0
def loadMoviedb(filterobj=None, value=None, sortcol=False):
    db.waitforDB(MovieDB)
    c = MovieDB.cursor()
    if filterobj:
        value = b"%{0}%".format(value)
        return db.cur_exec(
            c, 'select distinct * from movies where %s like (?)' % filterobj,
            (value, ))
    elif sortcol:
        return db.cur_exec(
            c,
            'select distinct * from movies where %s is not null order by %s asc'
            % (sortcol, sortcol))
    else:
        return db.cur_exec(
            c, 'select distinct * from movies order by movietitle asc')
Beispiel #27
0
def getShowTypes(col):
    db.waitforDB(tvDB)
    c = tvDB.cursor()
    items = db.cur_exec(c, 'select distinct %s from shows' % col)
    l = getTypes(items, col)
    c.close()
    return l
Beispiel #28
0
def getIMDbID(asins, title):
    url = imdbid = None
    db.waitforDB(tvDB)
    c = tvDB.cursor()
    for asin in asins.split(','):
        asin = '%' + asin + '%'
        url = db.cur_exec(c, 'select imdburl from seasons where seriesasin like (?) and imdburl is not null',
                          (asin,)).fetchone()
        if url:
            url = url[0]
            break
    if not url:
        while not imdbid:
            data = getURL('http://www.omdbapi.com/?type=series&t=' + urllib.quote_plus(title.encode('utf-8')))
            if data['Response'] == 'True':
                imdbid = data['imdbID']
            else:
                oldtitle = title
                if title.count(' - '):
                    title = title.split(' - ')[0]
                elif title.count(': '):
                    title = title.split(': ')[0]
                elif title.count('?'):
                    title = title.replace('?', '')
                if title == oldtitle:
                    imdbid = na
    else:
        imdbid = re.compile('/title/(.+?)/', re.DOTALL).findall(url)
    Log(imdbid + asins.split(',')[0])
    return imdbid
Beispiel #29
0
def updatePop():
    db.waitforDB(MovieDB)
    c = MovieDB.cursor()
    db.cur_exec(c, "update movies set popularity=null")
    Index = 0
    maxIndex = MAX * 3

    while -1 < Index < maxIndex:
        jsondata = appfeed.getList('Movie', Index, NumberOfResults=MAX)
        titles = jsondata['message']['body']['titles']
        for title in titles:
            Index += 1
            asin = title['titleId']
            if asin:
                updateMoviedb(asin, 'popularity', Index)
        if len(titles) == 0:
            Index = -1
Beispiel #30
0
def updatePop():
    Log('updating popular titles', xbmc.LOGDEBUG)
    c = tvDB.cursor()
    db.cur_exec(c, "update shows set popularity=null")
    Index = 0
    maxIndex = MAX * 3

    while -1 < Index < maxIndex:
        jsondata = appfeed.getList('tvepisode,tvseason,tvseries&RollupToSeries=T', Index, NumberOfResults=MAX)
        titles = jsondata['message']['body']['titles']
        for title in titles:
            Index += 1
            asin = title['titleId']
            if asin:
                db.cur_exec(c, "update shows set popularity=? where asin like (?) and popularity is null",
                            (Index, '%' + asin + '%'))
        if len(titles) == 0:
            Index = -1
Beispiel #31
0
def updatePop():
    Log('updating popular titles', xbmc.LOGDEBUG)
    c = tvDB.cursor()
    db.cur_exec(c, "update shows set popularity=null")
    Index = 0
    maxIndex = MAX * 3

    while -1 < Index < maxIndex:
        jsondata = appfeed.getList('TVSeason', Index, NumberOfResults=MAX)
        titles = jsondata['message']['body']['titles']
        for title in titles:
            Index += 1
            asin = title['titleId']
            if asin:
                seriesasin = lookupTVdb(asin, rvalue='seriesasin', tbl='seasons')
                if seriesasin:
                    db.cur_exec(c, "update shows set popularity=? where asin like (?) and popularity is null", (Index, '%' + seriesasin + '%'))
        if len(titles) == 0:
            Index = -1
Beispiel #32
0
def addMoviedb(moviedata):
    c = MovieDB.cursor()
    num = db.cur_exec(
        c,
        'insert ignore into movies values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
        moviedata).rowcount

    if num:
        MovieDB.commit()
    return num
Beispiel #33
0
def deleteMoviedb(asin=False):
    movietitle = lookupMoviedb(asin, 'movietitle')
    num = 0
    if movietitle:
        c = MovieDB.cursor()
        num = db.cur_exec(c, 'delete from movies where asin like (?)',
                          ('%' + asin + '%', )).rowcount
        if num:
            MovieDB.commit()

    return num
Beispiel #34
0
def fixDBLShows():
    Log('fixing double shows', xbmc.LOGDEBUG)
    c = tvDB.cursor()
    allseries = []
    for asin, seriestitle in db.cur_exec(c, 'select asin,seriestitle from shows').fetchall():
        flttitle = cleanTitle(seriestitle)
        addlist = True
        index = 0
        for asinlist, titlelist, fltlist in allseries:
            if flttitle == fltlist:
                allseries.pop(index)
                allseries.insert(index, [asinlist + ',' + asin, titlelist, fltlist])
                db.cur_exec(c, 'delete from shows where seriestitle = (?) and asin = (?)', (seriestitle, asin))
                addlist = False
            index += 1
        if addlist:
            allseries.append([asin, seriestitle, flttitle])

    for asinlist, titlelist, fltlist in allseries:
        db.cur_exec(c, "update shows set asin = (?) where seriestitle = (?)", (asinlist, titlelist))
Beispiel #35
0
def updatePop():
    Log('updating popular titles', xbmc.LOGDEBUG)
    c = tvDB.cursor()
    db.cur_exec(c, "update shows set popularity=null")
    Index = 0
    maxIndex = MAX_RES * 3

    while -1 < Index < maxIndex:
        MAX = randint(5, MAX_RES)
        jsondata = appfeed.getList('TVSeason', Index, NumberOfResults=MAX)
        titles = jsondata['message']['body']['titles']
        for title in titles:
            Index += 1
            asin = title['titleId']
            if asin:
                seriesasin = lookupTVdb(asin, rvalue='seriesasin', tbl='seasons')
                if seriesasin:
                    db.cur_exec(c, "update shows set popularity=? where asin like (?) and popularity is null", (Index, '%' + seriesasin + '%'))
        if len(titles) == 0:
            Index = -1
Beispiel #36
0
def deleteremoved(asins, refresh=True):
    Log('delete removed titles', xbmc.LOGDEBUG)
    c = tvDB.cursor()
    delShows = 0
    delSeasons = 0
    delEpisodes = 0
    Log('ASINS to Remove: ' + asins.__str__())
    for item in asins:
        for seasonasin in item.split(','):
            season, seriesasin = lookupTVdb(seasonasin,
                                            rvalue='season, seriesasin',
                                            tbl='seasons')
            if not seriesasin:
                season, seriesasin = lookupTVdb(seasonasin,
                                                rvalue='season, seriesasin',
                                                name='seasonasin',
                                                tbl='episodes')
            if seriesasin:
                asin = '%' + seasonasin + '%'
                delEpisodes += db.cur_exec(
                    c,
                    'delete from episodes where season = (?) and seasonasin like (?)',
                    (season, asin)).rowcount
                delSeasons += db.cur_exec(
                    c,
                    'delete from seasons where season = (?) and asin like (?)',
                    (season, asin)).rowcount
                if not lookupTVdb(seriesasin,
                                  rvalue='asin',
                                  tbl='seasons',
                                  name='seriesasin'):
                    delShows += db.cur_exec(
                        c, 'delete from shows where asin like (?)',
                        ('%' + seriesasin + '%', )).rowcount
    tvDB.commit()
    c.close()
    if refresh:
        xbmc.executebuiltin('Container.Refresh')

    return delShows, delSeasons, delEpisodes
Beispiel #37
0
def getMoviedbAsins(isPrime=1, retlist=False):
    db.waitforDB(MovieDB)
    c = MovieDB.cursor()
    content = ''
    sqlstring = 'select asin from movies where isPrime = (%s)' % isPrime
    if retlist:
        content = []
    for item in db.cur_exec(c, sqlstring).fetchall():
        if retlist:
            content.append([','.join(item), 0])
        else:
            content += ','.join(item)
    return content
Beispiel #38
0
def setNewest(compList=False):
    Log('updating new seasons', xbmc.LOGDEBUG)
    if not compList:
        compList = getCategories()
    catList = compList['tv_shows']
    db.waitforDB(tvDB)
    c = tvDB.cursor()
    db.cur_exec(c, 'drop table if exists categories')
    db.cur_exec(c, 'create table categories(title TEXT, asins TEXT)')
    db.cur_exec(c, 'update seasons set recent=null')
    count = 1
    for catid in catList:
        if catid == 'PrimeTVRecentlyAdded':
            for asin in catList[catid]:
                seasonasin = lookupTVdb(asin, rvalue='seasonasin')
                if not seasonasin:
                    seasonasin = asin

                db.cur_exec(c, "update seasons set recent=? where asin like (?)", (count, '%' + seasonasin + '%'))
                count += 1
        else:
            db.cur_exec(c, 'insert ignore into categories values (?,?)', [catid, catList[catid]])
    tvDB.commit()
Beispiel #39
0
def deleteremoved(asins, refresh=True):
    Log('delete removed titles', xbmc.LOGDEBUG)
    c = tvDB.cursor()
    delShows = 0
    delSeasons = 0
    delEpisodes = 0
    Log('ASINS to Remove: ' + asins.__str__())
    for item in asins:
        for seasonasin in item.split(','):
            season, seriesasin = lookupTVdb(seasonasin, rvalue='season, seriesasin', tbl='seasons')
            if not seriesasin:
                season, seriesasin = lookupTVdb(seasonasin, rvalue='season, seriesasin', name='seasonasin', tbl='episodes')
            if seriesasin:
                asin = '%' + seasonasin + '%'
                delEpisodes += db.cur_exec(c, 'delete from episodes where season = (?) and seasonasin like (?)', (season, asin)).rowcount
                delSeasons += db.cur_exec(c, 'delete from seasons where season = (?) and asin like (?)', (season, asin)).rowcount
                if not lookupTVdb(seriesasin, rvalue='asin', tbl='seasons', name='seriesasin'):
                    delShows += db.cur_exec(c, 'delete from shows where asin like (?)', ('%'+seriesasin+'%',)).rowcount
    tvDB.commit()
    c.close()
    if refresh:
        xbmc.executebuiltin('Container.Refresh')

    return delShows, delSeasons, delEpisodes
Beispiel #40
0
def updateFanart():
    if tvdb_art == '0':
        return

    seasons = False
    c = tvDB.cursor()
    sqlstring = "select asin, seriestitle, fanart, poster from shows where fanart is null"
    Log('TV Update: Updating Fanart')
    if tvdb_art == '2':
        sqlstring += " or fanart like '%images-amazon.com%'"
    if tvdb_art == '3':
        sqlstring += " or poster like '%images-amazon.com%'"
        seasons = True
    db.waitforDB(tvDB)
    for asin, title, oldfanart, oldposter in db.cur_exec(c,
                                                         sqlstring).fetchall():
        title = title.lower().replace('[ov]', '').replace('[ultra hd]', '').replace('?', '') \
                .replace('omu', '').split('(')[0].strip()
        tvid, poster, fanart = appfeed.getTVDBImages(title, seasons=seasons)

        if not fanart:
            fanart = appfeed.getTMDBImages(title, content='tv')

        if oldfanart and not fanart:
            fanart = oldfanart

        if oldposter and not poster:
            poster = oldposter

        if tvid:
            if not fanart:
                fanart = na

            if not poster:
                fanart = na

        db.cur_exec(c, 'update shows set fanart=? where asin = (?)',
                    (fanart, asin))
        if tvdb_art == '3':
            db.cur_exec(c, 'update shows set poster=? where asin = (?)',
                        (poster, asin))
            if tvid:
                for season, url in tvid.items():
                    for singleasin in asin.split(','):
                        singleasin = '%' + singleasin + '%'
                        db.cur_exec(
                            c,
                            'update seasons set poster=? where seriesasin like (?) and season = (?)',
                            (url, singleasin, int(season)))
    tvDB.commit()
    Log('TV Update: Updating Fanart Finished')
Beispiel #41
0
def lookupTVdb(value, rvalue='distinct *', tbl='episodes', name='asin', single=True, exact=False):
    db.waitforDB(tvDB)
    c = tvDB.cursor()
    if not db.cur_exec(c, 'counttables', (tbl,)).fetchone():
        return '' if single else []

    sqlstring = 'select %s from %s where %s ' % (rvalue, tbl, name)
    retlen = len(rvalue.split(','))
    if not exact:
        value = '%' + value + '%'
        sqlstring += 'like (?)'
    else:
        sqlstring += '= (?)'
    if db.cur_exec(c, sqlstring, (value,)).fetchall():
        result = db.cur_exec(c, sqlstring, (value,)).fetchall()
        if single:
            if len(result[0]) > 1:
                return result[0]
            return result[0][0]
        else:
            return result
    if (retlen < 2) and single:
        return None
    return (None,) * retlen
Beispiel #42
0
def getTVdbAsins(table, isPrime=1, retlist=False, value='asin'):
    c = tvDB.cursor()
    content = [] if retlist else ''
    sqlstring = 'select %s from %s' % (value, table)

    if isPrime < 2:
        sqlstring += ' where isPrime = (%s)' % isPrime

    for item in db.cur_exec(c, sqlstring).fetchall():
        if str(item[0]) not in str(content):
            if retlist:
                content.append(list(item)+[0, ])
            else:
                content += ','.join(item) + ','

    return content
Beispiel #43
0
def getTVdbAsins(table, isPrime=1, retlist=False, value='asin'):
    c = tvDB.cursor()
    content = [] if retlist else ''
    sqlstring = 'select %s from %s' % (value, table)

    if isPrime < 2:
        sqlstring += ' where isPrime = (%s)' % isPrime

    for item in db.cur_exec(c, sqlstring).fetchall():
        if str(item[0]) not in str(content):
            if retlist:
                content.append(list(item)+[0, ])
            else:
                content += ','.join(item) + ','

    return content
Beispiel #44
0
def fixYears():
    Log('fixing years', xbmc.LOGDEBUG)
    c = tvDB.cursor()
    seasons = db.cur_exec(c, 'select seasonasin,year,season from episodes where year is not null order by year desc').fetchall()
    for asin, year, season in seasons:
        asin = '%' + asin + '%'
        db.cur_exec(c, "update seasons set year=? where season=? and asin like ?", (year, season, asin))
    seasons = db.cur_exec(c, 'select seriesasin,year from seasons where year is not null order by year desc').fetchall()
    for asin, year in seasons:
        asin = '%' + asin + '%'
        db.cur_exec(c, "update shows set year=? where asin like ?", (year, asin))
Beispiel #45
0
def fixYears():
    Log('fixing years', xbmc.LOGDEBUG)
    c = tvDB.cursor()
    seasons = db.cur_exec(c, 'select seasonasin,year,season from episodes where year is not null order by year desc').fetchall()
    for asin, year, season in seasons:
        asin = '%' + asin + '%'
        db.cur_exec(c, "update seasons set year=? where season=? and asin like ?", (year, season, asin))
    seasons = db.cur_exec(c, 'select seriesasin,year from seasons where year is not null order by year desc').fetchall()
    for asin, year in seasons:
        asin = '%' + asin + '%'
        db.cur_exec(c, "update shows set year=? where asin like ?", (year, asin))
Beispiel #46
0
def updateFanart():
    if var.tvdb_art == '0':
        return

    seasons = False
    c = tvDB.cursor()
    sqlstring = "select asin, seriestitle, fanart, poster from shows where fanart is null"
    Log('TV Update: Updating Fanart')
    if var.tvdb_art == '2':
        sqlstring += " or fanart like '%images-amazon.com%'"
    if var.tvdb_art == '3':
        sqlstring += " or poster like '%images-amazon.com%'"
        seasons = True
    db.waitforDB(tvDB)
    for asin, title, oldfanart, oldposter in db.cur_exec(c, sqlstring).fetchall():
        title = title.lower().replace('[ov]', '').replace('[ultra hd]', '').replace('?', '') \
                .replace('omu', '').split('(')[0].strip()
        tvid, poster, fanart = appfeed.getTVDBImages(title, seasons=seasons)

        if not fanart:
            fanart = appfeed.getTMDBImages(title, content='tv')

        if oldfanart and not fanart:
            fanart = oldfanart

        if oldposter and not poster:
            poster = oldposter

        if tvid:
            if not fanart:
                fanart = na

            if not poster:
                fanart = na

        db.cur_exec(c, 'update shows set fanart=? where asin = (?)', (fanart, asin))
        if var.tvdb_art == '3':
            db.cur_exec(c, 'update shows set poster=? where asin = (?)', (poster, asin))
            if tvid:
                for season, url in tvid.items():
                    for singleasin in asin.split(','):
                        singleasin = '%' + singleasin + '%'
                        db.cur_exec(c, 'update seasons set poster=? where seriesasin like (?) and season = (?)',
                                    (url, singleasin, int(season)))
    tvDB.commit()
    Log('TV Update: Updating Fanart Finished')
Beispiel #47
0
def setNewest(compList=False):
    if not compList:
        compList = getCategories()
    catList = compList['movies']
    db.waitforDB(MovieDB)
    c = MovieDB.cursor()
    db.cur_exec(c, 'drop table if exists categories')
    db.cur_exec(
        c, '''create table categories(
                 title TEXT,
    asins TEXT);''')
    db.cur_exec(c, 'update movies set recent=null')
    count = 1
    for catid in catList:
        if catid == 'PrimeMovieRecentlyAdded':
            for asin in catList[catid]:
                updateMoviedb(asin, 'recent', count)
                count += 1
        else:
            db.cur_exec(c, 'insert ignore into categories values (?,?)',
                        [catid, catList[catid]])
    MovieDB.commit()
Beispiel #48
0
def updateFanart():
    if tmdb_art == '0':
        return

    sqlstring = "select asin, movietitle, year, fanart from movies where fanart is null"
    c = MovieDB.cursor()
    Log('Movie Update: Updating Fanart')
    if tmdb_art == '2':
        sqlstring += " or fanart like '%images-amazon.com%'"

    db.waitforDB(MovieDB)
    for asin, movie, year, oldfanart in db.cur_exec(c, sqlstring):
        movie = movie.lower().replace('[ov]', '').replace('omu', '').replace(
            '[ultra hd]', '').split('(')[0].strip()
        result = appfeed.getTMDBImages(movie, year=year)
        if oldfanart:
            if result == na or not result:
                result = oldfanart
        updateMoviedb(asin, 'fanart', result)
    MovieDB.commit()
    Log('Movie Update: Updating Fanart Finished')
Beispiel #49
0
def countDB(tbl):
    c = tvDB.cursor()
    return len(db.cur_exec(c, 'select * from %s' % tbl).fetchall())
Beispiel #50
0
def loadTVEpisodesdb(seriestitle):
    db.waitforDB(tvDB)
    c = tvDB.cursor()
    return db.cur_exec(c, 'select distinct * from episodes where seasonasin = (?) order by episode', (seriestitle,))
Beispiel #51
0
def getPoster(seriestitle):
    c = tvDB.cursor()
    data = db.cur_exec(c, 'select distinct poster from seasons where seriestitle = (?)', (seriestitle,)).fetchone()
    return data[0]