{"id":32,"date":"2016-03-02T06:17:55","date_gmt":"2016-03-02T06:17:55","guid":{"rendered":"http:\/\/localhost\/~downtime\/wordpress\/?p=32"},"modified":"2016-03-02T06:17:55","modified_gmt":"2016-03-02T06:17:55","slug":"i-guess-im-learning-python","status":"publish","type":"post","link":"https:\/\/kg5jbe.com\/?p=32","title":{"rendered":"I guess I&#8217;m learning Python"},"content":{"rendered":"<p>I just wrote the first script I&#8217;ve written in years and it works beautifully. It&#8217;s very dirty, and I&#8217;m sure I&#8217;ll rewrite it to be more robust, but for now it gets the job done. The job, so to speak, is relatively simple. Take a large single audiobook file and break it up into smaller, regular tracks. Using python, ffprobe, ffmpeg and very liberal use of google, I got it done in just few hours total time. But this is starting pretty much from scratch. I couldn&#8217;t remember how to start a python script. It&#8217;s amazing what one is able to remember when the need arises. I seemingly intuitively knew to use str() and float() to correct a concat error? That one surprised me. Anyway, here it is in all it&#8217;s glory.<\/p>\n<p><code><br \/>\n#!\/usr\/bin\/python<\/p>\n<p>## this is a very quick and dirty file splitter<br \/>\n## i think this only works for non-chapter .m4b<br \/>\n## quicksplit.py author title filename<\/p>\n<p>import sys<br \/>\nimport subprocess<br \/>\nimport os<\/p>\n<p>author = sys.argv[1]<br \/>\ntitle = sys.argv[2]<br \/>\nfilename = sys.argv[3]<\/p>\n<p>start = 0<br \/>\nend = 0<br \/>\ntrack = 1<br \/>\nsegment = 1800 # time in seconds<\/p>\n<p>probe_command = \"ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 '\" + filename + \"'\"<\/p>\n<p>print(\"Audiobook \" + title + \" written by \" + author)<\/p>\n<p>## get the total duration of the file and convert to float<br \/>\nduration = float(subprocess.check_output(probe_command, shell=True))<\/p>\n<p>while start &lt; duration : end = start + segment ## get a new endpoint by adding the segment length if end &gt; duration : ## check of we've iterated past the actual duration<br \/>\nend = duration<br \/>\nprint(\"Break from \" + str(start) + \" to \" + str(end) + \" until \" + str(duration))<br \/>\nsplit_command = \"ffmpeg -i '\" + filename + \"' -ss \" + str(start) + \" -to \" + str(end) + \" -acodec copy '\" + author + \" - \" + title + \" - \" + str(track) + \".mp4' #print(split_command)<br \/>\nsubprocess.call(split_command, shell=True)<br \/>\nstart = end ## iterate start to where we left off<br \/>\ntrack = track + 1<br \/>\n<\/code><br \/>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I just wrote the first script I&#8217;ve written in years and it works beautifully. It&#8217;s very dirty, and I&#8217;m sure I&#8217;ll rewrite it to be more robust, but for now it gets the job done. The job, so to speak, is relatively simple. Take a large single audiobook file and break it up into smaller, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-32","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/kg5jbe.com\/index.php?rest_route=\/wp\/v2\/posts\/32","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kg5jbe.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kg5jbe.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kg5jbe.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kg5jbe.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=32"}],"version-history":[{"count":0,"href":"https:\/\/kg5jbe.com\/index.php?rest_route=\/wp\/v2\/posts\/32\/revisions"}],"wp:attachment":[{"href":"https:\/\/kg5jbe.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=32"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kg5jbe.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=32"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kg5jbe.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=32"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}