Skip to content

Commit ba664d0

Browse files
authored
Add files via upload
1 parent 26b2b7f commit ba664d0

File tree

2 files changed

+121
-0
lines changed

2 files changed

+121
-0
lines changed

MusicListCreater_m3u8.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import os
2+
3+
def getInput():
4+
#Show options.
5+
#[0]=>Quit without alarming.
6+
#[1]=>Generate files(processOption()).
7+
#[2]=>Print usage then quit.
8+
print("\
9+
[0]Quit.(default)\n\
10+
[1]Generate lists\n\
11+
[2]Print usage and quit.\n")
12+
#Get option.
13+
user_input = input("Choose a option:")
14+
return user_input
15+
16+
def processOption():
17+
#Target parent_dir.
18+
parent_dir = input("Enter the targeted parent_dir:")
19+
#Change dir.
20+
if parent_dir != "":
21+
os.chdir(parent_dir)
22+
#Get content of parent_dir.
23+
parent_list = os.listdir()
24+
#Quit if empty.
25+
if parent_list == []:
26+
exit(1)
27+
28+
#Fetch names of sub_dir by iterating parent_dir.
29+
for sub_list_name in parent_list:
30+
#Neglect m3u8lists and scripts.
31+
if ("py" in sub_list_name) or ("m3u8" in sub_list_name):
32+
continue
33+
34+
#Create list for specific sub_dir.
35+
#This must be done first, having the list file be created in parent_dir.
36+
m3u8list = open("./%s.m3u8"%(sub_list_name), mode = "w")
37+
38+
#Change dir, ensuring that it is generating list for sub_dir.
39+
os.chdir(sub_list_name)
40+
#Fetch current dir.
41+
sub_list_dir = os.getcwd()
42+
43+
#Get names of music then sort, forming a sequence of A~Z, making it neat.
44+
sub_list = os.listdir()
45+
sub_list.sort()
46+
47+
#Iterate each name in sub_dir.
48+
for sub_list_file in sub_list:
49+
#Neglect the lyric files (*.lrc).
50+
if not (".mp3" in sub_list_file):
51+
continue
52+
#Add path to file.
53+
m3u8list.write(sub_list_dir+"/"+sub_list_file+"\n")
54+
#Save list.
55+
m3u8list.close()
56+
#Return to parent_dir, prepareing to make list for another sub_dir.
57+
os.chdir("..")
58+
59+
def chooseMethod(user_input):
60+
if user_input == "1":
61+
return processOption()
62+
if user_input == "2":
63+
#Usage attached here.
64+
return lambda: print("Usage:\n\
65+
##Structure ##Concept\n\
66+
parent_dir #parent_dir\n\
67+
|___sub_dir01 The dir containing all the files.\n\
68+
|___music01.mp3 Generated m3u8lists will be here,\n\
69+
|___music02.mp3 named after names the sub_dir bellow.\n\
70+
|___musicxx.mp3 #sub_dir\n\
71+
|___... Adequate classified ones.\n\
72+
|___sub_dir02\n\
73+
|___... ##Notice\n\
74+
|___sub_dirxx... Files will be neglected,\n\
75+
|___... except *.mp3 and *.flac.\n\
76+
|___sub_dir01.m3u8 Do not put files in the parent_dir,\n\
77+
|___sub_dir02.m3u8 except *.py and *.m3u8,\n\
78+
|___sub_dirxx.m3u8 while putting this script is recommended,\n\
79+
|___... for assigning parent_dir is no need. \n\
80+
")
81+
#Quit if anything except "1" or "2" is entered.
82+
else:
83+
return lambda: exit(0)
84+
85+
def main():
86+
#Get input from console.
87+
userInput = getInput()
88+
#Match function then execute.
89+
processingMethod = chooseMethod(userInput)
90+
processingMethod()
91+
exit(0)
92+
93+
main()

README.MD

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Usage
2+
## Structure
3+
>
4+
parent_dir\
5+
____sub_dir01\
6+
____ ____music01.mp3\
7+
____ ____music02.mp3\
8+
____ ____musicxx.mp3\
9+
____ ____...\
10+
____sub_dir02\
11+
____sub_dirxx...\
12+
____sub_dir01.m3u8\
13+
____sub_dir02.m3u8\
14+
____sub_dirxx.m3u8\
15+
____...
16+
17+
## Concept
18+
19+
### parent_dir
20+
The dir containing all the files.\
21+
Generated m3u8lists will be here, named after names the sub_dir bellow.
22+
23+
### sub_dir
24+
Adequate classified ones.
25+
26+
## Notice
27+
Files will be neglected, except *.mp3 and *.flac.\
28+
Do not put files in the parent_dir, except *.py and *.m3u8, while putting this script is recommended, for assigning parent_dir is no need.

0 commit comments

Comments
 (0)