-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconstants.py
268 lines (219 loc) · 10.6 KB
/
constants.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
''' Contains a number of constants used throughout the project
that were originally spread across the tops of several files.
thisismy-github 3/14/22 '''
import qthelpers
import os
import sys
import time
import platform
import subprocess
# ---------------------
VERSION = 'pyplayer 0.6.0 beta'
REPOSITORY_URL = 'https://github.com/thisismy-github/pyplayer'
# ---------------------
SCRIPT_START_TIME = time.time()
IS_COMPILED = getattr(sys, 'frozen', False)
APP_RUNNING = False
PLATFORM = platform.system()
IS_WINDOWS = PLATFORM == 'Windows'
IS_MAC = PLATFORM == 'Darwin'
IS_LINUX = not IS_WINDOWS and not IS_MAC
SCRIPT_PATH = sys.executable if IS_COMPILED else os.path.realpath(__file__)
CWD = os.path.dirname(SCRIPT_PATH)
_sep = os.sep
BIN_DIR = f'{CWD}{_sep}{"PyQt5" if IS_COMPILED else "bin"}'
TEMP_DIR = f'{BIN_DIR}{_sep}temp'
PROBE_DIR = f'{TEMP_DIR}{_sep}probed'
THUMBNAIL_DIR = f'{TEMP_DIR}{_sep}thumbnails'
THEME_DIR = f'{CWD}{_sep}themes'
RESOURCE_DIR = f'{THEME_DIR}{_sep}resources'
LOG_PATH = f'{CWD}{_sep}pyplayer.log'
CONFIG_PATH = f'{CWD}{_sep}config.ini'
PID_PATH = f'{TEMP_DIR}{_sep}{os.getpid()}.pid'
for _dir in (TEMP_DIR, PROBE_DIR, THUMBNAIL_DIR, THEME_DIR):
try: os.makedirs(_dir)
except: continue
# ---------------------
if IS_WINDOWS:
STARTUPINFO = subprocess.STARTUPINFO()
STARTUPINFO.dwFlags |= subprocess.STARTF_USESHOWWINDOW
else:
STARTUPINFO = None
# ---------------------
SUBTITLE_EXTENSIONS = ('.cdg', '.idx', '.srt', '.sub', '.utf', '.ass', '.ssa',
'.aqt', '.jss', '.psb', '.it', '.sami', 'smi', '.txt',
'.smil', '.stl', '.usf', '.dks', '.pjs', '.mpl2',
'.mks', '.vtt', '.tt', '.ttml', '.dfxp', '.scc')
SPECIAL_TRIM_EXTENSIONS = ('x-msvideo', 'quicktime', 'x-flv', 'webm', 'mpeg', 'ogg')
VIDEO_EXTENSIONS = ('.mp4', '.mpeg', '.m1v', '.mpe', '.mpg', '.mov', '.qt',
'.webm', '.avi', '.movie', '.264', '.3g2', '.3gp', '.3gp2',
'.3gpp', '.amv', '.asf', '.asx', '.divx', '.dv', '.evo',
'.f4v', '.flv', '.h264', '.hdmov', '.IVF', '.m2t', '.m2ts',
'.m2v', '.m4a', '.m4v', '.mk3d', '.mkv', '.mod', '.mp2v',
'.mp4v', '.mpv2', '.mpv4', '.mts', '.mxf', '.ogm', '.ogv',
'.ogx', '.rm', '.rmvb', '.tod', '.tp', '.ts', '.tts',
'.uvu', '.video', '.vob', '.wm', '.wmv', '.wmx', '.wvx')
AUDIO_EXTENSIONS = ('.m3u', '.m3u8', '.au', '.snd', '.mp3', '.mp2', '.aif',
'.aifc', '.aiff', '.ra', '.wav', '.mpa', '.aa', '.aac',
'.aax', '.ac3', '.adt', '.adts', '.ape', '.ec3', '.flac',
'.lpcm', '.m4b', '.m4p', '.m4r', '.mid', '.midi', '.mka',
'.mpc', '.oga', '.ogg', '.opus', '.pls', '.rmi', '.tak',
'.wave', '.wax', '.weba', '.wma', '.wv')
IMAGE_EXTENSIONS = ('.bmp', '.gif', '.ief', '.jpg', '.jpe', '.jpeg', '.png',
'.svg', '.tiff', '.tif', '.ico', '.ras', '.pnm', '.pbm',
'.pgm', '.ppm', '.rgb', '.xbm', '.xpm', '.xwd', '.3fr',
'.ari', '.arw', '.bay', '.cap', '.cb7', '.cbr', '.cbz',
'.cr2', '.cr3', '.crw', '.dcr', '.dcs', '.dds', '.dib',
'.dng', '.drf', '.eip', '.emf', '.erf', '.fff', '.iiq',
'.jfif', '.jxr', '.k25', '.kdc', '.mef', '.mos', '.mrw',
'.nef', '.nrw', '.orf', '.ori', '.pef', '.ptx', '.pxn',
'.raf', '.raw', '.rw2', '.rwl', '.sr2', '.srw', '.wdp',
'.webp', '.wmf', '.x3f')
ALL_MEDIA_EXTENSIONS = VIDEO_EXTENSIONS + AUDIO_EXTENSIONS + IMAGE_EXTENSIONS
# ---------------------
class SetProgressContext(int):
NONE = 0
RESTORE = 1
RESTART = 2
RESET_TO_MIN = 3
RESET_TO_MAX = 4
NAVIGATION_RELATIVE = 5
NAVIGATION_EXACT = 6
SCRUB = 7
class UndoType(int):
RENAME = 0
# ---------------------
OUTPUT_TEXTBOX_TOOLTIP_SUFFIX = '''
---
Enter: Rename this file to whatever you've entered.
Shift + Enter: Open the entered file if it exists.
Tab: View files similar to your entry (*/? supported).'''
TRIM_BUTTON_TOOLTIP_BASE = '''Click to set the starting position of a trim/
the point where the intro fade will stop.
Currently in ?mode mode.
Right-click for more options.'''
MARK_DELETED_TOOLTIP_BASE = '''Mark media for future deletion.
?count are currently marked for deletion.
Shortcuts:
Ctrl + click: Immediately delete current media.
Shift + click: Show deletion-confirmation prompt.
Right-click for more options. Deletion-confirmation
prompt is shown on exit if any files are marked.'''
SNAPSHOT_TOOLTIP_BASE = '''Takes a snapshot of the current media at its current position.
Click: ?click
Ctrl + click: ?ctrlclick
Shift + click: ?shiftclick
Alt + click: ?altclick
Right-click for more options.'''
SIZE_DIALOG_DIMENSIONS_LABEL_BASE = '''If width AND height are 0,
the native resolution is used
(?resolution).
If width OR height are 0,
native aspect-ratio is used.
Supports percentages, such as 50%.'''
ZOOM_FORCE_MINIMUM_TOOLTIP_BASE = '''If checked, and the minimum zoom factor cannot actually be reached
(i.e. the media was very small to begin with), the minimum zoom will
be relative to the media's size instead of the window's size.
(i.e. ?valuex the current media size instead of ?valuex the current window size)'''
# ---------------------
if IS_COMPILED:
FFMPEG = f'{CWD}{_sep}plugins{_sep}ffmpeg{_sep}ffmpeg'
FFPROBE = f'{CWD}{_sep}plugins{_sep}ffmpeg{_sep}ffprobe'
else:
folder = 'ffmpeg-windows' if IS_WINDOWS else 'ffmpeg-unix'
FFMPEG = f'{CWD}{_sep}executable{_sep}include{_sep}{folder}{_sep}ffmpeg'
FFPROBE = f'{CWD}{_sep}executable{_sep}include{_sep}{folder}{_sep}ffprobe'
def verify_ffmpeg(self, warning: bool = True, force_warning: bool = False) -> str:
''' Checks, sets, and returns constants.FFMPEG if it's present in the
bin/PyQt/root folders, or the user's PATH variable. If not, FFMPEG is
set to ''. If `warning` is True, a popup is displayed unless the user
clicks 'Cancel' on one of the popups. If `force_warning` is True and
constants.FFMPEG is missing, a popup is displayed no matter what. '''
global FFMPEG
expected_path = (FFMPEG + '.exe') if IS_WINDOWS else FFMPEG
filename = 'ffmpeg.exe' if IS_WINDOWS else 'ffmpeg'
if not os.path.exists(expected_path): # FFmpeg not in expected path
if os.path.exists(filename):
FFMPEG = os.path.realpath(filename) # ffmpeg.exe exists in root
if IS_WINDOWS: # strip '.exe'
FFMPEG = FFMPEG[:-4]
else:
import util
FFMPEG = util.get_from_PATH(filename)
if FFMPEG == '':
import config
if config.cfg.ffmpegwarningignored and not force_warning:
import logging
warn = logging.getLogger('constants.py').warning
warn('(!) FFmpeg not detected. Assuming it is still accessible.')
elif warning or force_warning:
_display_ffmpeg_warning(self, forced=force_warning)
return FFMPEG
def verify_ffprobe(self, warning: bool = True) -> str:
''' Checks, sets, and returns constants.FFPROBE if it's present in the
bin/PyQt/root folders, or the user's PATH variable. If not, FFPROBE
is set to ''. If `warning` is True and constants.FFPROBE is missing,
a popup is displayed (no matter what). '''
global FFPROBE
if not self.dialog_settings.checkFFprobe.isChecked():
import logging
logging.getLogger('constants.py').info('FFprobe is disabled.')
FFPROBE = ''
else:
expected_path = (FFPROBE + '.exe') if IS_WINDOWS else FFPROBE
filename = 'ffprobe.exe' if IS_WINDOWS else 'ffprobe'
if not os.path.exists(expected_path): # FFprobe not in expected path
if os.path.exists(filename):
FFPROBE = os.path.realpath(filename) # ffprobe.exe exists in root
if IS_WINDOWS: # strip '.exe'
FFPROBE = FFPROBE[:-4]
else:
import util
FFPROBE = util.get_from_PATH(filename)
if FFPROBE == '' and warning:
_display_ffprobe_warning(self)
return FFPROBE
def _display_ffmpeg_warning(self, forced: bool = True) -> None:
import logging
from PyQt5.QtWidgets import QMessageBox
dir_name = 'plugins' if IS_COMPILED else 'executable\\include'
warning_text = '.' if forced else ', or click\n"Cancel" to stop receiving this warning.'
popup_text = \
f'''FFmpeg was not detected in the {dir_name} folder, your install folder,
or your system PATH variable. FFmpeg is used for editing.
Without it, editing features will not function. For Windows
users, it should have been included with your download.
If it wasn't, download the FFmpeg essentials below{warning_text}'''
popup_text_informative = '<a href=https://ffmpeg.org/download.html>https://ffmpeg.org/download.html</a>'
if not forced and qthelpers.getPopupOkCancel(
title='FFmpeg not detected',
text=popup_text,
textInformative=popup_text_informative,
icon=QMessageBox.Warning,
**self.get_popup_location()
).exec() == QMessageBox.Cancel:
import config
config.cfg.ffmpegwarningignored = True
logging.getLogger('constants.py').warning('FFmpeg not detected. Current FFMPEG constant: ' + FFMPEG)
def _display_ffprobe_warning(self) -> None:
import logging
from PyQt5.QtWidgets import QMessageBox
dir_name = 'plugins' if IS_COMPILED else 'executable\\include'
popup_text = \
f'''FFprobe was not detected in the {dir_name} folder, your install folder, or
your system PATH variable. FFprobe is used for parsing media files,
with VLC's less stable parsing used as a backup.
FFprobe is not required, but recommended. Click "Cancel" to
disable FFprobe, or "OK" to leave FFprobe enabled. For Windows
users, FFprobe should have been included with your download.
If it wasn't, download the FFmpeg essentials below.'''
popup_text_informative = '<a href=https://ffmpeg.org/download.html>https://ffmpeg.org/download.html</a>'
if qthelpers.getPopupOkCancel(
title='FFprobe not detected',
text=popup_text,
textInformative=popup_text_informative,
icon=QMessageBox.Warning,
**self.get_popup_location()
).exec() == QMessageBox.Cancel:
self.dialog_settings.checkFFprobe.setChecked(False)
logging.getLogger('constants.py').warning('FFprobe not detected. Current FFPROBE constant: ' + FFPROBE)