Fix FileNotFound error when trying to download search plugin when the working directory is not the directory of the program

This commit is contained in:
James Taylor 2020-02-06 22:17:58 -08:00
parent d86384c4ec
commit 6f28d959f0
2 changed files with 3 additions and 1 deletions

View File

@ -147,6 +147,7 @@ For security reasons, enabling this is not recommended.''',
}), }),
]) ])
program_directory = os.path.dirname(os.path.realpath(__file__))
acceptable_targets = settings_info.keys() | {'enable_comments', 'enable_related_videos'} acceptable_targets = settings_info.keys() | {'enable_comments', 'enable_related_videos'}

View File

@ -8,6 +8,7 @@ import base64
import mimetypes import mimetypes
from flask import request from flask import request
import flask import flask
import os
# Sort: 1 # Sort: 1
# Upload date: 2 # Upload date: 2
@ -106,6 +107,6 @@ def get_search_page():
@yt_app.route('/opensearch.xml') @yt_app.route('/opensearch.xml')
def get_search_engine_xml(): def get_search_engine_xml():
with open("youtube/opensearch.xml", 'rb') as f: with open(os.path.join(settings.program_directory, 'youtube/opensearch.xml'), 'rb') as f:
content = f.read().replace(b'$port_number', str(settings.port_number).encode()) content = f.read().replace(b'$port_number', str(settings.port_number).encode())
return flask.Response(content, mimetype='application/xml') return flask.Response(content, mimetype='application/xml')