diff options
Diffstat (limited to 'settings.py')
-rw-r--r-- | settings.py | 181 |
1 files changed, 160 insertions, 21 deletions
diff --git a/settings.py b/settings.py index 1482db0..2de5efa 100644 --- a/settings.py +++ b/settings.py @@ -8,6 +8,20 @@ import flask from flask import request SETTINGS_INFO = collections.OrderedDict([ + ('app_public', { + 'type': bool, + 'default': False, + 'comment': '''Set app public mode, disabled by default''', + 'hidden': True, + 'category': 'network', + }), + ('app_url', { + 'type': str, + 'default': 'http://localhost', + 'comment': '''Set URL of app 'http://localhost' by default''', + 'hidden': True, + 'category': 'network', + }), ('route_tor', { 'type': int, 'default': 0, @@ -25,7 +39,7 @@ SETTINGS_INFO = collections.OrderedDict([ ('tor_port', { 'type': int, - 'default': 9150, + 'default': 9050, 'comment': '', 'category': 'network', }), @@ -39,7 +53,7 @@ SETTINGS_INFO = collections.OrderedDict([ ('port_number', { 'type': int, - 'default': 8080, + 'default': 9010, 'comment': '', 'category': 'network', }), @@ -47,7 +61,7 @@ SETTINGS_INFO = collections.OrderedDict([ ('allow_foreign_addresses', { 'type': bool, 'default': False, - 'comment': '''This will allow others to connect to your Youtube Local instance as a website. + 'comment': '''This will allow others to connect to your YT Local instance as a website. For security reasons, enabling this is not recommended.''', 'hidden': True, 'category': 'network', @@ -137,25 +151,101 @@ For security reasons, enabling this is not recommended.''', 'category': 'interface', }), + ('autoplay_videos', { + 'type': bool, + 'default': False, + 'comment': '', + 'category': 'playback', + }), + ('default_resolution', { 'type': int, 'default': 720, 'comment': '', 'options': [ + (144, '144p'), + (240, '240p'), (360, '360p'), + (480, '480p'), (720, '720p'), + (1080, '1080p'), + (1440, '1440p'), + (2160, '2160p'), ], 'category': 'playback', }), - ('use_video_hotkeys', { - 'label': 'Enable video hotkeys', - 'type': bool, - 'default': True, + ('codec_rank_av1', { + 'type': int, + 'default': 1, + 'label': 'AV1 Codec Ranking', + 'comment': '', + 'options': [(1, '#1'), (2, '#2'), (3, '#3')], + 'category': 'playback', + }), + + ('codec_rank_vp', { + 'type': int, + 'default': 2, + 'label': 'VP8/VP9 Codec Ranking', 'comment': '', + 'options': [(1, '#1'), (2, '#2'), (3, '#3')], + 'category': 'playback', + }), + + ('codec_rank_h264', { + 'type': int, + 'default': 3, + 'label': 'H.264 Codec Ranking', + 'comment': '', + 'options': [(1, '#1'), (2, '#2'), (3, '#3')], + 'category': 'playback', + 'description': ( + 'Which video codecs to prefer. Codecs given the same ' + 'ranking will use smaller file size as a tiebreaker.' + ) + }), + + ('prefer_uni_sources', { + 'label': 'Use integrated sources', + 'type': int, + 'default': 1, + 'comment': '', + 'options': [ + (0, 'Prefer not'), + (1, 'Prefer'), + (2, 'Always'), + ], + 'category': 'playback', + 'description': 'If set to Prefer or Always and the default resolution is set to 360p or 720p, uses the unified (integrated) video files which contain audio and video, with buffering managed by the browser. If set to prefer not, uses the separate audio and video files through custom buffer management in av-merge via MediaSource unless they are unavailable.', + }), + + ('use_video_player', { + 'type': int, + 'default': 1, + 'comment': '', + 'options': [ + (0, 'Native'), + (1, 'Native with hotkeys'), + (2, 'Plyr'), + ], 'category': 'interface', }), + ('use_video_download', { + 'type': int, + 'default': 0, + 'comment': '', + 'options': [ + (0, 'Disabled'), + (1, 'Enabled'), + ], + 'category': 'interface', + 'comment': '''If enabled, you may incur legal issues with RIAA. Disabled by default. +More info: https://torrentfreak.com/riaa-thwarts-youts-attempt-to-declare-youtube-ripping-legal-221002/ +Archive: https://archive.ph/OZQbN''', + }), + ('proxy_images', { 'label': 'Route images', 'type': bool, @@ -198,8 +288,8 @@ For security reasons, enabling this is not recommended.''', 'comment': '', 'options': [ (0, 'Browser default'), - (1, 'Arial'), - (2, 'Liberation Serif'), + (1, 'Liberation Serif'), + (2, 'Arial'), (3, 'Verdana'), (4, 'Tahoma'), ], @@ -220,11 +310,16 @@ For security reasons, enabling this is not recommended.''', 'comment': '', }), - ('gather_googlevideo_domains', { + ('include_shorts_in_subscriptions', { 'type': bool, - 'default': False, - 'comment': '''Developer use to debug 403s''', - 'hidden': True, + 'default': 0, + 'comment': '', + }), + + ('include_shorts_in_channel', { + 'type': bool, + 'default': 1, + 'comment': '', }), ('debugging_save_responses', { @@ -236,14 +331,16 @@ For security reasons, enabling this is not recommended.''', ('settings_version', { 'type': int, - 'default': 3, + 'default': 6, 'comment': '''Do not change, remove, or comment out this value, or else your settings may be lost or corrupted''', 'hidden': True, }), ]) 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', 'preferred_video_codec' +} def comment_string(comment): @@ -290,9 +387,45 @@ def upgrade_to_3(settings_dict): return new_settings +def upgrade_to_4(settings_dict): + new_settings = settings_dict.copy() + if 'preferred_video_codec' in settings_dict: + pref = settings_dict['preferred_video_codec'] + if pref == 0: + new_settings['codec_rank_h264'] = 1 + new_settings['codec_rank_vp'] = 2 + new_settings['codec_rank_av1'] = 3 + else: + new_settings['codec_rank_h264'] = 3 + new_settings['codec_rank_vp'] = 2 + new_settings['codec_rank_av1'] = 1 + del new_settings['preferred_video_codec'] + new_settings['settings_version'] = 4 + return new_settings + + +def upgrade_to_5(settings_dict): + new_settings = settings_dict.copy() + if 'prefer_uni_sources' in settings_dict: + new_settings['prefer_uni_sources'] = int(settings_dict['prefer_uni_sources']) + new_settings['settings_version'] = 5 + return new_settings + + +def upgrade_to_6(settings_dict): + new_settings = settings_dict.copy() + if 'gather_googlevideo_domains' in new_settings: + del new_settings['gather_googlevideo_domains'] + new_settings['settings_version'] = 6 + return new_settings + + upgrade_functions = { 1: upgrade_to_2, 2: upgrade_to_3, + 3: upgrade_to_4, + 4: upgrade_to_5, + 5: upgrade_to_6, } @@ -306,8 +439,8 @@ if os.path.isfile("settings.txt"): data_dir = os.path.normpath('./data') else: print("Running in non-portable mode") - settings_dir = os.path.expanduser(os.path.normpath("~/.youtube-local")) - data_dir = os.path.expanduser(os.path.normpath("~/.youtube-local/data")) + settings_dir = os.path.expanduser(os.path.normpath("~/.yt-local")) + data_dir = os.path.expanduser(os.path.normpath("~/.yt-local/data")) if not os.path.exists(settings_dir): os.makedirs(settings_dir) @@ -381,14 +514,14 @@ globals().update(current_settings_dict) if route_tor: print("Tor routing is ON") else: - print("Tor routing is OFF - your Youtube activity is NOT anonymous") + print("Tor routing is OFF - your YouTube activity is NOT anonymous") hooks = {} def add_setting_changed_hook(setting, func): - '''Called right before new settings take effect''' + '''Called right after new settings take effect''' if setting in hooks: hooks[setting].append(func) else: @@ -443,15 +576,21 @@ def settings_page(): assert SETTINGS_INFO[setting_name]['type'] is bool, missing_inputs current_settings_dict[setting_name] = False - # call setting hooks + # find settings that have changed to prepare setting hook calls + to_call = [] for setting_name, value in current_settings_dict.items(): old_value = globals()[setting_name] if value != old_value and setting_name in hooks: for func in hooks[setting_name]: - func(old_value, value) + to_call.append((func, old_value, value)) globals().update(current_settings_dict) save_settings(current_settings_dict) + + # call setting hooks + for func, old_value, value in to_call: + func(old_value, value) + return flask.redirect(util.URL_ORIGIN + '/settings', 303) else: flask.abort(400) |