comparison bandm3u/bandm3u.py @ 0:dcd610585610

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