Python Forum
MP3 Tags to Excel Not working
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MP3 Tags to Excel Not working
#6
(Jan-26-2021, 11:01 PM)giddyhead Wrote:
(Jan-24-2021, 11:05 AM)ibreeden Wrote: I am sorry, I was completely wrong. The problem lies somewhere else. The problem is the definition of gettags[]. This should be a two dimensional list. Each item of gettags[] should be a copy of gettags2[]. Can you change this:
                    for x in range(len(gettags2)):
                        gettags.append(gettags2[x]) #Loop until All Tags are Added to List
... to this:
                    #append slice of gettags2, containing the entire gettags2
                    gettags.append(gettags2[:])
(You must use the slice operator [:] to make a copy or else a reference will be made to gettags2.)
Then also change the following:
                for r in gettags:
                    #_ = ws1.cell(column=col, row=row, value= gettags2[1]) #"{0}".format(get_column_letter(col)))
                     
                    column_cell = 'A'
                    ws1['A1'] = 'Album'
                    ws1[column_cell + str(row + 1)] = gettags[0]
                    ...
Instead of gettags you should use r:
                for r in gettags:
                    #_ = ws1.cell(column=col, row=row, value= gettags2[1]) #"{0}".format(get_column_letter(col)))
                     
                    column_cell = 'A'
                    ws1['A1'] = 'Album'
                    ws1[column_cell + str(row + 1)] = r[0]
                    ...
... and then the same for all columns.

There is an inefficiency in your program. Why fill the header on row 1 each time again?

Let me know if it works.

Quote:I have put the headers before the loop starts so it does it only once. Did not think about those changes Thanks for that. When I applied the changes unfortunately it did not apply the tags of each song it only did the last song MP3 Tags in some cells. What updates can I make to update the cells? Thanks

The following is an update on the enter data excel spread sheet I have changed this..
wb = Workbook()
    os.chdir('C:\\Users\\mrdrj\\Desktop\\cqq\\CD 3\\')
    dest_filename = '11empty_book11.xlsx'
    newFile = dest_filename
    wb = openpyxl.load_workbook(filename = newFile)        
    worksheet = wb.active
     
    ws1 = wb.active
    ws = wb.active
    ws1.title = "MP3 Info" # Main Tab
    sheet = "MP3 Info"
    r = 0
        
    #print(Mp3Tagsexel)
    for col in range(1, 2): # Add how many Tabs 
     #ws1.append(range(5)) #Add values to Rows
        for row in range(1, number_files): 
            #for col in range(1, 8): # Number of colums static
                #print('------View Results------')
                               
                for r in gettags:
                    #_ = ws1.cell(column=col, row=row, value= gettags2[1]) #"{0}".format(get_column_letter(col)))
                     
                    column_cell = 'A'
                    ws1['A1'] = 'Album'
                    ws1[column_cell + str(row + 1)] = gettags[0]
 
                    column_cell = 'B'
                    ws1['B1'] = 'Contributing Artists'
                    ws1[column_cell + str(row + 1)] =  gettags[1]    
 
                    column_cell = 'C'
                    ws1['C1'] = 'Title'
                    ws1[column_cell + str(row + 1)] = gettags[2] 
 
                    column_cell = 'D'
                    ws1['D1'] = 'Total Number of Disk'
                    ws1[column_cell + str(row + 1)] = gettags[3] 
 
                    column_cell = 'E'
                    ws1['E1'] = 'Genre'
                    ws1[column_cell + str(row + 1)] =  gettags[4] 
 
                    column_cell = 'F'     
                    ws1['F1'] = 'Disc Number'
                    ws1[column_cell + str(row + 1)] =  gettags[0] 
 
                    column_cell = 'G'
                    ws1['G1'] = 'Track Duration'
                    ws1[column_cell + str(row + 1)] =  gettags[0] 
 
    wb.save(filename=dest_filename)
To this. It enters the data however it duplicates it. How can I solve the duplication prior to it being entered into the excel document. I have tried TinyTag.valid_keys.keys()to have the headers added via code but they do not appear to be no attribute 'valid_keys' what options do I have so all keys can be produce? Thanks
os.chdir('C:\\Users\\mrdrj\\Desktop\\cqq\\Brimstone CD 3\\')
                header = [u'Album', u'Artist', u'Track', u'Title', u'Duration']
                #new_data = [[u'Album Test', u'Artist Test', 1, u'Title Test',u'3.00'],
                 #[u'Album Test 2', u'Artist Test 2', 2, u'Title Test 2',u'3.45']]
                new_date = gettags
                wb = Workbook()
                new_data = gettags
                dest_filename = '11empty_book11.xlsx'
                ws1 = wb.active
                ws1.title = "MP3 Tags"
                print()
                ws1.append(header)
                for row in new_data:
                    ws1.append(row)
                    wb.save(filename=dest_filename)
Reply


Messages In This Thread
MP3 Tags to Excel Not working - by giddyhead - Jan-22-2021, 09:16 PM
RE: MP3 Tags to Excel Not working - by ibreeden - Jan-23-2021, 09:22 AM
RE: MP3 Tags to Excel Not working - by giddyhead - Jan-23-2021, 10:33 PM
RE: MP3 Tags to Excel Not working - by ibreeden - Jan-24-2021, 11:05 AM
RE: MP3 Tags to Excel Not working - by giddyhead - Jan-26-2021, 11:01 PM
RE: MP3 Tags to Excel Not working - by giddyhead - Jan-27-2021, 03:23 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Excel isnt working properly after python function is started IchNar 2 108 5 hours ago
Last Post: IchNar
  Working with Excel and Word, Several Questions Regarding Find and Replace Brandon_Pickert 4 1,594 Feb-11-2023, 03:59 PM
Last Post: Brandon_Pickert
  Too many if statements working as "tags" zeek 3 2,013 Sep-20-2021, 05:22 PM
Last Post: deanhystad
  Working with excel files arsouzaesilva 6 3,219 Sep-17-2021, 06:52 PM
Last Post: arsouzaesilva
  Need help working with two excel file with different formats mikey3580 1 1,614 Apr-22-2020, 07:11 AM
Last Post: DPaul
  Loop through tags inside tags in Selenium/Python xpack24 1 5,701 Oct-23-2019, 10:15 AM
Last Post: Larz60+
  working with more excel files Krszt 1 2,475 Mar-13-2019, 11:41 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020