-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
56 lines (49 loc) · 1.7 KB
/
main.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
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
#
# main.py for gtasa_usertrack_linker by shinrax2
import os
import sys
import winshell
from win32com.client import Dispatch
def createLnk(shell, path, target):
link = shell.CreateShortCut(path)
link.Targetpath = target
link.WorkingDirectory = os.path.dirname(target)
link.save()
def getfiles(dirpath):
f = []
for root, dirs, files in os.walk(dirpath):
for file in files:
if os.path.isfile(os.path.join(root, file)):
f.append(os.path.join(root, file))
f.sort(key=str.lower)
return f
def filterfiles(files):
filetypes = [".wav", ".ogg", ".mp3", ".wma"]
newfiles = []
for file in files:
for type in filetypes:
if file.endswith(type) == True:
newfiles.append(file)
break
newfiles.sort(key=str.lower)
return newfiles
dirs = sys.argv[1:]
for dir in dirs:
if os.path.isdir(dir) == True:
shell = Dispatch("WScript.Shell")
musicdir = dir
usertrackdir = os.path.join(os.path.join(os.environ["HOMEDRIVE"], os.environ["HOMEPATH"]), "Documents\GTA San Andreas User Files\\User Tracks")
print("scanning "+dir)
files = filterfiles(getfiles(musicdir))
print("found {0} matching files".format(len(files)))
print("creating .lnk files")
counter = 1
for file in files:
createLnk(shell, os.path.join(usertrackdir, os.path.basename(file)+"_"+str(counter)+"_.lnk"), file)
counter += 1
else:
print("skipping {0}. its not a directory".format(dir))
print("please provide a valid path to the music you want to use")
input("done. press enter to exit.")