Skip to content

Commit 05cdc9b

Browse files
committed
add useful_pieces folder
1 parent 1505708 commit 05cdc9b

18 files changed

+579
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,6 @@ coverage.xml
5252
# Sphinx documentation
5353
docs/_build/
5454

55+
**/auto_vote/**/p*[0-9].txt
56+
**/auto_vote/auto_*_db.*
57+
**/burn_calculator/config.ini

useful_pieces/BuildM3U/BuildM3U.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#coding=utf-8
2+
3+
import os, sys, random, re
4+
import os.path
5+
6+
def randstr(length):
7+
str = ""
8+
for i in range(length):
9+
str += random.choice("_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")
10+
return str
11+
12+
def newfname(filename):
13+
npattern = re.compile(r'(?<=_\[)\w{5}(?=\]$)')
14+
namelist = os.path.splitext(filename)
15+
mo = npattern.search(namelist[0])
16+
if mo:
17+
replacestr = randstr(5)
18+
while replacestr == mo.group():
19+
replacestr = randstr(5)
20+
return npattern.sub(replacestr, namelist[0]) + namelist[1]
21+
else:
22+
return namelist[0] + '_[' + randstr(5) + ']' + namelist[1]
23+
24+
def labelnameout(names):
25+
for i in range(len(names)):
26+
print(i+1, ':', names[i])
27+
28+
def getnameorder():
29+
nums = []
30+
instr = input('please input the order of newfiles: (1 - n):\n')
31+
p = re.compile(r'\D+')
32+
for numstr in p.split(instr):
33+
if numstr:
34+
nums.append(int(numstr) - 1)
35+
return nums
36+
37+
if __name__ == "__main__":
38+
extension = ['.mp3', '.wma', '.ogg', '.mpc', '.wav', '.wmv', '.mpg', '.avi']
39+
prefix = r'http://dl.getdropbox.com/u/2128104/blogplays/'
40+
fninm3u = []
41+
fnindir = []
42+
newfiles = []
43+
orders = []
44+
finalfiles = []
45+
46+
# fill fnindir and fninm3u
47+
fnindir = [fn for fn in os.listdir('.') if ((fn != 'playlist.wma') \
48+
and (os.path.splitext(fn)[1] in extension))]
49+
try:
50+
file = open('playlist.wma', 'r')
51+
for line in file:
52+
fname = os.path.split(line.strip())[1]
53+
if fname in fnindir:
54+
fninm3u.append(fname)
55+
file.close()
56+
except IOError:
57+
pass
58+
59+
# now we got fnindir and fninm3u
60+
newfiles = [fname for fname in fnindir if fname not in fninm3u]
61+
# print the new filenames and their label:
62+
if newfiles:
63+
labelnameout(newfiles)
64+
# get order of them
65+
orders = getnameorder()
66+
67+
# fill finalfiles
68+
for i in orders:
69+
finalfiles.append(newfiles[i])
70+
for fname in fninm3u:
71+
finalfiles.append(fname)
72+
73+
# rename and write to file
74+
file = open('playlist.wma', 'w')
75+
for fname in finalfiles:
76+
newname = newfname(fname)
77+
os.rename(fname, newname)
78+
file.write(prefix + newname + '\n')
79+
file.close()
80+

useful_pieces/BuildM3U/Next_www_123.456.789_[FXM36].ogg

Whitespace-only changes.

useful_pieces/BuildM3U/[Sound Horizon] - slkdug_[BTK9H].mp3

Whitespace-only changes.

useful_pieces/BuildM3U/ljljaaauum_[8XIT6].wma

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
http://dl.getdropbox.com/u/2128104/blogplays/[Sound Horizon] - slkdug_[BTK9H].mp3
2+
http://dl.getdropbox.com/u/2128104/blogplays/ljljaaauum_[8XIT6].wma
3+
http://dl.getdropbox.com/u/2128104/blogplays/Next_www_123.456.789_[FXM36].ogg
4+
http://dl.getdropbox.com/u/2128104/blogplays/tooooooooooooooooooooooooooooolong_[2WDCZ].wmv

useful_pieces/BuildM3U/readme.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
读取当前文件夹内的文件列表,并与 playlist.wma 中记录的列表比较,列出新文件及序号
2+
根据用户输入对新加文件进行排序
3+
在所有文件名后添加一个[6位]的随机字符串,并重命名所有文件
4+
根据前述顺序,将所有文件添加路径前缀,并写入 playlist.wma 文件

useful_pieces/BuildM3U/tooooooooooooooooooooooooooooolong_[2WDCZ].wmv

Whitespace-only changes.

useful_pieces/CleanSolutions.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#coding=cp936
2+
3+
import os
4+
from os.path import join,abspath,split,splitext,basename
5+
6+
def RemoveTree(path):
7+
if len(abspath(path)) < 40:
8+
return
9+
for root, dirs, files in os.walk(path, topdown=False):
10+
for name in files:
11+
os.remove(join(root,name))
12+
for name in dirs:
13+
os.rmdir(join(root,name))
14+
os.rmdir(path)
15+
16+
def CleanSolution(path,slnname):
17+
ClnFileExt = ['.ncb','.aps','.user','.ilk','.pdb']
18+
ClnFolder = ['debug','release']
19+
if not os.path.exists(join(path,slnname+".sln")):
20+
return
21+
for name in os.listdir(path):
22+
if (os.path.isfile(join(path,name)) and \
23+
splitext(name)[0] == slnname and \
24+
splitext(name)[1] in ClnFileExt):
25+
os.remove(join(path,name))
26+
for folder in ClnFolder:
27+
if os.path.exists(join(path,folder)):
28+
for file in os.listdir(join(path,folder)):
29+
if splitext(file)[1] in ClnFileExt:
30+
os.remove(join(path,folder,file))
31+
if not os.path.exists(join(path,slnname)):
32+
return
33+
for name in os.listdir(join(path,slnname)):
34+
if (os.path.isfile(join(path,slnname,name)) and \
35+
splitext(name)[1] in ClnFileExt):
36+
os.remove(join(path,slnname,name))
37+
for folder in ClnFolder:
38+
if os.path.exists(join(path,slnname,folder)):
39+
RemoveTree(join(path,slnname,folder))
40+
41+
def RemoveSlns(path):
42+
for root, dirs, files in os.walk(path):
43+
for name in files:
44+
if splitext(name)[1] == '.sln':
45+
#print "Cleaning",join(root,splitext(name)[0]),"..."
46+
print ("Cleaning", root, "...")
47+
dirs[:] = []
48+
CleanSolution(root,splitext(name)[0])
49+
50+
if __name__ == '__main__':
51+
RemoveSlns('.')
52+
os.system("pause")
53+
54+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#-------------------------------------------------------------------------------
2+
# Name: file name sorted as Windows Explorer
3+
# Purpose:
4+
#
5+
# Author: tadvent
6+
#
7+
# Created: 23/10/2013
8+
# Copyright: (c) tadvent 2013
9+
# Licence: <your licence>
10+
#-------------------------------------------------------------------------------
11+
12+
import re
13+
14+
def subfilename(filename):
15+
def padnum(matchObj):
16+
numstr = matchObj.group(0)
17+
return ' ' * (10 - len(numstr)) + numstr
18+
return re.sub(r"(\d+)", padnum, filename)
19+
20+
21+
def main():
22+
print(subfilename('a1b22c3'))
23+
print(subfilename('a1b2c3'))
24+
25+
if __name__ == '__main__':
26+
main()

0 commit comments

Comments
 (0)