-
Notifications
You must be signed in to change notification settings - Fork 8
/
fs.py
218 lines (141 loc) · 5.13 KB
/
fs.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
# -*- coding: utf-8 -*-
import os
from time import sleep
import threading
from PyQt5.QtCore import QObject, pyqtSignal, pyqtSlot
from ffmpeg import Ffmpeg
from folder_list import Folders
import files_list
class Fs(QObject):
def __init__(self):
QObject.__init__(self)
self.app_running = True
self.ff = Ffmpeg()
self.folders = set(Folders)
self.files = files_list.Files
self.filesPrevCount = 0
self.now_crawling = True
self.prop = 0
self.has_booted = False
self._sub_files = []
self._prep_file = ""
self.prep_file_index = 0
self._prep_folder = ""
self._supported_ext = ('.mp3', '.aac', '.wav', '.m4a', '.ogg')
startUp = pyqtSignal(list, arguments=['bootUp'])
called = pyqtSignal(list, arguments=['callToPlay'])
propertyChanged = pyqtSignal(list, arguments=['propertyNotifier'])
endOfPropertyChange = pyqtSignal(list, arguments=['endPropertyChange'])
propertyEnd = pyqtSignal(list, arguments=['propertyEnded'])
@pyqtSlot()
def bootUp(self):
# send the files
self.propertyNotify(self.files)
self.startUp.emit(self.files)
def propertyNotify(self, prop):
self.prop = prop
propNoti = threading.Thread(target = self._propertyNotify)
propNoti.start()
def propertyNotifier(self, result):
self.propertyChanged.emit(result)
def _propertyNotify(self):
while self.app_running and self.now_crawling:
sleep(.3)
count = len(self.prop)
if count > self.filesPrevCount:
self.filesPrevCount = count
self.propertyNotifier([count, self.prop])
def endPropertyChange(self):
sleep(1)
count = len(self.prop)
result = [count, '']
# emit the end of property
self.endOfPropertyChange.emit(result)
def endProperty(self):
self.now_crawling = False
self.endPropertyChange()
endProp = threading.Thread( target = self._endProperty )
endProp.start()
def _endProperty(self):
sleep(15)
self.prop = 0
self.propertyEnded()
def propertyEnded(self):
result = []
self.propertyEnd.emit(result)
def prepare(self, file):
# start thred
#_prepare()
# call _prepare
self._prep_file = file.replace("\\", "/")
prep_thread = threading.Thread( target = self._prepare )
prep_thread.start()
def _prepare(self):
# do the job
splits = os.path.split(self._prep_file)
self._prep_folder = splits[0]
self.subs_prep(self._prep_folder)
self._ffjob(self._prep_file)
self.callToPlay()
def callToPlay(self):
index = self.prep_file_index
lists = [self._prep_file, self.files[index]['format_name'], index ]
self.called.emit(lists)
def subs_prep(self, folder):
# _subs_preb()
sub_preb = threading.Thread( target = self._subs_preb )
sub_preb.start()
def _subs_preb(self):
# check if folder has been scanned before
if self._prep_folder not in self.folders:
self.now_crawling = True
self.folders.add(self._prep_folder)
else:
self.now_crawling = False
return
files = self._list_dir(self._prep_folder)
files.remove(self._prep_file)
for a in files:
tags = self.ff.probe(a)
if tags not in self.files:
self.files.append(tags)
self.endProperty()
def ffjob(self, file):
self._ffjob(file)
def _ffjob(self, file):
if self.app_running:
# check if app is running
if not self.app_running:
return False
info = self.ff.probe(file)
# check if app is running
if not self.app_running:
return False
self.ff.convert(file, info['format_name'])
# check if app is running
if not self.app_running:
return False
if info not in self.files:
self.files.append(info)
self.prep_file_index = self.files.index(info)
def _list_dir(self, directory):
sleep(.3)
self._search(directory)
return self._sub_files
def _is_dir(self, entry):
try:
os.listdir(entry)
self._search(entry)
return True
except:
return False
def _search(self, directory):
list_dir = os.listdir(directory)
for entry in list_dir:
path = directory + "/" + entry
if self._is_dir(path):
pass
else:
split = os.path.splitext(entry)
if split[1] in self._supported_ext:
self._sub_files.append(path)