This repository has been archived by the owner on Aug 23, 2021. It is now read-only.
forked from arnif/MoveIt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
moveit.py
executable file
·91 lines (69 loc) · 1.91 KB
/
moveit.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
#!/usr/bin/python
import re
import os
import json
import shutil
json_data = open('locations.json')
data = json.load(json_data)
path = '.'
files = os.listdir(path)
def main():
count = 0
for i in data['tvshows']:
show = data['tvshows'][count]['name']
goHere = data['tvshows'][count]['location']
reggie = createRegex(show)
# matcha dotid vid eitthvad i files arrayinu
for foo in files:
matchObj = re.search( reggie, foo, re.IGNORECASE)
if matchObj:
fileName = reggie + ".*(.mp4|.mkv|.avi)"
matchFile = re.search(fileName, foo, re.IGNORECASE)
if os.path.isdir(foo):
# get the file from the folder and remove it
print "FOLDER " + foo
os.chdir(foo)
isItHere = os.listdir(".")
rarFile = reggie + ".*(.rar)"
for l in isItHere:
rarMatch = re.search(rarFile, l, re.IGNORECASE)
matchObj = re.search(fileName, l, re.IGNORECASE)
if rarMatch:
print "UNRAR " + l
os.system("unrar x -e " + l)
os.system("rm " + l)
isItHere = os.listdir(".")
for b in isItHere:
matchObj = re.search(fileName, b, re.IGNORECASE)
if matchObj:
shutil.move(b, goHere)
os.chdir("../")
shutil.rmtree(foo)
elif matchObj:
print l + " goes " + goHere
shutil.move(l, goHere)
os.chdir("../")
shutil.rmtree(foo)
else:
if matchFile:
# move that shit (foo to goHere)
print foo + " goes " + goHere
shutil.move(foo, goHere)
count = count + 1
def createRegex(show):
arr = show.replace(show[:1],"^.")
arr = arr.split(" ")
first = arr[0] + ".*"
# fileEnd = ".*(.mp4|.mkv|.avi)"
fileEnd = ".*."
#replace rest first char with ".*."
newArr = []
for i in arr:
newString = i.replace(i[:1], ".*.")
newArr.append(newString)
newArr[0] = first
newArr.append(fileEnd)
returnThis = "".join(newArr)
return returnThis
main()
json_data.close()