-1

I have two collections of mp3 files. I want to batch-replace the tags of one collection with the tags of the other. The difficulty is that the original "date" tags are strings like "01/02/1934" or "Jan 02 1934", which can be recognized and edited by software like foobar2000 and Mp3tag.

I have been trying to achieve this with Python eyeD3 and mutagen libraries. But they cannot recognize the non-standard dates. So I have no way to access the original date string.

I wonder how music software can read and write any string into the "Date" field. Maybe there is a way to extract the string from the binary data of mp3?

Myusico
  • 69
  • 4
  • Does this answer your question? [Convert string "Jun 1 2005 1:33PM" into datetime](https://stackoverflow.com/questions/466345/convert-string-jun-1-2005-133pm-into-datetime) – picobit Apr 12 '23 at 18:44

1 Answers1

0

I think this is a solution for something like regex:

matcher = re.compile(r'\d{2}/\d{2}/\d{4}|\d{4}-\d{2}-\d{2}')

Then just run your string through as matcher.match("MY EXISTING TAG")

But this is just using your examples, so your exact regex would differ based on exactly what you want to match.

Another option is to just use the datetime parse functions:

from datetime import datetime

date_string = "01/02/1934"
try:
    date = datetime.strptime(date_string, '%m/%d/%Y')
    print(date)
except ValueError:
    print("Invalid date format")
pypalms
  • 461
  • 4
  • 12
  • This works for converting between different date formats. But I currently have no way to extract the original string. – Myusico Apr 12 '23 at 19:54
  • I'm really unsure then, maybe try tagging/asking as a question specific to the app, because this solution should get the names to a desired start state at the very least, and if the app you are using doesn't natively support it, then it wouldn't be a python issue – pypalms Apr 13 '23 at 16:04