-
Notifications
You must be signed in to change notification settings - Fork 0
/
eng_to_hi_renamer.py
132 lines (112 loc) · 3.89 KB
/
eng_to_hi_renamer.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import os
import shutil
import urllib.parse
mapping = {
'0': '०',
'1': '१',
'2': '२',
'3': '३',
'4': '४',
'5': '५',
'6': '६',
'7': '७',
'8': '८',
'9': '९',
}
rev_mapping = {v: k for k, v in mapping.items()}
def gita_renamer_eng_to_hi(eng_name):
hi_name = 'गीता '
skipped = ''
for ch in eng_name:
if ch in mapping:
hi_name += mapping[ch]
elif ch == '_':
hi_name += '-'
else:
skipped += ch
if skipped:
print(f'skipped chars are: {skipped}')
return hi_name
def gita_renamer_hi_to_eng(hi_name):
eng_name = ''
skipped = ''
for ch in hi_name:
if ch in rev_mapping:
eng_name += rev_mapping[ch]
elif ch == '-':
eng_name += '_'
else:
skipped += ch
if not eng_name:
print(f'skipped chars are: {skipped}')
return eng_name
def all_gita_renamer():
for root, dirs, files in os.walk('/Users/kishoriji/sadhana/audio/slokas mp3/gita'):
for file in files:
name, ext = file.split('.')
if ext != 'mp3':
continue
print(name)
eng_name = gita_renamer_hi_to_eng(name) + f'.{ext}'
print(eng_name)
shutil.copy(f'{root}/{file}', f'/Users/kishoriji/sadhana/audio/slokas mp3/tmp/{eng_name}')
def all_rigveda_renamer():
for root, dirs, files in os.walk('/Users/kishoriji/sadhana/audio/slokas mp3/upanishads/rigveda'):
for file in files:
name, ext = file.split('.')
if ext != 'mp3':
continue
print(name)
new_name = (name.replace('ऋगवेद ', '').replace('ऋग्वेद ', '')
+ f'.{ext}')
shutil.copy(f'{root}/{file}', f'/Users/kishoriji/sadhana/audio/slokas mp3/tmp/{new_name}')
def bhagwat_rename_hi_to_en(hi_name):
skipped = ''
en_name = ''
for ch in hi_name:
if ch in rev_mapping:
en_name += rev_mapping[ch]
elif ch == '-':
en_name += '_'
else:
skipped += ch
if not en_name:
print(f'skipped chars are: {skipped}')
en_name.replace('भाग. ', '').replace('भाग ', '')
return en_name.strip()
def all_bhagwat_renamer():
for root, dirs, files in os.walk('/Users/kishoriji/sadhana/audio/slokas mp3/bhagwat'):
for file in files:
if not file.endswith('.mp3'):
continue
name = file[:-4]
print(name)
eng_name = bhagwat_rename_hi_to_en(name) + '.mp3'
print(eng_name)
shutil.copy(f'{root}/{file}', f'/Users/kishoriji/sadhana/audio/slokas mp3/tmp/{eng_name}')
def all_shwetashatar_renamer():
for root, dirs, files in os.walk('/Users/kishoriji/sadhana/audio/slokas mp3/upanishads/keno'):
for file in files:
if not file.endswith('.mp3'):
continue
name = file[:-4].replace('keno_', '') + '.mp3'
print(name)
shutil.copy(f'{root}/{file}', f'/Users/kishoriji/sadhana/audio/slokas mp3/tmp/{name}')
def all_brahm_sutras_renamer():
for root, dirs, files in os.walk('/Users/kishoriji/sadhana/audio/slokas mp3/brahma sutras'):
for file in files:
if not file.endswith('.mp3'):
continue
name = file[:-4]
print(name)
eng_name = gita_renamer_hi_to_eng(name) + '.mp3'
print(eng_name)
shutil.copy(f'{root}/{file}', f'/Users/kishoriji/sadhana/audio/slokas mp3/tmp/{eng_name}')
def playlist_processor():
with open('slokas/playlists/sadhana.m3u', encoding='utf-8') as f:
for line in f:
if 'EXTINF' not in line:
print(urllib.parse.unquote(line.strip()))
if __name__ == '__main__':
#all_brahm_sutras_renamer()
playlist_processor()