-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslowpics.py
122 lines (111 loc) · 4.32 KB
/
slowpics.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
import subprocess, json, os, glob, datetime, sys, platform
from shutil import rmtree as rmdir
try:
import requests
from pyperclip import copy
from requests_toolbelt.multipart.encoder import MultipartEncoder, MultipartEncoderMonitor
from clint.textui.progress import Bar as ProgressBar
except:
print("ImportError!")
print('Please run "py -3 -m pip install requests clint requests-toolbelt pyperclip --upgrade" in the console.')
sys.exit()
#FFMPEG/FFPROBE
def pec(program):
'''
Program Exist Check
'''
try:
subprocess.call(program, stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL)
except FileNotFoundError:
print("You didn't install " + program + ". Please put in in PATH or in the current folder (or install it on unix) and restart the program...")
except:
raise
def gft(timed):
'''
Get Formatted Time
'''
#time.strftime('%H:%M:%S', time.gmtime(timed))
return str(datetime.timedelta(seconds=timed))
pec("ffmpeg")
pec("ffprobe")
#Screenshots
v1 = input("Input the Videoname of Video 1: ")
if os.path.basename(v1) == v1:
v1 = "./" + v1
v2 = input("Input the Videoname of Video 2: ")
if os.path.basename(v2) == v2:
v2 = "./" + v2
try:
duration = int(json.loads(subprocess.check_output(['ffprobe', '-i', v1, '-print_format', 'json', '-v', 'quiet', '-show_format', '-show_streams']))["format"]["duration"].split(".")[0])
except:
raise
print("Video Duration: "+str(duration)+" seconds")
sc = int(input("How many Screenshots should be taken: ")) + 1
sctime = round(duration/sc)
print("A screenshot will be taken every "+ str(sctime) +" seconds")
v1dir = "_Video_1"
v2dir = "_Video_2"
for i in [v1dir,v2dir]:
try:
os.mkdir(i)
except FileExistsError:
if input("The folder " + i + " already exists. Should it be removed (y/n): ").lower() == "y":
rmdir(i)
os.mkdir(i)
else:
sys.exit()
print()
#Making Screenshots
t = 0
for loli in range(1,sc):
t += sctime
subprocess.call(['ffmpeg','-loglevel','error','-ss',gft(t),'-i',v1,'-vframes','1','-q:v','1','./'+v1dir+'/screenshot_'+str(loli)+'.png'])
subprocess.call(['ffmpeg','-loglevel','error','-ss',gft(t),'-i',v2,'-vframes','1','-q:v','1','./'+v2dir+'/screenshot_'+str(loli)+'.png'])
print("Created Screenshot "+str(loli))
v1files = glob.glob(v1dir+"/*.png")
v2files = glob.glob(v2dir+"/*.png")
print()
def create_callback(files):
bar = ProgressBar(expected_size=files.len, filled_char='█')
def callback(monitor):
bar.show(monitor.bytes_read)
return callback
s = requests.session()
s.get("https://slowpics.org/comparison")
collName = input("Please input a name for your collection: ")
print('\nVideo 1: "'+os.path.basename(v1)+'"')
v1name = input("Please input a name for Video 1: ")
print('\nVideo 2: "'+os.path.basename(v2)+'"')
v2name = input("Please input a name for Video 2: ")
fields={
"collectionName":collName,
"public":"false",
}
for i in range(len(v1files)):
fields["comparisons["+str(i)+"].name"] = str(i+1)
fields["comparisons["+str(i)+"].images[0].name"] = v1name
fields["comparisons["+str(i)+"].images[0].file"] = (os.path.basename(v1files[i]),open(v1files[i],"rb"),"image/png")
fields["comparisons["+str(i)+"].images[1].name"] = v2name
fields["comparisons["+str(i)+"].images[1].file"] = (os.path.basename(v2files[i]),open(v2files[i],"rb"),"image/png")
files = MultipartEncoder(fields)
callback=create_callback(files)
monitor=MultipartEncoderMonitor(files, callback)
headers={
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7",
"Content-Length":str(files.len),
"Content-Type": monitor.content_type,
"Origin": "https://slowpics.org",
"Referer": "https://slowpics.org/comparison",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36",
"X-XSRF-TOKEN": s.cookies.get_dict()["XSRF-TOKEN"]
}
print('Uploading pictures to SlowPics with Collectionname "'+collName+'".')
ComparisonURL = s.post("https://slowpics.org/api/comparison", data=monitor, headers=headers)
print("URL: https://slowpics.org/comparison/"+ComparisonURL.text)
if platform.system() == "Windows":
copy("https://slowpics.org/comparison/"+ComparisonURL.text)
print("The URL has been copied to your clipboard.")