Nun möchte ich die Informationen in eine Form bringen, die es mir ermöglicht sie direkt zum Umbenennen von Dateien zu verwenden. Also in diese Form etwa:View by:
Season 1
Season 1, Episode 1:
Pilot
Season 1, Episode 2:
Hell-A Woman
Season 1, Episode 3:
The Whore of Babylon
Season 1, Episode 4:
Fear and Loathing at the Fundraiser
Season 1, Episode 5:
LOL
Season 1, Episode 6:
Absinthe Makes the Heart Grow Fonder
Season 1, Episode 7:
Girls, Interrupted
Season 1, Episode 8:
California Son
Season 1, Episode 9:
Filthy Lucre
Season 1, Episode 10:
The Devil's Threesome
Season 1, Episode 11:
Turn the Page
Season 1, Episode 12:
The Last Waltz
Season 2
Season 2, Episode 1:
Slip of the Tongue
Season 2, Episode 2:
The Great Ashby
Season 2, Episode 3:
No Way to Treat a Lady
Season 2, Episode 4:
The Raw
the Cooked
Season 2, Episode 5:
Vaginatown
Season 2, Episode 6:
Coke Dick
First Kick
. . .
Dazu habe ich benutze ich folgenden Code:Californication - S01E01 - Pilot.avi
Californication - S01E02 - Hell-A Woman.avi
Californication - S01E03 - The Whore of Babylon.avi
Californication - S01E04 - Fear and Loathing at the Fundraiser.avi
Californication - S01E05 - LOL.avi
Californication - S01E06 - Absinthe Makes the Heart Grow Fonder.avi
Californication - S01E07 - Girls, Interrupted.avi
Californication - S01E08 - California Son.avi
Californication - S01E09 - Filthy Lucre.avi
Californication - S01E10 - The Devil's Threesome.avi
Californication - S01E11 - Turn the Page.avi
Californication - S01E12 - The Last Waltz.avi
Californication - S02E01 - Slip of the Tongue.avi
Californication - S02E02 - The Great Ashby.avi
Californication - S02E03 - No Way to Treat a Lady.avi
Californication - S02E04 - The Raw.avi
Californication - S02E05 - Vaginatown.avi
Californication - S02E06 - Coke Dick.avi
Californication - S02E07 - In a Lonely Place.avi
Californication - S02E08 - Going Down and Out in Beverly Hills.avi
Californication - S02E09 - La Ronde.avi
Californication - S02E10 - In Utero.avi
Californication - S02E11 - Blues from Laurel Canyon.avi
Californication - S02E12 - La Petite Mort.avi
Code: Alles auswählen
import re
f = open(r"D:\Filme\Californication\seasons.txt", "r")
content = f.read()
f.close()
#-----------------------------------------------------------------------------
# Find the relevant informations and build a list of them.
content = re.findall(r"Season [0-9]+\, Episode [0-9]+\: \n.*", content)
content = [element.replace("\n", "- ") for element in content]
content = [element.replace(":", "") for element in content]
#-----------------------------------------------------------------------------
# Build the filenames.
content = [element.replace("Season ", "S") for element in content]
content = [element.replace(", Episode ", "E") for element in content]
for index, element in enumerate(content):
if element[2] == "E":
content[index] = element.replace("S", "S0", 1)
for index, element in enumerate(content):
if element[5] == " ":
content[index] = element.replace("E", "E0", 1)
#-----------------------------------------------------------------------------
# Write the content back.
f = open(r"D:\Filme\Californication\seasons2.txt", "w")
for element in content:
f.write("Californication - " + element.strip() + ".avi\n")
f.close()
Und nun wollte ich fragen, ob man das irgendwie besser machen kann. Der Code gefällt mir irgendwie nicht wirklich und ist auch sehr unflexibel. Weiterhin muß ich zum Beispiel um zu checken, ob die Angaben im Format S01 und E01 statt S1 und E1 zwei Schleifen verwenden. Geht das besser? Und wie kann ich Zeichen herausfiltern, die in einem Dateinamen nicht verwendet werden dürfen?
Über jegliche Verbesserungsvorschläge bin ich sehr dankbar.