Advertisement
Guest User

Untitled

a guest
May 27th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.05 KB | None | 0 0
  1. import os
  2. import datetime
  3. from time import sleep, time
  4.  
  5. from mutagen.easyid3 import EasyID3
  6. import MySQLdb as sql
  7.  
  8. config_sql_user = "swinger"
  9. config_sql_pass = "2rUnrSZTz7q38aDp"
  10. config_sql_db = "swinger"
  11. config_sql_waittime = 10
  12.  
  13. config_dir_processed = "/home/knifa/public_html/swinger/files/processed/"
  14. config_dir_queued = "/home/knifa/public_html/swinger/files/queued/"
  15.  
  16. config_swinger = "/home/knifa/swing.py"
  17.  
  18. sql_db = sql.connect(user=config_sql_user, passwd=config_sql_pass,
  19.     db=config_sql_db, use_unicode=True)
  20.    
  21. sql_c = sql_db.cursor()
  22.  
  23. while True:
  24.     print "Checking database..."
  25.        
  26.     sql_c.execute("SELECT count(*) FROM queue");
  27.     queue_len = sql_c.fetchone()[0]
  28.        
  29.     if queue_len > 0:
  30.         print "Processing tracks..."
  31.            
  32.         sql_c.execute("SELECT * FROM queue ORDER BY id ASC");
  33.         tracks = sql_c.fetchall()
  34.    
  35.         for track in tracks:
  36.             id = track[0]
  37.             filename = track[1]
  38.             orig_filename = track[2]
  39.        
  40.             print "Processing", filename + "..."
  41.            
  42.             # Get the filepaths for the audio files.
  43.             input_path = config_dir_queued + filename
  44.             output_path = config_dir_processed + filename
  45.            
  46.             # Get the tags from the file.
  47.             try:
  48.                 tags = EasyID3(input_path)
  49.                 artist = tags["artist"][0]
  50.                 title = tags["title"][0]
  51.                 album = tags["album"][0]
  52.             except:
  53.                 artist = ""
  54.                 title = ""
  55.                 album = ""
  56.            
  57.             # Process the file.
  58.             #cmd = "python " + config_swinger + " "
  59.             #cmd = cmd + "-o " + output_path + " " + input_path
  60.             #os.system(cmd)
  61.            
  62.             # Add the track into the track table.
  63.             sql_c.execute(u"""INSERT INTO tracks (queue_id,
  64.                 filename, orig_filename, added, artist, title, album)
  65.                 VALUES (%s, %s, %s, NOW(), %s, %s, %s);""",
  66.                 (id, filename, orig_filename, artist, title, album))
  67.        
  68.             # Delete the queued track.
  69.             #sql_c.execute("""DELETE FROM queue WHERE id="%s";""", (id,))
  70.            
  71.             # Delete the original file.
  72.             #os.remove(input_path)
  73.            
  74.         print "Waiting 1 second..."
  75.         sleep(1)
  76.     else:
  77.         print "No tracks to be processed."
  78.         print "Waiting 10 seconds..."
  79.         sleep(config_sql_waittime)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement