Hallo zusammen,
ich habe vor geraumer zeit ein script gebastelt, dass informationen aus .nfo dateien (tiny media manager) ausliest und in für emc lesbare txt dateien speichert.
das funktionierte bisher auch immer ganz gut aber ich bekomme mittlerweile am ende der programmausführung (das script macht nach wie vor alles was es soll) einen fehler.
aufgerufen wird das python-sript mit folgendem sh-script:
Spoiler anzeigen
#!/bin/bash
cd /hdd/movie/Filme/wasndas
while IFS= read -r -d '' desc; do python parser.py "$desc"; done < <(find . -type f -name '*.nfo' -print0)
echo "fertig :)"
das python-script selber sieht so aus
Spoiler anzeigen
#!/usr/bin/python
# coding: utf-8
import io, os, sys
import xml.etree.ElementTree as ElementTree
for filename in sys.argv[1:]:
if os.path.exists(filename):
doc = ElementTree.parse(filename)
if doc.find('title') is None:
title = "Kein Titel"
print "title fehlt in %s" % filename
else:
title = doc.find('title').text or "Kein Titel"
if doc.find('year') is None:
year = "Jahr ?"
print "year fehlt in %s" % filename
else:
year = doc.find('year').text or "Jahr ?"
if doc.find('plot') is None:
plot = "Keine Inhaltsangabe"
print "plot fehlt in %s" % filename
else:
plot = doc.find('plot').text or "Keine Inhaltsangabe"
if doc.find('votes') is None:
votes = "-"
print "votes fehlt in %s" % filename
else:
votes = doc.find('votes').text or "-"
if doc.find('mpaa') is None:
mpaa = "?"
print "mpaa fehlt in %s" % filename
else:
mpaa = doc.find('mpaa').text or "?"
if doc.find('director') is None:
director = "?"
print "director fehlt in %s" % filename
else:
director = doc.find('director').text or "?"
if doc.find('runtime') is None:
runtime = "X"
print "runtime fehlt in %s" % filename
else:
runtime = doc.find('runtime').text or "X"
if doc.find('rating') is None:
rating = "-.-"
print "rating fehlt in %s" % filename
else:
rating = doc.find('rating').text
if rating is None: votes = "-"
if rating is None: rating = "-.-"
if mpaa is 'not' or 'rated':
mpaa = "FSK k.A."
if doc.find('country') is None:
country = "Land k.A."
print "country fehlt in %s" % filename
else:
country = doc.find('country').text or "Land k.A."
if country == "United Kingdom": country = "GB"
if country == "France": country = "Frankreich"
if country == "Australia": country = "Australien"
if country == "Belgium": country = "Belgien"
if country == "Germany": country = "Deutschland"
if country == "United States of America": country = "USA"
if country == "Netherlands": country = "Niederlande"
if country == "Sweden": country = "Schweden"
if country == "Canada": country = "Kanada"
if country == "Colombia": country = "Kolumbien"
if country == "Spain": country = "Spanien"
if country == "Argentina": country = "Argentinien"
if country == "Italy": country = "Italien"
if country == "Cuba": country = "Kuba"
if country == "Denmark": country = "D nemark"
if country == "Czech Republic": country = "Tscheschien"
if country == "New Zealand": country = "Neuseeland"
if country == "Russia": country = "Russland"
if country == "Iceland": country = "Island"
names = [n.text or "?" for n in doc.findall('actor/name')]
genre = [g.text or "Genre ?" for g in doc.findall('genre')]
items = [ title, country + ' ' + year + ' (Bewertung/Stimmen: ' + rating[:3] + '/' + votes + ')' + ' ' + mpaa, runtime + ' min, ' + ', '.join(genre), plot, 'Regie: ' + director, 'Darsteller: ' + ', '.join(names)]
basename = os.path.splitext(filename)[0]
with io.open(basename + '.txt', 'w', encoding='utf-8') as fh:
fh.write(u'\n\n'.join(items))
und ganz am ende bekomme ich folgenden fehler (wie gesagt, das ergebnis des scripts stimmt)
Spoiler anzeigen
Traceback (most recent call last):
File "parser.py", line 8, in <module>
doc = ElementTree.parse(filename)
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1182, in parse
tree.parse(source, parser)
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 656, in parse
parser.feed(data)
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1642, in feed
self._raiseerror(v)
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1506, in _raiseerror
raise err
xml.etree.ElementTree.ParseError: syntax error: line 2, column 0
hat jemand ne idee wie ich das wegbekomme ?
ich habe vor geraumer zeit ein script gebastelt, dass informationen aus .nfo dateien (tiny media manager) ausliest und in für emc lesbare txt dateien speichert.
das funktionierte bisher auch immer ganz gut aber ich bekomme mittlerweile am ende der programmausführung (das script macht nach wie vor alles was es soll) einen fehler.
aufgerufen wird das python-sript mit folgendem sh-script:
#!/bin/bash
cd /hdd/movie/Filme/wasndas
while IFS= read -r -d '' desc; do python parser.py "$desc"; done < <(find . -type f -name '*.nfo' -print0)
echo "fertig :)"
das python-script selber sieht so aus
#!/usr/bin/python
# coding: utf-8
import io, os, sys
import xml.etree.ElementTree as ElementTree
for filename in sys.argv[1:]:
if os.path.exists(filename):
doc = ElementTree.parse(filename)
if doc.find('title') is None:
title = "Kein Titel"
print "title fehlt in %s" % filename
else:
title = doc.find('title').text or "Kein Titel"
if doc.find('year') is None:
year = "Jahr ?"
print "year fehlt in %s" % filename
else:
year = doc.find('year').text or "Jahr ?"
if doc.find('plot') is None:
plot = "Keine Inhaltsangabe"
print "plot fehlt in %s" % filename
else:
plot = doc.find('plot').text or "Keine Inhaltsangabe"
if doc.find('votes') is None:
votes = "-"
print "votes fehlt in %s" % filename
else:
votes = doc.find('votes').text or "-"
if doc.find('mpaa') is None:
mpaa = "?"
print "mpaa fehlt in %s" % filename
else:
mpaa = doc.find('mpaa').text or "?"
if doc.find('director') is None:
director = "?"
print "director fehlt in %s" % filename
else:
director = doc.find('director').text or "?"
if doc.find('runtime') is None:
runtime = "X"
print "runtime fehlt in %s" % filename
else:
runtime = doc.find('runtime').text or "X"
if doc.find('rating') is None:
rating = "-.-"
print "rating fehlt in %s" % filename
else:
rating = doc.find('rating').text
if rating is None: votes = "-"
if rating is None: rating = "-.-"
if mpaa is 'not' or 'rated':
mpaa = "FSK k.A."
if doc.find('country') is None:
country = "Land k.A."
print "country fehlt in %s" % filename
else:
country = doc.find('country').text or "Land k.A."
if country == "United Kingdom": country = "GB"
if country == "France": country = "Frankreich"
if country == "Australia": country = "Australien"
if country == "Belgium": country = "Belgien"
if country == "Germany": country = "Deutschland"
if country == "United States of America": country = "USA"
if country == "Netherlands": country = "Niederlande"
if country == "Sweden": country = "Schweden"
if country == "Canada": country = "Kanada"
if country == "Colombia": country = "Kolumbien"
if country == "Spain": country = "Spanien"
if country == "Argentina": country = "Argentinien"
if country == "Italy": country = "Italien"
if country == "Cuba": country = "Kuba"
if country == "Denmark": country = "D nemark"
if country == "Czech Republic": country = "Tscheschien"
if country == "New Zealand": country = "Neuseeland"
if country == "Russia": country = "Russland"
if country == "Iceland": country = "Island"
names = [n.text or "?" for n in doc.findall('actor/name')]
genre = [g.text or "Genre ?" for g in doc.findall('genre')]
items = [ title, country + ' ' + year + ' (Bewertung/Stimmen: ' + rating[:3] + '/' + votes + ')' + ' ' + mpaa, runtime + ' min, ' + ', '.join(genre), plot, 'Regie: ' + director, 'Darsteller: ' + ', '.join(names)]
basename = os.path.splitext(filename)[0]
with io.open(basename + '.txt', 'w', encoding='utf-8') as fh:
fh.write(u'\n\n'.join(items))
und ganz am ende bekomme ich folgenden fehler (wie gesagt, das ergebnis des scripts stimmt)
Traceback (most recent call last):
File "parser.py", line 8, in <module>
doc = ElementTree.parse(filename)
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1182, in parse
tree.parse(source, parser)
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 656, in parse
parser.feed(data)
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1642, in feed
self._raiseerror(v)
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1506, in _raiseerror
raise err
xml.etree.ElementTree.ParseError: syntax error: line 2, column 0
hat jemand ne idee wie ich das wegbekomme ?
Gruß wsxws
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von wsxws ()