connect / extra /dataMaker.py
thejagstudio's picture
Upload 363 files
2a065c3 verified
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,
)