net wheel bug, onlyproxy function and more...
This commit is contained in:
@@ -4,5 +4,6 @@
|
|||||||
"listen_ip": "127.0.0.1",
|
"listen_ip": "127.0.0.1",
|
||||||
"listen_num": 39,
|
"listen_num": 39,
|
||||||
"buffsize": 4096,
|
"buffsize": 4096,
|
||||||
"proxy": false
|
"proxy": false,
|
||||||
|
"onlyproxy": false
|
||||||
}
|
}
|
||||||
4
mswp.py
4
mswp.py
@@ -30,7 +30,7 @@ BUFFSIZE = jsondata.try_to_read_jsondata('buffsize', 4096)
|
|||||||
ID = jsondata.try_to_read_jsondata('id', 'unknown_id')
|
ID = jsondata.try_to_read_jsondata('id', 'unknown_id')
|
||||||
class Datapack:
|
class Datapack:
|
||||||
def __init__(self, method='post', app='all', version='msw/0.1', head=None, body=b'',
|
def __init__(self, method='post', app='all', version='msw/0.1', head=None, body=b'',
|
||||||
file=None, gen_flag=True):
|
file=None, gen_flag=True, delete=False):
|
||||||
self.id = ID
|
self.id = ID
|
||||||
if head is None:
|
if head is None:
|
||||||
head = {}
|
head = {}
|
||||||
@@ -38,6 +38,7 @@ class Datapack:
|
|||||||
self.head['id'] = self.id
|
self.head['id'] = self.id
|
||||||
self.method = method
|
self.method = method
|
||||||
self.file = file
|
self.file = file
|
||||||
|
self.delete = delete
|
||||||
self.app = app
|
self.app = app
|
||||||
self.version = version
|
self.version = version
|
||||||
self.body = body
|
self.body = body
|
||||||
@@ -93,6 +94,7 @@ class Datapack:
|
|||||||
ndp = copy.deepcopy(self)
|
ndp = copy.deepcopy(self)
|
||||||
ndp.app = ndp.head['from']
|
ndp.app = ndp.head['from']
|
||||||
ndp.method = 'reply'
|
ndp.method = 'reply'
|
||||||
|
ndp.delete = False
|
||||||
if not self.head['id'] == ID: # net package
|
if not self.head['id'] == ID: # net package
|
||||||
ndp.head['to'] = self.head['id']
|
ndp.head['to'] = self.head['id']
|
||||||
ndp.head['id'] = ID
|
ndp.head['id'] = ID
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ class Ffmpeg_controller:
|
|||||||
self.server = None
|
self.server = None
|
||||||
self.conver_task_queue = queue.Queue()
|
self.conver_task_queue = queue.Queue()
|
||||||
self.org_filename = None
|
self.org_filename = None
|
||||||
|
self.concat = True
|
||||||
|
|
||||||
self.conver_task_thread = threading.Thread(target=self.conver_task_func, args=())
|
self.conver_task_thread = threading.Thread(target=self.conver_task_func, args=())
|
||||||
self.conver_task_thread.start()
|
self.conver_task_thread.start()
|
||||||
@@ -39,7 +40,18 @@ class Ffmpeg_controller:
|
|||||||
dp = receive_queue.get()
|
dp = receive_queue.get()
|
||||||
|
|
||||||
if dp.method == 'post' and dp.body == b'start': # config ffmpeg is server or client
|
if dp.method == 'post' and dp.body == b'start': # config ffmpeg is server or client
|
||||||
|
if dp.head.get('concat'):
|
||||||
|
if dp.head['concat'] == 'true':
|
||||||
|
self.concat = True
|
||||||
|
elif dp.head['concat'] == 'false':
|
||||||
|
self.concat = False
|
||||||
|
else:
|
||||||
|
print('unknown concat value')
|
||||||
|
continue
|
||||||
|
|
||||||
self.org_filename = dp.head['filename']
|
self.org_filename = dp.head['filename']
|
||||||
|
|
||||||
|
if self.concat:
|
||||||
ndp = dp.reply()
|
ndp = dp.reply()
|
||||||
ndp.body = 'Spliting file %s' % dp.head['filename']
|
ndp.body = 'Spliting file %s' % dp.head['filename']
|
||||||
ndp.body = ndp.body.encode()
|
ndp.body = ndp.body.encode()
|
||||||
@@ -52,6 +64,7 @@ class Ffmpeg_controller:
|
|||||||
|
|
||||||
self.run_as_server()
|
self.run_as_server()
|
||||||
|
|
||||||
|
if self.concat:
|
||||||
# concat all file
|
# concat all file
|
||||||
filelist = os.listdir('res/ffmpeg_finished')
|
filelist = os.listdir('res/ffmpeg_finished')
|
||||||
if 'filelist.txt' in filelist:
|
if 'filelist.txt' in filelist:
|
||||||
@@ -63,7 +76,11 @@ class Ffmpeg_controller:
|
|||||||
subprocess.check_output('ffmpeg -f concat -i res/ffmpeg_finished/filelist.txt \
|
subprocess.check_output('ffmpeg -f concat -i res/ffmpeg_finished/filelist.txt \
|
||||||
-c copy -y ' + object_filename, shell=True)
|
-c copy -y ' + object_filename, shell=True)
|
||||||
|
|
||||||
print('All process finished at ' + object_filename)
|
for file in filelist:
|
||||||
|
os.remove('res/ffmpeg_finished/' + file)
|
||||||
|
os.remove('res/ffmpeg_finished/filelist.txt')
|
||||||
|
|
||||||
|
print('All process finished')
|
||||||
|
|
||||||
elif dp.method == 'post' and dp.body == b'enable': # clinet mode
|
elif dp.method == 'post' and dp.body == b'enable': # clinet mode
|
||||||
self.status = 1
|
self.status = 1
|
||||||
@@ -176,10 +193,13 @@ class Ffmpeg_controller:
|
|||||||
os.system('ffmpeg -i ' + filename + ' -c:a libopus -ab 64k \
|
os.system('ffmpeg -i ' + filename + ' -c:a libopus -ab 64k \
|
||||||
-c:v libx265 -s 1280x720 -y ' + output_filename)
|
-c:v libx265 -s 1280x720 -y ' + output_filename)
|
||||||
|
|
||||||
|
os.remove(filename)
|
||||||
|
|
||||||
ndp = dp.reply()
|
ndp = dp.reply()
|
||||||
ndp.head['filename'] = output_filename
|
ndp.head['filename'] = output_filename
|
||||||
ndp.head['old_filename'] = filename
|
ndp.head['old_filename'] = filename
|
||||||
ndp.method = 'file'
|
ndp.method = 'file'
|
||||||
|
ndp.delete = True
|
||||||
send_queue.put(ndp)
|
send_queue.put(ndp)
|
||||||
|
|
||||||
self.send_request()
|
self.send_request()
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ receive_queue = receive_queues[__name__]
|
|||||||
BUFFSIZE = jsondata.try_to_read_jsondata('buffsize', 4096)
|
BUFFSIZE = jsondata.try_to_read_jsondata('buffsize', 4096)
|
||||||
ID = jsondata.try_to_read_jsondata('id', 'Unknown_ID')
|
ID = jsondata.try_to_read_jsondata('id', 'Unknown_ID')
|
||||||
RETRYSLEEP = 5
|
RETRYSLEEP = 5
|
||||||
|
MYPROXY = jsondata.try_to_read_jsondata('proxy', False)
|
||||||
|
ONLYPROXY = jsondata.try_to_read_jsondata('onlyproxy', False)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
network_controller = Network_controller()
|
network_controller = Network_controller()
|
||||||
@@ -23,6 +26,9 @@ def main():
|
|||||||
|
|
||||||
class Network_controller: # manage id and connection
|
class Network_controller: # manage id and connection
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
if ONLYPROXY and not MYPROXY:
|
||||||
|
print('config failed because you set onlyproxy true but proxy false')
|
||||||
|
return
|
||||||
self.send_queue = queue.Queue()
|
self.send_queue = queue.Queue()
|
||||||
self.id_dict = {}
|
self.id_dict = {}
|
||||||
self.lock = threading.Lock()
|
self.lock = threading.Lock()
|
||||||
@@ -153,6 +159,12 @@ class Network_controller: # manage id and connection
|
|||||||
ip, port = connection.conn.getpeername()
|
ip, port = connection.conn.getpeername()
|
||||||
port = int(connection.listen_port)
|
port = int(connection.listen_port)
|
||||||
connection_list.append((ip, port))
|
connection_list.append((ip, port))
|
||||||
|
for addr in self.conflist:
|
||||||
|
if not addr in connection_list:
|
||||||
|
connection_list.append(addr)
|
||||||
|
for addr in self.conflist_pass:
|
||||||
|
if not addr in connection_list:
|
||||||
|
connection_list.append(addr)
|
||||||
data_dict['mht'] = connection_list
|
data_dict['mht'] = connection_list
|
||||||
data_dict['proxy'] = self.proxydict
|
data_dict['proxy'] = self.proxydict
|
||||||
|
|
||||||
@@ -209,6 +221,13 @@ class Network_controller: # manage id and connection
|
|||||||
elif not to:
|
elif not to:
|
||||||
print('not to', dp)
|
print('not to', dp)
|
||||||
|
|
||||||
|
elif ONLYPROXY and not to == MYPROXY:
|
||||||
|
if dp.head['to']:
|
||||||
|
dp.head['to'] = to + dp.head['to']
|
||||||
|
else:
|
||||||
|
dp.head['to'] = to
|
||||||
|
self.send_to_id(MYPROXY, dp)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.send_to_id(to, dp)
|
self.send_to_id(to, dp)
|
||||||
|
|
||||||
@@ -349,7 +368,7 @@ class Connection:
|
|||||||
self.conn.close()
|
self.conn.close()
|
||||||
return
|
return
|
||||||
|
|
||||||
self.netowrk_controller.set_connection(self,)
|
self.netowrk_controller.set_connection(self)
|
||||||
|
|
||||||
self.thread_send = threading.Thread(target=self.send_func, args=(), daemon=True)
|
self.thread_send = threading.Thread(target=self.send_func, args=(), daemon=True)
|
||||||
self.thread_send.start()
|
self.thread_send.start()
|
||||||
@@ -467,6 +486,13 @@ class Connection:
|
|||||||
#print('you connect to your self')
|
#print('you connect to your self')
|
||||||
return 4, dp.head.get('flag')
|
return 4, dp.head.get('flag')
|
||||||
|
|
||||||
|
if ONLYPROXY and not self.id == MYPROXY: # refuce not proxy connection
|
||||||
|
return 5, dp.head.get('flag')
|
||||||
|
|
||||||
|
if dp.head.get('onlyuseproxy'):
|
||||||
|
if not dp.head['onlyuseproxy'] == ID:
|
||||||
|
return 6, dp.head.get('flag')
|
||||||
|
|
||||||
if not self.positive:
|
if not self.positive:
|
||||||
self.send_id()
|
self.send_id()
|
||||||
|
|
||||||
@@ -476,6 +502,8 @@ class Connection:
|
|||||||
def send_id(self):
|
def send_id(self):
|
||||||
dp = Datapack(head={'from': __name__})
|
dp = Datapack(head={'from': __name__})
|
||||||
dp.app = 'handshake'
|
dp.app = 'handshake'
|
||||||
|
if ONLYPROXY:
|
||||||
|
dp.head['onlyuseproxy'] = MYPROXY
|
||||||
dp.head['listen_port'] = str(jsondata.try_to_read_jsondata('listen_port', 3900))
|
dp.head['listen_port'] = str(jsondata.try_to_read_jsondata('listen_port', 3900))
|
||||||
dp.encode()
|
dp.encode()
|
||||||
self.conn.sendall(dp.encode_data)
|
self.conn.sendall(dp.encode_data)
|
||||||
@@ -497,8 +525,14 @@ class Connection:
|
|||||||
self.conn.sendall(data)
|
self.conn.sendall(data)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('Failed to send file %s %s: %s' % (dp.head['filename'], type(e), str(e)), dp)
|
print('Failed to send file %s %s: %s' % (dp.head['filename'], type(e), str(e)), dp)
|
||||||
|
if dp.head.get('to'):
|
||||||
|
dp.head['to'] = self.id + '&' + dp.head['to']
|
||||||
|
else:
|
||||||
|
dp.head['to'] = self.id
|
||||||
self.netowrk_controller.wheel_queue.put(dp)
|
self.netowrk_controller.wheel_queue.put(dp)
|
||||||
break
|
break
|
||||||
|
if dp.delete:
|
||||||
|
os.remove(dp.head['filename'])
|
||||||
print('Send file %s finished' % dp.head['filename'], dp)
|
print('Send file %s finished' % dp.head['filename'], dp)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user