def transcode (audio_file, timestamp, epg): title = replacechars(epg[1].decode('latin-1').encode('utf-8')) alias = epg[0] out_dir = os.path.join(DIR_TO, alias, title) if not os.path.exists(out_dir): os.makedirs(out_dir) out_file = out_dir + '/' + datetime.datetime.fromtimestamp( int(timestamp)).strftime(DATE_TIME_FORMAT) + '_' + epg[0] + '.mp3' avconv = [ 'avconv', '-i', audio_file, '-vn', '-acodec', 'libmp3lame', '-ab', '256k', out_file, ] subprocess.call(avconv) return out_file
def movelatest(): with closing(MySQLdb.connect(login.DB_HOST, login.DB_USER, login.DB_PASSWORD, login.DB_DATABASE)) as connection: with closing(connection.cursor()) as cursor: cursor.execute("SELECT id, channel, title, audiofile FROM recordings ORDER BY id ASC") id, channel, title, audiofile = cursor.fetchone() db_request = "DELETE FROM recordings WHERE id = %s" cursor.execute(db_request, (id,)) connection.commit() channel = replacechars(channel.decode("latin-1").encode("utf-8")) title = replacechars(title.decode("latin-1").encode("utf-8")) origin = os.path.join(RECORDING_PATH, channel, title, audiofile) destination = os.path.join(BACKUP_PATH, channel, title, audiofile) destination_path = os.path.join(BACKUP_PATH, channel, title) if not os.path.exists(destination_path): os.makedirs(destination_path) shutil.move(origin, destination)
def delete_db_orphans(connection, cursor): cursor.execute('SELECT * FROM recordings') result = cursor.fetchall() for db_record in result: channel_alias = replacechars( db_record[3].decode('latin-1').encode('utf-8') ) title_path = replacechars( db_record[4].decode('latin-1').encode('utf-8') ) mp3 = os.path.join( PATH_RECORDINGS, channel_alias, title_path, db_record[6] ) check = os.path.isfile(mp3) if check is False: db_request = 'DELETE FROM recordings WHERE audiofile = %s' cursor.execute(db_request, (db_record[6],)) connection.commit()
def main(channel_alias): with closing(MySQLdb.connect( login.DB_HOST, login.DB_USER, login.DB_PASSWORD, login.DB_DATABASE)) as connection: channel = station(connection, channel_alias) last_build_date = formatdate(time.time(), True) podcast_img = image(channel_alias) xml_file = PODCAST_PATH + channel_alias + '.xml' feed = open(xml_file, 'w') podcast_header = header(channel, last_build_date, podcast_img) feed.write(podcast_header) feed.close feed = open(xml_file, 'a') with closing(connection.cursor()) as cursor: cursor.execute( 'SELECT * FROM recordings WHERE channel=%s', channel,) result = cursor.fetchall() for db_record in result: timestamp = db_record[7] title = ( db_record[4] + ' (' + datetime.datetime.fromtimestamp( int(timestamp)).strftime(ID3_TIME_FORMAT) + ' Uhr)' ) description = db_record[5] title_path = replacechars( db_record[4].decode('latin-1').encode('utf-8') ) audio_file = ( channel_alias + '/' + title_path + '/' + db_record[6] ) length_bytes = db_record[9] guid = ( HOST_NAME + '/podcast/' # + '/dreamberry/podcast/' + channel_alias + '_' + str(db_record[0]) ) pub_date = db_record[10] length = db_record[8] podcast_item = item(title, description, audio_file, length_bytes, guid, pub_date, podcast_img, channel, length ) feed.write(podcast_item) feed.write('</channel>\n</rss>') feed.close