Freebox Jukebox

E-Touch General Category => General Discussion => Topic started by: mxd on February 14, 2013, 10:08:57 AM

Title: my recursive search "non mps tag" creator
Post by: mxd on February 14, 2013, 10:08:57 AM
I've just moved to etouch and need to tag my vids, so instead of opening each directory I wrote a quick and dirty python script that same may find useful

N.B it will tag every file (e.g covers, tags etc..)

if you collection is
video\artist\album\song.avi

then install python, save the following at tagit.py in the video directory then double click tagit.py, it should traverse all directories and write a tag file for every file.

If the file name has "strange" ascii chars in it it will die there ?

--------------------------------
import os, os.path
start = "."

for root, dirs, files in os.walk(os.path.abspath(start)):
    #for d in dirs:
        #fullpath = os.path.join(root, f)
        # if os.path.splitext(fullpath)[1] == '.txt':
    print ("dirs ", dirs)
    if len(files) > 0:
        for f in files:
            print ("----")
            artist = os.path.split(os.path.dirname(root))[1]
            album =os.path.split(root)[1]
            title = os.path.splitext(f)[0]
            filename = f+".tag"
            filepath =root
            print ("artist ", artist)
            print ("title ",title)
            print ("filename ", filename)
            print ("album ", album)
            print ("filepath", filepath)
            print ("----")
            myFile = open(os.path.join(filepath,f+".tag"), 'w')
            myFile.write("<NonMP3Tag>\n")
            myFile.write("  <Artist>"+artist+"</Artist>\n")
            myFile.write("  <Title>"+title+"</Title>\n")
            myFile.write("  <Album>"+album+"</Album>\n")
            myFile.write("  <Band></Band>\n")
            myFile.write("  <Track></Track>\n")
            myFile.write("  <Year></Year>\n")
            myFile.write("  <Genre></Genre>\n")
            myFile.write("  <CommentTitle></CommentTitle>\n")
            myFile.write("  <CommentText></CommentText>\n")
            myFile.write("  <Seconds></Seconds>\n")
            myFile.write("  <Duration></Duration>]\n")
            myFile.write("</NonMP3Tag>\n")
            myFile.close()
Title: Re: my recursive search "non mps tag" creator
Post by: mxd on July 20, 2014, 12:52:40 AM
another dodgy script

this one will convert filenames from artist - song to

artist\song

import os, os.path
start = "."

for root, dirs, files in os.walk(os.path.abspath(start)):
    #for d in dirs:
        #fullpath = os.path.join(root, f)
        # if os.path.splitext(fullpath)[1] == '.txt':
    print ("dirs ", dirs)
    if len(files) > 0:# and os.path.splitext[1] != ".tag":
        for f in files:
            print ("----")
            title = os.path.splitext(f)[0]
            #the names are artist - song
            filename = f.split('-')[1:]
            # just in case there was - in the song name
            if len(filename) > 0:
                if len(filename) > 1:
                    name = filename[0]
                    for a in filename[1:]:
                            name = name + '-' + a
                else:
                    name=filename[0]
                # get rid of _ in the names and replace with space
                name = name.replace('_',' ' )
                #get rid of left and right spaces
                name =name.lstrip()
                name =name.rstrip()
                filepath =root
                directory =title.split('-')[0]
                directory =directory.lstrip()
                directory =directory.rstrip()
                print ("directory ", directory)
                print ("title ",title)
                print ("name ", name)
                print ("filepath", filepath)
                print ("----")
                # check if directory exists else create it
                if os.path.isdir(directory) is False:
                    os.makedirs(directory)
                #check if file exists else create it
                try:
                     os.rename(f,directory+'\\'+name)
                except:
                    print (directory+'\\'+name)