浏览代码

Initial threading implementation in worker, disable uploads temporarily

pull/3/head
tech234a 3 年前
父节点
当前提交
d1d10c458d
共有 1 个文件被更改,包括 65 次插入43 次删除
  1. +65
    -43
      worker.py

+ 65
- 43
worker.py 查看文件

@@ -2,6 +2,7 @@ import requests
from time import sleep from time import sleep
from os import mkdir from os import mkdir
from json import dumps from json import dumps
import threading


from shutil import make_archive, rmtree from shutil import make_archive, rmtree


@@ -11,6 +12,51 @@ from export import getsubs
WORKER_VERSION = 1 WORKER_VERSION = 1
SERVER_BASE_URL = "http://localhost:5000" SERVER_BASE_URL = "http://localhost:5000"


class batchthread(threading.Thread):
def run(self):
item = self.getName()
global recvids
global recchans
global recmixes
global recplayl

print("Video ID:", str(item).strip())
while True:
try:
info = getmetadata(str(item).strip())
break
except BaseException as e:
print(e)
print("Error in retrieving information, waiting 10 minutes")
sleep(600)

# Add any discovered videos
recvids.update(info[2])
recchans.update(info[3])
recmixes.update(info[4])
recplayl.update(info[5])

if info[0] or info[1]: # ccenabled or creditdata
mkdir("out/"+str(item).strip())

if info[1]: # creditdata
open("out/"+str(item).strip()+"/"+str(item).strip()+"_published_credits.json", "w").write(dumps(info[1]))

if info[0]: #ccenabled
while True:
gsres = False
try:
gsres = getsubs(str(item).strip())
except BaseException as e:
print(e)
if gsres:
break
else:
print("Error in retrieving subtitles, waiting 10 minutes")
sleep(600)

return True



# Get a worker ID # Get a worker ID
while True: while True:
@@ -57,41 +103,17 @@ while True:
# Process the batch # Process the batch
batchcontent = requests.get(batchinfo["content"]).text.split("\n") batchcontent = requests.get(batchinfo["content"]).text.split("\n")


for item in batchcontent:
print("Video ID:", str(item).strip())
while True:
try:
info = getmetadata(str(item).strip())
break
except BaseException as e:
print(e)
print("Error in retrieving information, waiting 10 minutes")
sleep(600)


# Add any discovered videos
recvids.update(info[2])
recchans.update(info[3])
recmixes.update(info[4])
recplayl.update(info[5])

if info[0] or info[1]: # ccenabled or creditdata
mkdir("out/"+str(item).strip())
threads = []
for item in batchcontent:
runthread = batchthread(name = item)
runthread.start()
threads.append(runthread)


if info[1]: # creditdata
open("out/"+str(item).strip()+"/"+str(item).strip()+"_published_credits.json", "w").write(dumps(info[1]))
for x in threads:
x.join()


if info[0]: #ccenabled
while True:
gsres = False
try:
gsres = getsubs(str(item).strip())
except BaseException as e:
print(e)
if gsres:
break
else:
print("Error in retrieving subtitles, waiting 10 minutes")
sleep(600)
#https://stackoverflow.com/a/11968881


# TODO: put the data somewhere... # TODO: put the data somewhere...
# TODO: put the discoveries somewhere... # TODO: put the discoveries somewhere...
@@ -99,16 +121,16 @@ while True:


make_archive("out.zip", "zip", "out") #check this make_archive("out.zip", "zip", "out") #check this


while True:
try:
uploadr = requests.post("https://transfersh.com/"+str(batchinfo["batchID"])+".zip", data=open("out.zip"))
if uploadr.status_code == 200:
resulturl = uploadr.text
break
except BaseException as e:
print(e)
print("Encountered error in uploading results... retrying in 10 minutes")
sleep(600)
# while True:
# try:
# uploadr = requests.post("https://transfersh.com/"+str(batchinfo["batchID"])+".zip", data=open("out.zip"))
# if uploadr.status_code == 200:
# resulturl = uploadr.text
# break
# except BaseException as e:
# print(e)
# print("Encountered error in uploading results... retrying in 10 minutes")
# sleep(600)


# Report the batch as complete (I can't think of a fail condition except for a worker exiting...) # Report the batch as complete (I can't think of a fail condition except for a worker exiting...)
# TODO: handle worker exit # TODO: handle worker exit
@@ -119,7 +141,7 @@ while True:
("batchID", batchinfo["batchID"]), ("batchID", batchinfo["batchID"]),
("randomKey", batchinfo["randomKey"]), ("randomKey", batchinfo["randomKey"]),
("status", "c"), ("status", "c"),
("resulturl", resulturl),
#("resulturl", resulturl),
) )
statusrequest = requests.get(SERVER_BASE_URL+"/worker/updateStatus", params=params) statusrequest = requests.get(SERVER_BASE_URL+"/worker/updateStatus", params=params)




正在加载...
取消
保存