Angeliki/Grad Scripts

From XPUB & Lens-Based wiki
Revision as of 14:31, 1 May 2019 by Angeliki (talk | contribs) (Created page with "=== srttojs.py === Make subtitles 'linkable' for html pip install pysrt <syntaxhighlight lang="python" line='line'> import pysrt, argparse ap = argparse.ArgumentParser("srtt...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

srttojs.py

Make subtitles 'linkable' for html

pip install pysrt
import pysrt, argparse

ap = argparse.ArgumentParser("srttojs")
ap.add_argument("srt")
args = ap.parse_args()

srt= pysrt.open(args.srt)
print("<div class='sub'>")
for t in srt:
    print ('<div><a data-start="{1}" href="#">{0}</a> {2}</div>'.format(t.start, t.start.ordinal/1000.0, t.text))
print ("</div>")

addmetadata.py

Add metadata to an audio file

pip install pydub
from pydub.utils import mediainfo
from pydub import AudioSegment
sound= AudioSegment.from_file("podcasts/podcast.20190501-1223-femalemale.mp3", format="mp3")
file=sound.export("podcasts/podcast.20190501-1223-femalemale-.mp3", tags={"title":"transformation for presence", "narrator":"angeliki", "topic":"female voice to male"})

metadatatohtml.py

Edit metadata for html preview

pip install pydub
from pydub import AudioSegment
from pydub.utils import mediainfo
import pprint

z = mediainfo("podcasts/3_podcast.mp3.mp3")

# sound= AudioSegment.from_file("podcasts/3_podcast.mp3", format="mp3")
# file=sound.export("out.mp3", tags={"podcaster":"lain"})
# print (mediainfo("out.mp3"))


def dict_to_html(dd, level=0):
    """
    Convert dict to html using basic html tags
    """
    import simplejson
    text = ''
    for k, v in dd.items():
        text += '<br>' + '&nbsp;'*(4*level) + '<b>%s</b>: %s' % (k, dict_to_html(v, level+1) if isinstance(v, dict) else (simplejson.dumps(v) if isinstance(v, list) else v))
    return text

def dict_to_html_ul(dd, level=0):
    """
    Convert dict to html using ul/li tags
    """
    import simplejson
    text = '<ul>'
    for k, v in dd.items():
        text += '<li><b>%s</b>: %s</li>' % (k, dict_to_html_ul(v, level+1) if isinstance(v, dict) else (simplejson.dumps(v) if isinstance(v, list) else v))
    text += '</ul>'
    return text

print (dict_to_html(z, level=0))