Skip to content

Instantly share code, notes, and snippets.

@robstenzinger
Created November 20, 2014 07:20
Show Gist options
  • Save robstenzinger/365bb4600c812f370238 to your computer and use it in GitHub Desktop.
Save robstenzinger/365bb4600c812f370238 to your computer and use it in GitHub Desktop.
polytechnicast.py Gets an MP3 file ready to post for the Polytechnicast using eyeD3 to set all the MP3 metadata plus artwork.
"""
polytechnicast.py
Gets an MP3 file ready to post for the Polytechnicast using eyeD3 to set all the MP3 metadata plus artwork.
Accepts a file path as a parameter,
assumes that the show notes and podcast MP3 file are named the same,
except for their given file extension,
and are in the same file directory.
Script is based on examples in the eyed3 documentation,
combined with this blog article which shows how to embed an image:
http://tuxpool.blogspot.com/2013/02/how-to-store-images-in-mp3-files-using.html
"""
import sys
import os
import eyed3
# get the name of the podcast as a parameter
base_name = sys.argv[1]
# prep the names of the output files
fileName, fileExtension = os.path.splitext(base_name)
file_markdown = fileName + ".md"
file_mp3 = fileName + ".mp3"
file_text = fileName + ".txt"
# path to the cover image
cover_image_file_path = u"/Users/Rob/Desktop/polytechnicast_cover.jpg"
# read markdown file into memory
with open (file_markdown, "r") as show_notes_file_ref:
show_notes_content = show_notes_file_ref.read()
# write a clean text version of the markdown, useful for posting to Patreon
text_file = open(file_text, "w")
show_notes_content_text = show_notes_content
show_notes_content_text = show_notes_content_text.replace("* [", "- ")
show_notes_content_text = show_notes_content_text.replace("](", ": ")
show_notes_content_text = show_notes_content_text.replace(")", "")
show_notes_content_text = show_notes_content_text.replace("## ", "")
show_notes_content_text = show_notes_content_text.replace("#Polytechnicast", "Polytechnicast")
text_file.write(show_notes_content_text)
text_file.close()
# read image into memory
with open (cover_image_file_path, "rb") as image_file_ref:
image_content = image_file_ref.read()
# set the general metadata on the file
audiofile = eyed3.load(file_mp3)
audiofile.tag.artist = u"Rob Stenzinger"
audiofile.tag.album = u"Polytechnicast"
audiofile.tag.album_artist = u"Rob Stenzinger"
audiofile.tag.title = u"" + os.path.basename(fileName)
audiofile.tag.release_year = 2014
audiofile.tag.year = 2014
# set front cover which is the 3 constant to proper image...
FRONT_COVER = 3
audiofile.tag.images.set(FRONT_COVER,image_content,"image/jpeg", u"album art")
# save it!
audiofile.tag.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment