Skip to content

Commit 1d4246b

Browse files
committed
Finalize package.
1 parent 662d74d commit 1d4246b

File tree

3 files changed

+82
-124
lines changed

3 files changed

+82
-124
lines changed

src/metadata_remover/__main__.py

Lines changed: 39 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
#flag=imp
22

3-
from metadata_remover import commons
4-
from metadata_remover import mrt
3+
from metadata_remover.commons import cls, exiftool, wait
4+
from metadata_remover.mrt import bulk, bulk1, singly, meta
55

66
import os
77
from shutil import move,copy
88

9-
# Clearscreen
10-
if platform.system().lower()=='windows':
11-
os.system('cls')
12-
else:
13-
os.system('clear')
14-
159
# Display menu
10+
cls()
1611
print('''
1712
\n |------ Metadata Removal Tool ------|\n
1813
1)Remove Metadata from a image.
@@ -26,49 +21,40 @@
2621

2722
# Take and parse input
2823
x=input('\n Enter command(1,2,3,4,5,6 or 7):')
29-
if x=='1':
30-
file=input('\n Enter image name:')
31-
singly(file,'i')
32-
exit()
33-
elif x=='2':
34-
file=input('\n Enter Video name:')
35-
singly(file,'v')
36-
exit()
37-
elif x=='3':
38-
file=input('\n Enter Audio File:')
39-
y=copy(file,'MRT')
40-
os.chdir('MRT')
41-
os.system('py mat2.py '+file)
42-
y=move(file.split('.')[0]+'.cleaned.'+file.split('.')[1],'..')
43-
os.remove(file)
44-
os.chdir('..')
45-
exit()
46-
elif x == '4':
47-
file=input('\n Enter Torrent File:')
48-
y=copy(file,'MRT')
49-
os.chdir('MRT')
50-
os.system('py mat2.py '+file)
51-
y=move(file.split('.')[0]+'.cleaned.'+file.split('.')[1],'..')
52-
os.remove(file)
53-
os.chdir('..')
54-
exit()
55-
elif x=='5':
56-
bulk()
57-
exit()
58-
elif x=='6':
59-
bulk1()
60-
exit()
61-
elif x=='7':
62-
exiftool()
63-
rb=input(' Enter Filename:')
64-
if os.path.exists(rb)==False:
65-
print('\n File Not Found!\n')
24+
match x:
25+
case '1':
26+
file=input('\n Enter image name:')
27+
singly(file,'i')
28+
case '2':
29+
file=input('\n Enter Video name:')
30+
singly(file,'v')
31+
case '3':
32+
file=input('\n Enter Audio File:')
33+
y=copy(file,'MRT')
34+
os.chdir('MRT')
35+
os.system('py mat2.py '+file)
36+
y=move(file.split('.')[0]+'.cleaned.'+file.split('.')[1],'..')
37+
os.remove(file)
38+
os.chdir('..')
39+
case '4':
40+
file=input('\n Enter Torrent File:')
41+
y=copy(file,'MRT')
42+
os.chdir('MRT')
43+
os.system('py mat2.py '+file)
44+
y=move(file.split('.')[0]+'.cleaned.'+file.split('.')[1],'..')
45+
os.remove(file)
46+
os.chdir('..')
47+
case '5':
48+
bulk()
49+
case '6':
50+
bulk1()
51+
case '7':
52+
exiftool()
53+
rb=input(' Enter Filename:')
54+
if os.path.exists(rb)==False:
55+
print('\n File Not Found!\n')
56+
wait()
57+
exit(0)
58+
meta(rb)
6659
wait()
67-
exit(0)
68-
meta(rb)
69-
wait()
70-
exit()
71-
elif x.lower()=='mm' or x.lower()=='c' or x.lower()=='close':
72-
exit()
73-
else:
74-
exit()
60+
exit()

src/metadata_remover/commons.py

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,9 @@
55
It contains necessary std libraries and basic functions for its users.
66
'''
77

8-
try:
9-
import hashlib
10-
import time
11-
import platform
12-
import os
13-
import getpass
14-
import webbrowser
15-
16-
except ImportError:
17-
print('Critical Error: Necessary Python Modules are missing!')
18-
print('Commons module couldnot satisfy all the dependencies!')
19-
x=input('\nPress any key to exit...')
20-
exit()
8+
import platform
9+
import os
10+
import webbrowser
2111

2212
# Deletes file after checking if it exists or not.
2313
def r(f):
@@ -26,10 +16,10 @@ def r(f):
2616

2717
# Function to open website if prerequisite software is not found in PC.
2818
def detect(cmd,web,snam,pkg):
19+
cls()
2920

30-
if platform.system().lower()=='windows':
21+
if sys() =='windows':
3122
if os.system(cmd+'>chk')!=0:
32-
os.system('cls')
3323
print('\nError: '+pkg+' is not detected!')
3424
print('\nPlease wait opening '+snam +' website in your browser!\nYou Have to download and install it.\n')
3525
webbrowser.open(web)
@@ -38,8 +28,7 @@ def detect(cmd,web,snam,pkg):
3828
exit()
3929

4030
else:
41-
if os.system(cmd+'>chk')!=0:
42-
os.system('clear')
31+
if os.system(cmd+'>chk')!=0:
4332
print('\nError:'+pkg+' is not detected!\n Please install The package to continue.')
4433
x=input('\nPress any key to exit...')
4534
r('chk')
@@ -109,18 +98,10 @@ def bcopy(file,file1):
10998
f.close()
11099
s.close()
111100

112-
# Clearscreen
101+
# Clear screen
113102
def cls():
114-
if platform.system().lower()=='windows':
115-
os.system('cls')
116-
else:
117-
os.system('clear')
118-
119-
120-
121-
103+
os.system('cls') if sys() == 'windows' else os.system('clear')
122104

123-
124-
125-
126-
105+
# Get system name
106+
def sys():
107+
return "windows" if platform.system().lower() == 'windows' else "notwin"

src/metadata_remover/mrt.py

Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#flag=imp
22

33
'''
4-
An Cross-platform opensource Metadata Remover using exiftool and ffmpeg to sanitize your images before posting on internet.
4+
A Cross-platform opensource Metadata Remover using exiftool and ffmpeg to sanitize your images before posting on internet.
55
'''
66

7+
import os, time
8+
import metadata_remover.commons as c
9+
710
# Function to write given message to file named log in append mode.
811
def w(msg,file='log'):
912
with open(file,'a+') as f:
@@ -12,7 +15,7 @@ def w(msg,file='log'):
1215
# Function to read and display metadata of a file.
1316
def meta(file):
1417
os.system('exiftool '+file+' >meta.txt')
15-
display('meta.txt')
18+
c.c.display('meta.txt')
1619
os.remove('meta.txt')
1720

1821
# Function to rename exiftool(-k).exe as exiftool.exe in windows.
@@ -30,7 +33,7 @@ def img(x):
3033

3134
# Function to remove metadata from video file.
3235
def vid(x):
33-
ffmpeg()
36+
c.ffmpeg()
3437
count=-1
3538
for i in x :
3639
count+=1
@@ -40,18 +43,15 @@ def vid(x):
4043
ext=x[count:]
4144
y=file+'_clean'+ext
4245
os.system('ffmpeg -i '+x+' -map_metadata -1 -c:v copy -c:a copy '+y)
43-
if platform.system().lower()=='windows':
44-
os.system('cls')
45-
else:
46-
os.system('clear')
46+
c.cls()
4747
os.system('exiftool '+y+'>output.txt')
48-
copy('output.txt','output_log.txt')
48+
c.copy('output.txt','output_log.txt')
4949

5050
# Function to remove metadata from single image or video file. It uses img() and vid() internally.
5151
# x denotes file given as input , y can be either i for images or v for videos , mode can be n for normal mode, or b for bulk processing mode.
5252
def singly(x,y,mode='n'):
5353
autoexif()
54-
exiftool()
54+
c.exiftool()
5555
flag=0
5656

5757
if os.path.exists(x)==False:
@@ -65,19 +65,19 @@ def singly(x,y,mode='n'):
6565
for i in v:
6666
if x.lower().endswith(i):
6767
os.system("exiftool "+x+">input.txt")
68-
copy('input.txt','input_log.txt')
68+
c.copy('input.txt','input_log.txt')
6969
img(x)
7070
flag=1
7171
os.system("exiftool "+x+">output.txt")
72-
copy('output.txt','output_log.txt')
72+
c.copy('output.txt','output_log.txt')
7373

7474
elif y.lower()=='v':
75-
ffmpeg()
75+
c.ffmpeg()
7676
v=('.mp4','.mov','.webm','.ogv','.flv','.wmv','.avi','.mkv','.vob','.ogg','.3gp')
7777
for i in v:
7878
if x.lower().endswith(i):
7979
os.system("exiftool "+x+">input.txt")
80-
copy('input.txt','input_log.txt')
80+
c.copy('input.txt','input_log.txt')
8181
vid(x)
8282
flag=1
8383

@@ -89,15 +89,12 @@ def singly(x,y,mode='n'):
8989

9090
if flag==0:
9191
print("\n Invalid File for processing!")
92-
wait()
92+
c.wait()
9393
exit()
9494

9595
if ((os.path.exists('input.txt')==True)and(os.path.exists('output.txt')==True)):
9696
if os.path.getsize('output.txt')==0:
97-
if platform.system().lower()=='windows':
98-
os.system('cls')
99-
else:
100-
os.system('clear')
97+
c.cls()
10198
print(' Error Processing File!')
10299
elif os.path.getsize('input.txt')>os.path.getsize('output.txt'):
103100
print(x+': Metadata removed successfully!')
@@ -113,60 +110,54 @@ def singly(x,y,mode='n'):
113110
os.remove('output.txt')
114111

115112
if mode=='n':
116-
wait()
113+
c.wait()
117114
if os.path.exists('log'):
118115
os.remove('log')
119116

120117
# Function to remove metadata of all images from folder.
121118
def bulk():
122-
start()
119+
c.start()
123120
loc=input(' Enter Folder:')
124-
if platform.system().lower()=='windows':
121+
if c.sys() =='windows':
125122
if os.path.exists('exiftool.exe'):
126-
bcopy('exiftool.exe',loc+'\\exiftool.exe')
123+
c.copy('exiftool.exe',loc+'\\exiftool.exe')
127124
os.chdir(loc)
128125
for i in os.listdir():
129126
singly(i,'i','b')
130-
if platform.system().lower()=='windows':
131-
os.system('cls')
132-
else:
133-
os.system('clear')
127+
c.cls()
134128

135129
print('\nOutput\n')
136-
display('log')
130+
c.display('log')
137131
if os.path.exists('log'):
138132
os.remove('log')
139133
else:
140134
print('No Image Files Detected!')
141135
print('Done')
142-
wait()
143-
end()
136+
c.wait()
137+
c.end()
144138

145139
# Function to remove metadata of all videos from folder.
146140
def bulk1():
147-
start()
141+
c.start()
148142
loc=input(' Enter Folder:')
149-
if platform.system().lower()=='windows':
143+
if c.sys() =='windows':
150144
if os.path.exists('exiftool.exe'):
151-
bcopy('exiftool.exe',loc+'\\exiftool.exe')
145+
c.copy('exiftool.exe',loc+'\\exiftool.exe')
152146
if os.path.exists('ffmpeg.exe'):
153-
bcopy('ffmpeg.exe',loc+'\\ffmpeg.exe')
147+
c.copy('ffmpeg.exe',loc+'\\ffmpeg.exe')
154148
os.chdir(loc)
155149
for i in os.listdir():
156150
singly(i,'v','b')
157-
if platform.system().lower()=='windows':
158-
os.system('cls')
159-
else:
160-
os.system('clear')
151+
c.cls()
161152
print('\nOutput\n')
162-
display('log')
153+
c.display('log')
163154
if os.path.exists('log'):
164155
os.remove('log')
165156
else:
166157
print('No Video Files Detected!')
167-
wait()
168-
end()
158+
c.wait()
159+
c.end()
169160

170161
if __name__=='__main__':
171162
print('\n |----- MRT module stable release version 0.2.4 ----|')
172-
wait()
163+
c.wait()

0 commit comments

Comments
 (0)