File size: 9,212 Bytes
2a065c3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import json
import os
from tinytag import TinyTag 
from PIL import Image
import io
import math

path = "D:/01-Bhajan Haridham-Mp3 (Pen-1)"

# list all files in the directory and subdirectories and store them in a list
def list_files(path):
    files = []
    for r, d, f in os.walk(path):
        for file in f:
            if ".mp3" in file:
                files.append(os.path.join(r, file).replace("\\", "/"))
    return files

bhajan_audios = list_files(path)
# extract all metadata from the mp3 files and store them in a list
data = []
for bhajan in bhajan_audios:
    metadata = {}
    # audio = TinyTag.get(bhajan)
    audio = TinyTag.get(bhajan, image=True)
    try:
        image = audio.get_image()
        if image is not None:
            pi = Image.open(io.BytesIO(image))
            pi.save("D:/01-Bhajan Haridham-Mp3 (Pen-1)/thumbnail/" + audio.title + ".jpg")
            metadata["thumbnail"] = True
    except:
        pass
    try:
        print("Url:" + bhajan)
        metadata["url"] = bhajan.replace("D:/01-Bhajan Haridham-Mp3 (Pen-1)","")
    except:
        pass
    try:
        print("Title:" + audio.title)
        metadata["title"] = audio.title
    except:
        pass
    try:
        print("album:" + audio.album)
        metadata["album"] = audio.album
    except:
        pass
    try:
        print("Artist: " + audio.artist)
        metadata["artist"] = audio.artist
    except:
        pass
    try:
        print("Year Released: " + audio.year)
        metadata["year"] = audio.year
    except:
        pass
    try:
        print("AlbumArtist: " + audio.albumartist)
        metadata["albumArtist"] = audio.albumartist
    except:
        pass
    try:
        print("Duration: " + str(audio.duration) + " seconds")
        # convert the duration to minutes and seconds
        metadata["duration"] = [math.floor(audio.duration / 60), math.floor(audio.duration % 60)]
    except:
        pass
    try:
        print("copyright: " + audio.extra["copywrite"])
        # convert the duration to minutes and seconds
        metadata["copyright"] = audio.extra["copywrite"]
    except:
        pass
    data.append(metadata)
with open("./metadata.json", "w") as f:
    json.dump(data, f, indent=4)


def swamiNiVato():
    prakaran1Data = json.loads(
        open("./extra/swamiNiVato/prakaran_1_data.json", "r", encoding="utf-8").read()
    )
    prakaran2Data = json.loads(
        open("./extra/swamiNiVato/prakaran_2_data.json", "r", encoding="utf-8").read()
    )
    prakaran3Data = json.loads(
        open("./extra/swamiNiVato/prakaran_3_data.json", "r", encoding="utf-8").read()
    )
    prakaran4Data = json.loads(
        open("./extra/swamiNiVato/prakaran_4_data.json", "r", encoding="utf-8").read()
    )
    prakaran5Data = json.loads(
        open("./extra/swamiNiVato/prakaran_5_data.json", "r", encoding="utf-8").read()
    )
    prakaran6Data = json.loads(
        open("./extra/swamiNiVato/prakaran_6_data.json", "r", encoding="utf-8").read()
    )
    prakaran7Data = json.loads(
        open("./extra/swamiNiVato/prakaran_7_data.json", "r", encoding="utf-8").read()
    )
    
    swamiNiVato = Books.objects.filter(title="Swami Ni Vato").first()
    # create 7 new sections in the book
    for i in range(1, 8):
        section = Sections.objects.create(
            book=swamiNiVato,
            title=f"Prakaran {i}",
            urlId=f"prakaran-{i}",
            isPdf=False,
            hasChapters=True,
        )
    # each prakaran {
    #     "contentGuj": "અનાદિ મૂળ અક્ષરમૂર્તિ શ્રી ગુણાતીતાનંદ સ્વામીએ વાત કરી જે, ભગવાન ને સાધુના મહિમાની વાતું નિરંતર કરવી ને સાંભળવી. ને મહારજ તો પોતાનું અક્ષરધામ ને પાર્ષદ ને પોતાનું સમગ્ર ઐશ્વર્ય તે લઈને આંહી પધાર્યા છે. તે એવા ને એવા જ છે. ને દેહ મૂકીને જેને પામવા છે, તે આજ દેહ છતાં મળ્યા છે, કાંઈ બાકી નથી; ને એમ ન સમજાય તેથી જીવમાં દુર્બળતા રહે છે, ને એમ સમજાય ત્યારે કોઈ દિવસ જીવમાં દુર્બળતા મનાય જ નહિ; ને જીવ બીજી રીતનો થઈ જાય છે. ને મહિમા સમજવા જેવું બીજું કોઈ મોટું સાધન પણ નથી ને મહિમા વિના બીજાં ગમે એટલાં સાધન કરે, તો પણ જીવ બળને પામે નહિ. ને એવો મહિમા સમજવાનું કારણ તો એવા ભગવદીનો પ્રસંગ છે, પણ તે વિના એવો મહિમા સમજાતો નથી.",
    #     "footnoteGuj": "",
    #     "mp3": "https://ia903107.us.archive.org/9/items/vato_20191108/1.mp3",
    #     "contentEng": "One should continuously engage in delivering and listening to talks on the glory of God and his Sadhu. Maharaj has come here (to earth) with his Akshardham,parshadsand all his powers. He is exactly the same (today).1He whom we wish to attain after death, we have attained during this life; there is nothing more left to attain. If this truth is not understood properly, thejivaremains weak. Once this is understood, thejivawill no longer consider itself weak and will acquire a different mettle. Also, there is no greater endeavour than to understand the glory of God. Without understanding the glory, even countless other endeavours will not enable thejivato attain spiritual strength. The means to understanding this glory is profound association with such a holy Sadhu, and without it the true glory of God cannot be understood.",
    #     "footnoteEng": "1. Meaning, the human form on earth is the same as the divine form in Akshardham.",
    #     "prakaran": 1,
    #     "vato": 1
    #   }
    # data
    for data in prakaran1Data:
        section = Sections.objects.filter(
            book=swamiNiVato, urlId=f"prakaran-{data["prakaran"]}"
        ).first()
        Chapters.objects.create(
            title=f'Vat {data["vato"]}',
            urlId=f'vat-{data["vato"]}',
            data=data,
            section=section,
            book=swamiNiVato,
            isPdf=False,
        )
    for data in prakaran2Data:
        section = Sections.objects.filter(
            book=swamiNiVato, urlId=f"prakaran-{data['prakaran']}"
        ).first()
        Chapters.objects.create(
            title=f'Vat {data["vato"]}',
            urlId=f'vat-{data["vato"]}',
            data=data,
            section=section,
            book=swamiNiVato,
            isPdf=False,
        )
    for data in prakaran3Data:
        section = Sections.objects.filter(
            book=swamiNiVato, urlId=f"prakaran-{data['prakaran']}"
        ).first()
        Chapters.objects.create(
            title=f'Vat {data["vato"]}',
            urlId=f'vat-{data["vato"]}',
            data=data,
            section=section,
            book=swamiNiVato,
            isPdf=False,
        )
    for data in prakaran4Data:
        section = Sections.objects.filter(
            book=swamiNiVato, urlId=f"prakaran-{data['prakaran']}"
        ).first()
        Chapters.objects.create(
            title=f'Vat {data["vato"]}',
            urlId=f'vat-{data["vato"]}',
            data=data,
            section=section,
            book=swamiNiVato,
            isPdf=False,
        )
    for data in prakaran5Data:
        section = Sections.objects.filter(
            book=swamiNiVato, urlId=f"prakaran-{data['prakaran']}"
        ).first()
        Chapters.objects.create(
            title=f'Vat {data["vato"]}',
            urlId=f'vat-{data["vato"]}',
            data=data,
            section=section,
            book=swamiNiVato,
            isPdf=False,
        )

    for data in prakaran6Data:
        section = Sections.objects.filter(
            book=swamiNiVato, urlId=f"prakaran-{data['prakaran']}"
        ).first()
        Chapters.objects.create(
            title=f'Vat {data["vato"]}',
            urlId=f'vat-{data["vato"]}',
            data=data,
            section=section,
            book=swamiNiVato,
            isPdf=False,
        )

    for data in prakaran7Data:
        section = Sections.objects.filter(
            book=swamiNiVato, urlId=f"prakaran-{data['prakaran']}"
        ).first()
        Chapters.objects.create(
            title=f'Vat {data["vato"]}',
            urlId=f'vat-{data["vato"]}',
            data=data,
            section=section,
            book=swamiNiVato,
            isPdf=False,
        )