annotate bandm3u/bandm3u.py @ 13:73fd89b46da4

bing4desktop-0.240206-3
author prymula <prymula76@outlook.com>
date Tue, 06 Feb 2024 17:47:04 +0100
parents dcd610585610
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
prymula <prymula76@outlook.com>
parents:
diff changeset
1 #!/usr/bin/env python3
prymula <prymula76@outlook.com>
parents:
diff changeset
2 # bandm3u- skrypt do tworzenia playlist m3u
prymula <prymula76@outlook.com>
parents:
diff changeset
3 # 16-02-2023
prymula <prymula76@outlook.com>
parents:
diff changeset
4 # Edytor: Geany
prymula <prymula76@outlook.com>
parents:
diff changeset
5 # (c) by P.R.P
prymula <prymula76@outlook.com>
parents:
diff changeset
6 # Mój pierwszy skrypt stworzony w Windows 11
prymula <prymula76@outlook.com>
parents:
diff changeset
7
prymula <prymula76@outlook.com>
parents:
diff changeset
8 import os
prymula <prymula76@outlook.com>
parents:
diff changeset
9
prymula <prymula76@outlook.com>
parents:
diff changeset
10 dir = os.getcwd()
prymula <prymula76@outlook.com>
parents:
diff changeset
11
prymula <prymula76@outlook.com>
parents:
diff changeset
12 data_files = []
prymula <prymula76@outlook.com>
parents:
diff changeset
13 data_out = []
prymula <prymula76@outlook.com>
parents:
diff changeset
14 extension = ['mp3', 'ogg', 'wav']
prymula <prymula76@outlook.com>
parents:
diff changeset
15
prymula <prymula76@outlook.com>
parents:
diff changeset
16 def check(string, sub_str):
prymula <prymula76@outlook.com>
parents:
diff changeset
17 if (string.find(sub_str) == -1):
prymula <prymula76@outlook.com>
parents:
diff changeset
18 return False
prymula <prymula76@outlook.com>
parents:
diff changeset
19 else:
prymula <prymula76@outlook.com>
parents:
diff changeset
20 return True
prymula <prymula76@outlook.com>
parents:
diff changeset
21
prymula <prymula76@outlook.com>
parents:
diff changeset
22 for data in os.listdir(dir):
prymula <prymula76@outlook.com>
parents:
diff changeset
23 for e in extension:
prymula <prymula76@outlook.com>
parents:
diff changeset
24 if check(data, e):
prymula <prymula76@outlook.com>
parents:
diff changeset
25 data_files += [os.path.basename(data)]
prymula <prymula76@outlook.com>
parents:
diff changeset
26
prymula <prymula76@outlook.com>
parents:
diff changeset
27 #print (data_files)
prymula <prymula76@outlook.com>
parents:
diff changeset
28 for n in range(100):
prymula <prymula76@outlook.com>
parents:
diff changeset
29 for f in data_files:
prymula <prymula76@outlook.com>
parents:
diff changeset
30 if n > 9:
prymula <prymula76@outlook.com>
parents:
diff changeset
31 nn = str(n)+" "
prymula <prymula76@outlook.com>
parents:
diff changeset
32 else:
prymula <prymula76@outlook.com>
parents:
diff changeset
33 nn = "0"+str(n)+" "
prymula <prymula76@outlook.com>
parents:
diff changeset
34 # sprawdza liczbę porządkową
prymula <prymula76@outlook.com>
parents:
diff changeset
35 if check(f, nn):
prymula <prymula76@outlook.com>
parents:
diff changeset
36 data_out.insert(n, f)
prymula <prymula76@outlook.com>
parents:
diff changeset
37
prymula <prymula76@outlook.com>
parents:
diff changeset
38
prymula <prymula76@outlook.com>
parents:
diff changeset
39 c = '\\'
prymula <prymula76@outlook.com>
parents:
diff changeset
40
prymula <prymula76@outlook.com>
parents:
diff changeset
41 # indeksy wysępowania znaku slash/unslash w łańcuchu
prymula <prymula76@outlook.com>
parents:
diff changeset
42 slash = [pos for pos, char in enumerate(dir) if char == c]
prymula <prymula76@outlook.com>
parents:
diff changeset
43 # zdejmuje ostatni indeks
prymula <prymula76@outlook.com>
parents:
diff changeset
44 last_slash = slash.pop()
prymula <prymula76@outlook.com>
parents:
diff changeset
45
prymula <prymula76@outlook.com>
parents:
diff changeset
46
prymula <prymula76@outlook.com>
parents:
diff changeset
47 f=open(dir[last_slash+1:]+".m3u","w+") # file name and mode
prymula <prymula76@outlook.com>
parents:
diff changeset
48 for x in range(0, len(data_out)):
prymula <prymula76@outlook.com>
parents:
diff changeset
49 f.writelines(data_out[x])
prymula <prymula76@outlook.com>
parents:
diff changeset
50 f.writelines("\r\n")
prymula <prymula76@outlook.com>
parents:
diff changeset
51 f.close()
prymula <prymula76@outlook.com>
parents:
diff changeset
52
prymula <prymula76@outlook.com>
parents:
diff changeset
53 print (dir)
prymula <prymula76@outlook.com>
parents:
diff changeset
54 print (data_out)