Comments (2)
Hey Ibrth,
Here's some example code to get you going. I didn't try it out, so there might be a small mistake, but I'm sure you'll get it to work. This code will look in all directories below /some/dir/path
and collect artist and titles from all mp3s and flacs. Afterwards it will output all the tracks that have the same artist and name and their file locations. Note that even the smallest differences will make that the artists and titles don't match, e.g. "James Brown" and "james brown" will not be picked up as the same artist. This you will have to figure out yourself.
from collections import defaultdict
import os
music_files = defaultdict(list)
music_path = '/some/dir/path'
for dirpath, dirnames, filenames in os.walk(music_path):
for filename in filenames:
# only look at flacs and mp3s
if not filename.endswith(('.mp3'), ('.flac')):
continue
full_file_name = os.path.join(dirpath, filename)
tag = TinyTag.get(full_file_name)
# collect all tracks with the same artiest and name in a list
track_identifier = (tag.artist, tag.title)
music_files[track_identifier].append(full_file_name)
# find tracks that exist multiple times
for identifier, filepaths in music_files.items():
if len(filepaths) > 1:
print('There are multiple versions of %s' % identifier)
for filepath in filepaths:
print(filepath)
I hope that this is of any help to you. For further questions, I guess you should ask on stackoverflow.
from tinytag.
Hi @devsnd ,
Thank's a lot for your very helpful reply. To get the codec I did exactly the same thing (get the file extension) but I didn't know the "collections" library, seems to be very powerful, I'm going to win some time with it for the deduplication process ! For the case where the filename doesn't match exactly, my idea is to normalize all file name as upper case and delete special charactere to compare it.
Thanks again for your disponibility,
lbrth
from tinytag.
Related Issues (20)
- [BUG] Incorrect bitrate and duration for VBR mp3s HOT 5
- [BUG] UnicodeDecodeError on valid MP3 file
- Make use of code linting HOT 1
- How to handle filebuffer instead of filenames
- [BUG] Some mp3 files report 1/2 of actual duration HOT 2
- Some MP3‘s genre cannot be read correctly since v1.8.0
- [Question] - detect image encoding / format HOT 1
- tag artist, quando adicionado mais de um artista a string fica mal formatada. HOT 1
- [BUG] struct.error: unpack requires a buffer of 4 bytes HOT 8
- [BUG] Parsing mp3 file w/ valid TDRC tag does not populate year HOT 4
- Replace deprecated aifc module HOT 3
- [BUG] TDRC tag not captured as "year" HOT 2
- [BUG] Can't read `extra` tags from .m4a files HOT 1
- Expose a list of supported file extensions HOT 4
- Fail to read track_total, but it is ok in foobar
- asyncio interfaces HOT 3
- [BUG] Incompatibility with Python-pip HOT 2
- [BUG] `tags.year` is null although the MP3 file has the year set HOT 2
- [BUG] tinytag 1.10.0 aiff does not have extra data HOT 4
- Ability to get all images HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tinytag.