update on mediasegie python script,much better code