def import_fav(): print 'fav' dialog = xbmcgui.Dialog() print 'd' try: r = dialog.browse(3, 'Folder', 'files') print r path = os.path.join(r, 'favorites.txt') shows = common.fetch_showlist(1) sd = {} for show in shows: sd[show[0]] = show import json print r json_data=open(path).read() #print json_data jd = json.loads(json_data) for title in jd: show = jd[title] series_title = show[0] mode = show[1] submode = show[2] series_title = urllib.unquote_plus(series_title) command = 'update shows set favor = 1 where series_title = ? and mode = ? and submode = ?;' values = (series_title, mode, submode) print values database.execute_command(command, values, commit = True) except Exception,e: print e
def create_watchlist(user_id, watchlist_name): '''Creates a watchlist for a user''' try: db.execute_command(conn, f'''INSERT INTO watchlist(user_id, watchlist_name) VALUES ({user_id}, '{watchlist_name}')''') return 'Success embed' except RuntimeError: return 'Watchlist already exists!'
def import_fav(): print 'fav' dialog = xbmcgui.Dialog() print 'd' try: r = dialog.browse(3, 'Folder', 'files') print r path = os.path.join(r, 'favorites.txt') shows = common.fetch_showlist(1) sd = {} for show in shows: sd[show[0]] = show import json print r json_data = open(path).read() #print json_data jd = json.loads(json_data) for title in jd: show = jd[title] series_title = show[0] mode = show[1] submode = show[2] series_title = urllib.unquote_plus(series_title) command = 'update shows set favor = 1 where series_title = ? and mode = ? and submode = ?;' values = (series_title, mode, submode) print values database.execute_command(command, values, commit=True) except Exception, e: print e
def refresh_db(): if not os.path.isfile(ustvpaths.DBFILE): database.create_db() networks = get_networks() dialog = xbmcgui.DialogProgress() dialog.create(smart_utf8(addon.getLocalizedString(39016))) total_stations = len(networks) current = 0 increment = 100.0 / total_stations all_shows = [] for network in networks: network_name = network.NAME if addon.getSetting(network.SITE) == 'true': percent = int(increment * current) dialog.update( percent, smart_utf8(addon.getLocalizedString(39017)) + network.NAME, smart_utf8(addon.getLocalizedString(39018))) showdata = network.masterlist() for show in showdata: try: series_title, mode, submode, url = show except: series_title, mode, submode, url, siteplot = show all_shows.append((smart_unicode(series_title.lower().strip()), smart_unicode(mode), smart_unicode(submode))) total_shows = len(showdata) current_show = 0 for show in showdata: percent = int((increment * current) + (float(current_show) / total_shows) * increment) dialog.update( percent, smart_utf8(addon.getLocalizedString(39017)) + network.NAME, smart_utf8(addon.getLocalizedString(39005)) + show[0]) get_serie(show[0], show[1], show[2], show[3], forceRefresh=False) current_show += 1 if (dialog.iscanceled()): return False current += 1 command = 'select tvdb_series_title , series_title, mode, submode, url from shows order by series_title' shows = database.execute_command(command, fetchall=True) for show in shows: tvdb_series_title, series_title, mode, submode, url = show if ((smart_unicode(series_title.lower().strip()), smart_unicode(mode), smart_unicode(submode)) not in all_shows and (smart_unicode(tvdb_series_title.lower().strip()), smart_unicode(mode), smart_unicode(submode)) not in all_shows): command = 'delete from shows where series_title = ? and mode = ? and submode = ? and url = ?;' values = (series_title, mode, submode, url) print "Deleting - " + series_title + " " + mode + " " + submode + " " + url database.execute_command(command, values, fetchone=True, commit=True)
def unhide_show(): series_title, mode, submode, url = args.url.split('<join>') series_title = urllib.unquote_plus(series_title) command = 'update shows set hide = 0 where tvdb_series_title = ? and mode = ? and submode = ?;' values = (series_title, mode, submode) database.execute_command(command, values, commit=True) common.args.name = series_title common.args.url = url refresh_menu(mode, submode, url)
def unhide_show(): series_title, mode, submode, url = args.url.split("<join>") series_title = urllib.unquote_plus(series_title) command = "update shows set hide = 0 where tvdb_series_title = ? and mode = ? and submode = ?;" values = (series_title, mode, submode) database.execute_command(command, values, commit=True) common.args.name = series_title common.args.url = url refresh_menu(mode, submode, url)
def fetch_showlist(favored = 0): if not os.path.exists(ustvpaths.DBFILE): database.create_db() refresh_db() elif not favored: refresh = False command = 'select distinct mode from shows order by mode' modes = database.execute_command(command, fetchall = True) mode_list = [element[0] for element in modes] for network in get_networks(): if addon.getSetting(network.SITE) == 'true' and network.SITE not in mode_list: refresh = True if refresh: refresh_db() database.check_db_version() command = "select * from shows where url <> '' and hide <> 1 and favor = ? order by series_title" return database.execute_command(command, fetchall = True, values = [favored])
def refresh_db(): if not os.path.isfile(ustvpaths.DBFILE): database.create_db() networks = get_networks() dialog = xbmcgui.DialogProgress() dialog.create(smart_utf8(addon.getLocalizedString(39016))) total_stations = len(networks) current = 0 increment = 100.0 / total_stations all_shows = [] for network in networks: network_name = network.NAME if addon.getSetting(network.SITE) == 'true': percent = int(increment * current) dialog.update(percent, smart_utf8(addon.getLocalizedString(39017)) + network.NAME, smart_utf8(addon.getLocalizedString(39018))) showdata = network.masterlist() for show in showdata: try: series_title, mode, submode, url = show except: series_title, mode, submode, url, siteplot = show all_shows.append((smart_unicode(series_title.lower().strip()), smart_unicode(mode), smart_unicode(submode))) total_shows = len(showdata) current_show = 0 for show in showdata: percent = int((increment * current) + (float(current_show) / total_shows) * increment) dialog.update(percent, smart_utf8(addon.getLocalizedString(39017)) + network.NAME, smart_utf8(addon.getLocalizedString(39005)) + show[0]) get_serie(show[0], show[1], show[2], show[3], forceRefresh = False) current_show += 1 if (dialog.iscanceled()): return False current += 1 command = 'select tvdb_series_title , series_title, mode, submode, url from shows order by series_title' shows = database.execute_command(command, fetchall = True) for show in shows: tvdb_series_title, series_title, mode, submode, url = show if ((smart_unicode(series_title.lower().strip()),smart_unicode(mode), smart_unicode(submode)) not in all_shows and (smart_unicode(tvdb_series_title.lower().strip()),smart_unicode(mode), smart_unicode(submode)) not in all_shows): command = 'delete from shows where series_title = ? and mode = ? and submode = ? and url = ?;' values = (series_title, mode, submode, url) print "Deleting - " + series_title + " " + mode + " " + submode + " " + url database.execute_command(command, values, fetchone = True, commit = True)
def episodes(episode_url = common.args.url): try: shutil.rmtree(os.path.join(ustvpaths.DATAPATH,'thumbs')) except: pass episode_data = connection.getURL(VIDEOLIST % episode_url.split('#')[0]) episode_menu = simplejson.loads(episode_data)['videos'] os.mkdir(os.path.join(ustvpaths.DATAPATH,'thumbs')) for episode_item in episode_menu: if int(episode_item['fullep']) == int(episode_url.split('#')[1]): show_name = episode_item['series_name'] url = episode_item['guid'] episode_duration = int(episode_item['duration_secs']) episode_plot = episode_item['description_long'] episode_name = episode_item['title'] season_number = int(episode_item['season']) episode_thumb = episode_item['large_thumbnail'] thumb_file = episode_thumb.split('/')[-1] thumb_path = os.path.join(ustvpaths.DATAPATH, 'thumbs', thumb_file) thumbcount = 0 for name in glob.glob(os.path.join(ustvpaths.DBPATH,'textures[0-9]*.db')): thumbcount = thumbcount+ database.execute_command('select count(1) from texture where url = ?', [thumb_path,], fetchone = True, dbfile = name)[0] if thumbcount == 0: thumb_data = connection.getURL(episode_thumb) file = open(thumb_path, 'wb') file.write(thumb_data) file.close() try: episode_number = int(episode_item['episode'][len(str(season_number)):]) except: episode_number = -1 try: episode_airdate = common.format_date(episode_item['airdate'],'%Y-%b-%d', '%d.%m.%Y') except: episode_airdate = -1 u = sys.argv[0] u += '?url="' + urllib.quote_plus(url) + '"' u += '&mode="' + SITE + '"' u += '&sitemode="play_video"' infoLabels={ 'title' : episode_name, 'durationinseconds' : episode_duration, 'season' : season_number, 'episode' : episode_number, 'plot' : episode_plot, 'premiered' : episode_airdate, 'tvshowtitle': show_name } common.add_video(u, episode_name, thumb_path, infoLabels = infoLabels) common.set_view('episodes')
def get_plot_by_tvdbid(tvdb_id): command = 'select * from shows where tvdb_id = ?;' values = (tvdb_id,) showdata = database.execute_command(command, values, fetchone = True) prefixplot = '' if showdata: series_title, mode, sitemode, url, tvdb_id, imdb_id, tvdbbanner, tvdbposter, tvdbfanart, first_aired, date, year, actors, genres, network, plot, runtime, rating, airs_dayofweek, airs_time, status, has_full_episodes, favor, hide, tvdb_series_title = showdata if network is not None: prefixplot += smart_utf8(addon.getLocalizedString(39013)) + network + '\n' if (airs_dayofweek is not None) and (airs_time is not None): prefixplot += smart_utf8(addon.getLocalizedString(39014)) + airs_dayofweek + '@' + airs_time + '\n' if status is not None: prefixplot += smart_utf8(addon.getLocalizedString(39015)) + status + '\n' if prefixplot is not '': prefixplot += '\n' if plot is not None: prefixplot = smart_unicode(prefixplot) + smart_unicode(replace_signs(plot)) return prefixplot
def get_serie(series_title, mode, submode, url, forceRefresh = False, sitedata = None): command = 'select * from shows where lower(series_title) = ? and mode = ? and submode = ?;' values = (series_title.lower(), mode, submode) checkdata = database.execute_command(command, values, fetchone = True) empty_values = get_skelton_series(series_title, mode, submode, url) try: siteplot = sitedata['plot'] except: siteplot = None try: tvdb_setting = int(addon.getSetting('strict_names')) except: tvdb_setting = 0 if checkdata and not forceRefresh and checkdata[24] is not None and checkdata[20] != 'None': if smart_unicode(checkdata[3]) != smart_unicode(url): command = 'update shows set url = ? where tvdb_series_title = ? and mode = ? and submode = ?;' values = (url, series_title, mode, submode) database.execute_command(command, values, commit = True) command = 'select * from shows where lower(series_title) = ? and mode = ? and submode = ?;' values = (series_title.lower(), mode, submode) return database.execute_command(command, values, fetchone = True) elif checkdata[15] is None and siteplot is not None: command = 'update shows set plot = ? where series_title = ? and mode = ? and submode = ?;' values = (siteplot, series_title, mode, submode) database.execute_command(command, values, commit = True) command = 'select * from shows where lower(series_title) = ? and mode = ? and submode = ?;' values = (series_title.lower(), mode, submode) return database.execute_command(command, values, fetchone = True) else: return checkdata elif tvdb_setting != 1 or forceRefresh: network = get_network(mode) try: tvdb_data = get_tvdb_series(series_title, manualSearch = forceRefresh, site = network.NAME, network_alias = network.ALIAS) except: tvdb_data = get_tvdb_series(series_title, manualSearch = forceRefresh, site = network.NAME) if tvdb_data: tvdb_id, imdb_id, tvdbbanner, tvdbposter, tvdbfanart, first_aired, date, year, actors, genres, network, plot, runtime, rating, airs_dayofweek, airs_time, status, tvdb_series_title = tvdb_data values = [series_title, mode, submode, url, tvdb_id, imdb_id, tvdbbanner, tvdbposter, tvdbfanart, first_aired, date, year, actors, genres, network, plot, runtime, rating, airs_dayofweek, airs_time, status, True, False, False, tvdb_series_title] else: values = empty_values command = 'insert or replace into shows values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);' database.execute_command(command, values, commit = True) command = 'select * from shows where series_title = ? and mode = ? and submode = ?;' values = (series_title, mode, submode) return database.execute_command(command, values, fetchone = True) else: command = 'insert or replace into shows values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);' empty_values[20] = 'None' database.execute_command(command, empty_values, commit = True) return empty_values
def episodes(episode_url=common.args.url): episodes = [] try: shutil.rmtree(os.path.join(ustvpaths.DATAPATH, 'thumbs')) except: pass episode_data = connection.getURL(VIDEOLIST % episode_url.split('#')[0]) episode_menu = simplejson.loads(episode_data)['videos'] try: os.mkdir(os.path.join(ustvpaths.DATAPATH, 'thumbs')) except: pass for episode_item in episode_menu: if int(episode_item['fullep']) == int(episode_url.split('#')[1]): show_name = episode_item['series_name'] url = episode_item['guid'] episode_duration = int(episode_item['duration_secs']) episode_plot = episode_item['description_long'] episode_name = episode_item['title'] season_number = int(episode_item['season']) episode_thumb = episode_item['large_thumbnail'] thumb_file = episode_thumb.split('/')[-1] thumb_path = os.path.join(ustvpaths.DATAPATH, 'thumbs', thumb_file) dbpath = xbmc.translatePath(ustvpaths.DBPATH) thumbcount = 0 for name in glob.glob(os.path.join(dbpath, 'textures[0-9]*.db')): thumbcount = thumbcount + database.execute_command( 'select count(1) from texture where url = ?', [ thumb_path, ], fetchone=True, dbfile=name)[0] if thumbcount == 0: thumb_data = connection.getURL(episode_thumb) file = open(thumb_path, 'wb') file.write(thumb_data) file.close() try: episode_number = int( episode_item['episode'][len(str(season_number)):]) except: episode_number = -1 try: episode_airdate = common.format_date(episode_item['airdate'], '%Y-%b-%d', '%d.%m.%Y') except: episode_airdate = -1 if episode_item['fullep'] == 1: episode_type = 'Full Episode' else: episode_type = 'Clip' episode_expires = episode_item['expire_time'] episode_mpaa = episode_item['rating'] u = sys.argv[0] u += '?url="' + urllib.quote_plus(url) + '"' u += '&mode="' + SITE + '"' u += '&sitemode="play_video"' infoLabels = { 'title': episode_name, 'durationinseconds': episode_duration, 'season': season_number, 'episode': episode_number, 'plot': episode_plot, 'premiered': episode_airdate, 'tvshowtitle': show_name, 'TVShowTitle': show_name, 'mpaa': episode_mpaa } infoLabels = common.enrich_infolabels( infoLabels, episode_expires.split('+')[0], '%Y-%m-%dT%H:%M:%S') episodes.append((u, episode_name, thumb_path, infoLabels, None, False, episode_type)) return episodes
def delete_show(): series_title, mode, submode, url = args.url.split('<join>') series_title = urllib.unquote_plus(series_title) command = 'delete from shows where tvdb_series_title = ? and mode = ? and submode = ?;' values = (series_title, mode, submode) database.execute_command(command, values, commit=True)
import sqlite3 from sqlite3 import Error import database as db conn = db.create_connection(r'watchlist.db') # connects to database for watchlists # creates a table to store data db.execute_command(conn, '''CREATE TABLE IF NOT EXISTS watchlist ( user_id int, watchlist_name varchar(255), symbols varchar(255), unique (user_id, watchlist_name) );''') def create_watchlist(user_id, watchlist_name): '''Creates a watchlist for a user''' try: db.execute_command(conn, f'''INSERT INTO watchlist(user_id, watchlist_name) VALUES ({user_id}, '{watchlist_name}')''') return 'Success embed' except RuntimeError: return 'Watchlist already exists!' def remove_watchlist(user_id, watchlist_name): '''Deletes an existing watchlist''' # will search for the entry in the database with user id, and watchlist name if found removes else returns an error embed return def add_symbol(user_id, symbol, watchlist_name): '''Adds a symbol passed in, to a watchlist''' # adds symbol to the 'symbols' field of the database for the user id and watchlist name return
def unfavor_show(): series_title, mode, submode, url = args.url.split("<join>") series_title = urllib.unquote_plus(series_title) command = "update shows set favor = 0 where series_title = ? and mode = ? and submode = ?;" values = (series_title, mode, submode) database.execute_command(command, values, commit=True)
def del_favorites(): command = "update shows set favor = 0 where favor = 1" database.execute_command(command, commit=True)
def hide_show(): series_title, mode, submode, url = args.url.split('<join>') series_title = urllib.unquote_plus(series_title) command = 'update shows set hide = 1 where tvdb_series_title = ? and mode = ? and submode = ?;' values = (series_title, mode, submode) database.execute_command(command, values, commit = True)
def del_favorites(): command = "update shows set favor = 0 where favor = 1" database.execute_command(command, commit = True)
def unfavor_show(): series_title, mode, submode, url = args.url.split('<join>') series_title = urllib.unquote_plus(series_title) command = 'update shows set favor = 0 where series_title = ? and mode = ? and submode = ?;' values = (series_title, mode, submode) database.execute_command(command, values, commit=True)
def delete_show(): series_title, mode, submode, url = args.url.split("<join>") series_title = urllib.unquote_plus(series_title) command = "delete from shows where tvdb_series_title = ? and mode = ? and submode = ?;" values = (series_title, mode, submode) database.execute_command(command, values, commit=True)
def episodes(episode_url=common.args.url): episodes = [] try: shutil.rmtree(os.path.join(ustvpaths.DATAPATH, "thumbs")) except: pass episode_data = connection.getURL(VIDEOLIST % episode_url.split("#")[0]) episode_menu = simplejson.loads(episode_data)["videos"] try: os.mkdir(os.path.join(ustvpaths.DATAPATH, "thumbs")) except: pass for episode_item in episode_menu: if int(episode_item["fullep"]) == int(episode_url.split("#")[1]): show_name = episode_item["series_name"] url = episode_item["guid"] episode_duration = int(episode_item["duration_secs"]) episode_plot = episode_item["description_long"] episode_name = episode_item["title"] season_number = int(episode_item["season"]) episode_thumb = episode_item["large_thumbnail"] thumb_file = episode_thumb.split("/")[-1] thumb_path = os.path.join(ustvpaths.DATAPATH, "thumbs", thumb_file) dbpath = xbmc.translatePath(ustvpaths.DBPATH) thumbcount = 0 for name in glob.glob(os.path.join(dbpath, "textures[0-9]*.db")): thumbcount = ( thumbcount + database.execute_command( "select count(1) from texture where url = ?", [thumb_path], fetchone=True, dbfile=name )[0] ) if thumbcount == 0: thumb_data = connection.getURL(episode_thumb) file = open(thumb_path, "wb") file.write(thumb_data) file.close() try: episode_number = int(episode_item["episode"][len(str(season_number)) :]) except: episode_number = -1 try: episode_airdate = common.format_date(episode_item["airdate"], "%Y-%b-%d", "%d.%m.%Y") except: episode_airdate = -1 if episode_item["fullep"] == 1: episode_type = "Full Episode" else: episode_type = "Clip" episode_expires = episode_item["expire_time"] episode_mpaa = episode_item["rating"] u = sys.argv[0] u += '?url="' + urllib.quote_plus(url) + '"' u += '&mode="' + SITE + '"' u += '&sitemode="play_video"' infoLabels = { "title": episode_name, "durationinseconds": episode_duration, "season": season_number, "episode": episode_number, "plot": episode_plot, "premiered": episode_airdate, "tvshowtitle": show_name, "TVShowTitle": show_name, "mpaa": episode_mpaa, } infoLabels = common.enrich_infolabels(infoLabels, episode_expires.split("+")[0], "%Y-%m-%dT%H:%M:%S") episodes.append((u, episode_name, thumb_path, infoLabels, None, False, episode_type)) return episodes