- Consider what happens if a user closes the "Load MP3" dialog without picking a file. In that case,
filepath would get set to "". The label would not change, but should the user press the "Shred" button anyway, we would try to import a file called "" (since the filepath variable exists, we don't get that NameError) which would presumably not go terribly well
- I'm not sure why we write the chunks to temporary files only to read them again? It seems like it'd be simpler to do something like this:
glued_song = AudioSegment.empty()
for chunk in random.sample(song[::1000], song.duration_seconds):
glued_song += chunk
- Should you need to keep the temp files, I would advise using the
tempfile module to create it in a more secure and portable manner, in a standard location
- You only seem to use
mutagen to get the duration of the original track. Since pydub supports getting the duration of AudioSegments, (using song.duration_seconds), taking on a whole other dependency just for that seems unnecessary
- Instead of a global variable, it may be neater to have the currently selected file path be a property of the
shredder class - you could set it like self.filepath = None in the __init__, and then access it as self.filepath in getfile and shred
- I do think allowing the user to pick the output file name might be a desirable feature
- Finally, I'm not a big fan of some of the variable names in use here:
shredder, as a class name, would typically be written like Shredder
btn and btn1 tells me very little about what those buttons are. load_button and shred_button, for example, would be more descriptive
- Similarly, I have no clue what
le means. I might go for something like path_label or selection_label instead
getfile is two words - get_file. Or perhaps select_file, or pick_file, to more clearly indicate a choice is being made
song is re-used for different purposes in the same method, which might get confusing
glue_it_back sounds like less like a thing and more like something you do - it's a fine name for a function, but for an object I'd prefer something like glued_song, or even just result