Giter Club home page Giter Club logo

Comments (2)

devsnd avatar devsnd commented on May 24, 2024

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.

lbrth avatar lbrth commented on May 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.