diff --git a/bazarr.py b/bazarr.py index 55d549548..390b0ec80 100644 --- a/bazarr.py +++ b/bazarr.py @@ -1,9 +1,12 @@ -bazarr_version = '0.1.1' +# coding: utf-8 +from __future__ import unicode_literals + +bazarr_version = '0.1.4' from bottle import route, run, template, static_file, request, redirect import bottle -#bottle.debug(True) -#bottle.TEMPLATES.clear() +bottle.debug(True) +bottle.TEMPLATES.clear() import os bottle.TEMPLATE_PATH.insert(0,os.path.join(os.path.dirname(__file__), 'views/')) @@ -292,16 +295,6 @@ def check_update(): @route(base_url + 'system') def system(): - db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) - c = db.cursor() - c.execute("SELECT * FROM table_scheduler") - tasks = c.fetchall() - c.close() - - logs = [] - for line in reversed(open(os.path.join(os.path.dirname(__file__), 'data/log/bazarr.log')).readlines()): - logs.append(line.rstrip()) - def get_time_from_interval(interval): interval_clean = interval.split('[') interval_clean = interval_clean[1][:-1] @@ -387,8 +380,26 @@ def system(): task_list.append([job.name, get_time_from_interval(str(job.trigger)), pretty.date(job.next_run_time.replace(tzinfo=None)), job.id]) elif job.trigger.__str__().startswith('cron'): task_list.append([job.name, get_time_from_cron(job.trigger.fields), pretty.date(job.next_run_time.replace(tzinfo=None)), job.id]) + + with open(os.path.join(os.path.dirname(__file__), 'data/log/bazarr.log')) as f: + for i, l in enumerate(f, 1): + pass + row_count = i + max_page = (row_count / 50) + 1 - return template('system', tasks=tasks, logs=logs, base_url=base_url, task_list=task_list, bazarr_version=bazarr_version) + return template('system', base_url=base_url, task_list=task_list, row_count=row_count, max_page=max_page, bazarr_version=bazarr_version) + +@route(base_url + 'logs/') +def get_logs(page): + page_size = 50 + begin = (page * page_size) - page_size + end = (page * page_size) - 1 + logs_complete = [] + for line in reversed(open(os.path.join(os.path.dirname(__file__), 'data/log/bazarr.log')).readlines()): + logs_complete.append(line.rstrip()) + logs = logs_complete[begin:end] + + return template('logs', logs=logs, base_url=base_url) @route(base_url + 'execute/') def execute_task(taskid): @@ -414,7 +425,7 @@ def remove_subtitles(): except OSError: pass store_subtitles(episodePath) - list_missing_subtitles(tvdbid) + list_missing_subtitles(sonarrSeriesId) @route(base_url + 'get_subtitle', method='POST') def get_subtitle(): @@ -442,7 +453,7 @@ def get_subtitle(): if result is not None: history_log(1, sonarrSeriesId, sonarrEpisodeId, result) store_subtitles(episodePath) - list_missing_subtitles(tvdbid) + list_missing_subtitles(sonarrSeriesId) redirect(ref) except OSError: pass diff --git a/check_update.py b/check_update.py index f4ecc2e33..a7a75836b 100644 --- a/check_update.py +++ b/check_update.py @@ -1,3 +1,6 @@ +# coding: utf-8 +from __future__ import unicode_literals + from get_general_settings import * import os @@ -25,7 +28,25 @@ def check_and_apply_update(repo=local_repo, remote_name='origin'): repo.head.set_target(remote_id) result = 'Bazarr updated to latest version and restarting.' os.execlp('python', 'python', os.path.join(os.path.dirname(__file__), 'bazarr.py')) - else: - raise AssertionError('Unknown merge analysis result') + # We can just do it normally + elif merge_result & pygit2.GIT_MERGE_ANALYSIS_NORMAL: + repo.merge(remote_id) + print repo.index.conflicts + assert repo.index.conflicts is None, 'Conflicts, ahhhh!' + user = repo.default_signature + tree = repo.index.write_tree() + commit = repo.create_commit('HEAD', + user, + user, + 'Merge!', + tree, + [repo.head.target, remote_id]) + repo.state_cleanup() + result = 'Conflict detected when trying to update.' + os.execlp('python', 'python', os.path.join(os.path.dirname(__file__), 'bazarr.py')) + # We can't do it + else: + result = 'Bazarr cannot be updated: Unknown merge analysis result' + return result diff --git a/create_db.sql b/create_db.sql index a29b2fdf1..f60878a46 100644 --- a/create_db.sql +++ b/create_db.sql @@ -41,11 +41,6 @@ CREATE TABLE "table_settings_general" ( `auto_update` INTEGER ); INSERT INTO `table_settings_general` (ip,port,base_url,path_mapping,log_level, branch, auto_update) VALUES ('0.0.0.0',6767,'/',Null,'INFO','master','True'); -CREATE TABLE `table_scheduler` ( - `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, - `name` TEXT NOT NULL, - `frequency` TEXT NOT NULL -); CREATE TABLE "table_history" ( `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, `action` INTEGER NOT NULL, diff --git a/get_episodes.py b/get_episodes.py index f586d2e18..ee9f5750e 100644 --- a/get_episodes.py +++ b/get_episodes.py @@ -1,3 +1,6 @@ +# coding: utf-8 +from __future__ import unicode_literals + import os import sqlite3 import requests @@ -36,7 +39,7 @@ def update_all_episodes(): url_sonarr_api_episode = protocol_sonarr + "://" + config_sonarr[0] + ":" + str(config_sonarr[1]) + base_url_sonarr + "/api/episode?seriesId=" + str(seriesId[0]) + "&apikey=" + apikey_sonarr r = requests.get(url_sonarr_api_episode) for episode in r.json(): - if episode['hasFile']: + if episode['hasFile'] and episode['episodeFile']['size'] > 20480: # Add shows in Sonarr to current shows list current_episodes_sonarr.append(episode['id']) @@ -60,15 +63,6 @@ def update_all_episodes(): # Close database connection c.close() - - #Cleanup variables to free memory - del current_episodes_db - del current_episodes_db_list - del seriesIdList - del r - del current_episodes_sonarr - del deleted_items - del c # Store substitles for all episodes full_scan_subtitles() @@ -110,7 +104,7 @@ def add_new_episodes(): url_sonarr_api_episode = protocol_sonarr + "://" + config_sonarr[0] + ":" + str(config_sonarr[1]) + base_url_sonarr + "/api/episode?seriesId=" + str(seriesId[0]) + "&apikey=" + apikey_sonarr r = requests.get(url_sonarr_api_episode) for episode in r.json(): - if episode['hasFile']: + if episode['hasFile'] and episode['episodeFile']['size'] > 20480: # Add shows in Sonarr to current shows list current_episodes_sonarr.append(episode['id']) @@ -132,15 +126,6 @@ def add_new_episodes(): # Close database connection c.close() - - #Cleanup variables to free memory - del current_episodes_db - del current_episodes_db_list - del seriesIdList - del r - del current_episodes_sonarr - del deleted_items - del c # Store substitles from episodes we've just added new_scan_subtitles() diff --git a/get_general_settings.py b/get_general_settings.py index b86698fe8..a517e63cb 100644 --- a/get_general_settings.py +++ b/get_general_settings.py @@ -1,3 +1,6 @@ +# coding: utf-8 +from __future__ import unicode_literals + import sqlite3 import os import ast @@ -27,27 +30,23 @@ branch = general_settings[5] automatic = general_settings[6] def path_replace(path): - for path_mapping in path_mappings: - path = path.replace(path_mapping[0], path_mapping[1], 1) - - if '\\' in path: - path = path.replace('/', '\\') - - return path + for path_mapping in path_mappings: + if path_mapping[0] in path: + path = path.replace(path_mapping[0], path_mapping[1]) + if path.startswith('\\\\'): + path = path.replace('/', '\\') + elif path.startswith('/'): + path = path.replace('\\', '/') + break + return path def path_replace_reverse(path): - for path_mapping in path_mappings: - if path.startswith('\\\\\\\\'): - if '\\\\' in path: - path = path.replace('\\\\', '\\') - elif '\\' in path: - path = path.replace('\\\\', '\\') - - path = path.replace(path_mapping[1], path_mapping[0], 1) - elif path.startswith('\\\\'): - path = path.replace(path_mapping[1], path_mapping[0], 1) - - if '\\' in path: - path = path.replace('\\', '/') - - return path + for path_mapping in path_mappings: + if path_mapping[1] in path: + path = path.replace(path_mapping[1], path_mapping[0]) + if path.startswith('\\\\'): + path = path.replace('/', '\\') + elif path.startswith('/'): + path = path.replace('\\', '/') + break + return path diff --git a/get_languages.py b/get_languages.py index efb7cc4b0..8a81cb1cf 100644 --- a/get_languages.py +++ b/get_languages.py @@ -1,3 +1,6 @@ +# coding: utf-8 +from __future__ import unicode_literals + import sqlite3 import pycountry import os diff --git a/get_providers.py b/get_providers.py index c02e5c126..cfdf109ed 100644 --- a/get_providers.py +++ b/get_providers.py @@ -1,3 +1,6 @@ +# coding: utf-8 +from __future__ import unicode_literals + import sqlite3 import os from subliminal import * diff --git a/get_series.py b/get_series.py index 07c52f924..61f89d080 100644 --- a/get_series.py +++ b/get_series.py @@ -1,3 +1,6 @@ +# coding: utf-8 +from __future__ import unicode_literals + import os import sqlite3 import requests diff --git a/get_sonarr_settings.py b/get_sonarr_settings.py index bf64883b4..93a02f1cc 100644 --- a/get_sonarr_settings.py +++ b/get_sonarr_settings.py @@ -1,3 +1,6 @@ +# coding: utf-8 +from __future__ import unicode_literals + import sqlite3 import os import ast diff --git a/get_subtitle.py b/get_subtitle.py index 605a7c60a..f1e72c88e 100644 --- a/get_subtitle.py +++ b/get_subtitle.py @@ -1,3 +1,6 @@ +# coding: utf-8 +from __future__ import unicode_literals + import os import sqlite3 import ast @@ -26,20 +29,10 @@ def download_subtitle(path, language, hi, providers): except: return None - del video - del best_subtitles - try: - del result - del downloaded_provider - del downloaded_language - del message - except: - pass - def series_download_subtitles(no): conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) c_db = conn_db.cursor() - episodes_details = c_db.execute("SELECT path, missing_subtitles, sonarrEpisodeId FROM table_episodes WHERE path = ?", (no,)).fetchall() + episodes_details = c_db.execute("SELECT path, missing_subtitles, sonarrEpisodeId FROM table_episodes WHERE sonarrSeriesId = ?", (no,)).fetchall() series_details = c_db.execute("SELECT hearing_impaired FROM table_shows WHERE sonarrSeriesId = ?", (no,)).fetchone() enabled_providers = c_db.execute("SELECT name FROM table_settings_providers WHERE enabled = 1").fetchall() c_db.close() @@ -75,16 +68,6 @@ def wanted_download_subtitles(path): list_missing_subtitles(episode[3]) history_log(1, episode[3], episode[2], message) - del conn_db - del c_db - del episodes_details - del enabled_providers - del providers_list - try: - del message - except: - pass - def wanted_search_missing_subtitles(): db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) db.create_function("path_substitution", 1, path_replace) @@ -96,7 +79,3 @@ def wanted_search_missing_subtitles(): for episode in data: wanted_download_subtitles(episode[0]) - - del db - del c - del data diff --git a/init_db.py b/init_db.py index 1b6393284..9db99101b 100644 --- a/init_db.py +++ b/init_db.py @@ -1,3 +1,6 @@ +# coding: utf-8 +from __future__ import unicode_literals + import os import sqlite3 diff --git a/list_subtitles.py b/list_subtitles.py index a5cd58ada..1535137f4 100644 --- a/list_subtitles.py +++ b/list_subtitles.py @@ -1,3 +1,6 @@ +# coding: utf-8 +from __future__ import unicode_literals + import os import enzyme import babelfish @@ -49,18 +52,17 @@ def store_subtitles(file): except: pass - conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) - c_db = conn_db.cursor() - subtitles = core.search_external_subtitles(file) for subtitle, language in subtitles.iteritems(): actual_subtitles.append([str(language), path_replace_reverse(os.path.join(os.path.dirname(file), subtitle))]) - try: - c_db.execute("UPDATE table_episodes SET subtitles = ? WHERE path = ?", (str(actual_subtitles), path_replace_reverse(file))) - conn_db.commit() - except: - pass + + conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) + c_db = conn_db.cursor() + + c_db.execute("UPDATE table_episodes SET subtitles = ? WHERE path = ?", (str(actual_subtitles), path_replace_reverse(file))) + conn_db.commit() + c_db.close() return actual_subtitles @@ -68,7 +70,7 @@ def store_subtitles(file): def list_missing_subtitles(*no): query_string = '' try: - query_string = " WHERE table_shows.tvdbId = " + str(no[0]) + query_string = " WHERE table_shows.sonarrSeriesId = " + str(no[0]) except: pass conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) @@ -107,7 +109,7 @@ def full_scan_subtitles(): c_db.close() for episode in episodes: - store_subtitles(path_replace(episode[0].encode('utf-8'))) + store_subtitles(path_replace(episode[0])) def series_scan_subtitles(no): conn_db = sqlite3.connect(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) @@ -116,7 +118,7 @@ def series_scan_subtitles(no): c_db.close() for episode in episodes: - store_subtitles(path_replace(episode[0].encode('utf-8'))) + store_subtitles(path_replace(episode[0])) list_missing_subtitles(no) @@ -127,4 +129,4 @@ def new_scan_subtitles(): c_db.close() for episode in episodes: - store_subtitles(path_replace(episode[0].encode('utf-8'))) + store_subtitles(path_replace(episode[0])) diff --git a/scheduler.py b/scheduler.py index a77e9efac..724b9a12b 100644 --- a/scheduler.py +++ b/scheduler.py @@ -1,3 +1,6 @@ +# coding: utf-8 +from __future__ import unicode_literals + from get_general_settings import * from get_series import * from get_episodes import * diff --git a/update.py b/update.py index 69f249bf9..02b31f232 100644 --- a/update.py +++ b/update.py @@ -1,3 +1,6 @@ +# coding: utf-8 +from __future__ import unicode_literals + from get_general_settings import * import git diff --git a/utils.py b/utils.py index 68adf89ad..8cc932785 100644 --- a/utils.py +++ b/utils.py @@ -1,3 +1,6 @@ +# coding: utf-8 +from __future__ import unicode_literals + import os import sqlite3 import time diff --git a/views/history.tpl b/views/history.tpl index db555a142..a2386ffb2 100644 --- a/views/history.tpl +++ b/views/history.tpl @@ -40,6 +40,8 @@ .fast.backward, .backward, .forward, .fast.forward { cursor: pointer; } + .fast.backward, .backward, .forward, .fast.forward { pointer-events: auto; } + .fast.backward.disabled, .backward.disabled, .forward.disabled, .fast.forward.disabled { pointer-events: none; } diff --git a/views/logs.tpl b/views/logs.tpl new file mode 100644 index 000000000..305002b0b --- /dev/null +++ b/views/logs.tpl @@ -0,0 +1,87 @@ + + + + + + + + + + + +
+
Loading...
+
+
+ + + + + + + + + + %import time + %import datetime + %import pretty + %for log in logs: + %line = [] + %line = log.split('|') + + + + + + %end + +
MessageTime
{{line[2]}}{{pretty.date(int(time.mktime(datetime.datetime.strptime(line[0], "%d/%m/%Y %H:%M:%S").timetuple())))}}
+
+ + + + + + \ No newline at end of file diff --git a/views/system.tpl b/views/system.tpl index 7f35d7d3e..738a1c9dd 100644 --- a/views/system.tpl +++ b/views/system.tpl @@ -37,6 +37,11 @@ margin-bottom: 3em; padding: 1em; } + .fast.backward, .backward, .forward, .fast.forward { + cursor: pointer; + } + .fast.backward, .backward, .forward, .fast.forward { pointer-events: auto; } + .fast.backward.disabled, .backward.disabled, .forward.disabled, .fast.forward.disabled { pointer-events: none; } @@ -107,86 +112,78 @@
- - - - - - - - - - %import time - %import datetime - %import pretty - %for log in logs: - %line = [] - %line = log.split('|') - - - - - - %end - -
MessageTime
{{line[2]}}{{pretty.date(int(time.mktime(datetime.datetime.strptime(line[0], "%d/%m/%Y %H:%M:%S").timetuple())))}}
+
+ +
+
+
+
+ + + / {{max_page}} + + +
+
Total records: {{row_count}}
+
+
Bazarr version: {{bazarr_version}}
- -