import sqlite3
import os
import time

path_root = "M:/"
path_artist = ""
path_album = ""
path_track = ""
track_num = ""
song_id = 1
song_duration = 0
song_path = ""

conn_source = sqlite3.connect("music_metadata4.db")
conn_target = sqlite3.connect("spotty_smith.db")
cursor_source = conn_source.cursor()
cursor_target = conn_target.cursor()

cursor_source.execute("SELECT * FROM music")
rows = cursor_source.fetchall() 
for row in rows:
    song_id = row[0]
    path_artist = row[2]
    path_album = row[3]
    path_track = row[1]
    track_num = row[6]
    song_duration = row[7]

    song_duration = time.strftime("%M:%S", time.gmtime(song_duration))
    
    song_path = path_root + path_artist + '/'+ path_album + '/' + track_num + ' - ' + path_track + '.mp3'
    print("Working on " + str(song_path), end="\r")



    cursor_target.execute('''
        INSERT INTO songs (id, title, artist, album, duration, file_path)
        VALUES (?, ?, ?, ?, ?, ?)
        ''', (song_id, path_track, path_artist, path_album, song_duration, song_path))
    conn_target.commit()