Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import datetime
- from time import sleep, time
- from mutagen.easyid3 import EasyID3
- import MySQLdb as sql
- config_sql_user = "swinger"
- config_sql_pass = "2rUnrSZTz7q38aDp"
- config_sql_db = "swinger"
- config_sql_waittime = 10
- config_dir_processed = "/home/knifa/public_html/swinger/files/processed/"
- config_dir_queued = "/home/knifa/public_html/swinger/files/queued/"
- config_swinger = "/home/knifa/swing.py"
- sql_db = sql.connect(user=config_sql_user, passwd=config_sql_pass,
- db=config_sql_db, use_unicode=True)
- sql_c = sql_db.cursor()
- while True:
- print "Checking database..."
- sql_c.execute("SELECT count(*) FROM queue");
- queue_len = sql_c.fetchone()[0]
- if queue_len > 0:
- print "Processing tracks..."
- sql_c.execute("SELECT * FROM queue ORDER BY id ASC");
- tracks = sql_c.fetchall()
- for track in tracks:
- id = track[0]
- filename = track[1]
- orig_filename = track[2]
- print "Processing", filename + "..."
- # Get the filepaths for the audio files.
- input_path = config_dir_queued + filename
- output_path = config_dir_processed + filename
- # Get the tags from the file.
- try:
- tags = EasyID3(input_path)
- artist = tags["artist"][0]
- title = tags["title"][0]
- album = tags["album"][0]
- except:
- artist = ""
- title = ""
- album = ""
- # Process the file.
- #cmd = "python " + config_swinger + " "
- #cmd = cmd + "-o " + output_path + " " + input_path
- #os.system(cmd)
- # Add the track into the track table.
- sql_c.execute(u"""INSERT INTO tracks (queue_id,
- filename, orig_filename, added, artist, title, album)
- VALUES (%s, %s, %s, NOW(), %s, %s, %s);""",
- (id, filename, orig_filename, artist, title, album))
- # Delete the queued track.
- #sql_c.execute("""DELETE FROM queue WHERE id="%s";""", (id,))
- # Delete the original file.
- #os.remove(input_path)
- print "Waiting 1 second..."
- sleep(1)
- else:
- print "No tracks to be processed."
- print "Waiting 10 seconds..."
- sleep(config_sql_waittime)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement