我正在编写脚本来从mp4文件的内容构建nfo文件。我使用itunes.xml文件查找播放列表中的项目,然后搜索XML以将项目编号转换为该位置。这很好。我的问题是当我试着看看" path"和" MOVIEFOLDER"比赛。通过屏幕它看起来像它,但编程上它没有。
这是我的代码:
import os, sys, subprocess, shutil, ftplib
from subprocess import call
import xml.etree.ElementTree as ET
MOVIEFOLDER="/Volumes/Data/Media/Movies"
ITUNESPLAYLIST = "Movies,"
ITUNESFOLDER = "/Volumes/Macintosh HD/Users/brianjhille/Music/iTunes"
ITUNESFILENAME = "/iTunes Music Library.xml"
fullitunesfilename = os.path.join(ITUNESFOLDER + ITUNESFILENAME)
if "," in ITUNESPLAYLIST:
ITUNESPLAYLIST = ITUNESPLAYLIST.split(",")
def getplaylistcontents():
mediaintlist = None
totalplaylists = len(playlistdata)
for z in range(0, totalplaylists):
strings = map(lambda x: x.text, playlistdata[z].findall('string'))
integers = map(lambda x: x.text, playlistdata[z].findall('array/dict/integer'))
for playlist in ITUNESPLAYLIST:
if playlist in strings:
if mediaintlist is None:
mediaintlist = integers
else:
mediaintlist = mediaintlist + integers
if mediaintlist is not None:
movielist = None
totalelements = len(mediadata)
for z in range(0, totalelements):
strings = map(lambda x: x.text, mediadata[z].findall('string'))
keys = map(lambda x: x.text, mediadata[z].findall('key'))
integers = map(lambda x: x.text, mediadata[z].findall('integer'))
#print "iTunes: " + str(strings[-1].replace("%20", " ").replace("file://", ""))
for mediaint in mediaintlist:
if str(mediaint) in integers:
if ("Movie" in keys):
if movielist is None:
movielist = str(strings[-1].replace("%20", " ").replace("file://", ""))
else:
movielist = movielist + "," + str(strings[-1].replace("%20", " ").replace("file://", ""))
if movielist is not None:
if "," in movielist:
movielist = movielist.split(",")
movielist.sort(key = lambda k : k.lower())
return movielist
else:
print ""
print "Movie playlist(s) not found. Unable to sync movies."
with open(fullitunesfilename, 'r') as itunes:
tree = ET.parse(itunes)
root = tree.getroot()
print " Getting media list"
mediadata = tree.findall('dict/dict/dict')
print " Getting playlist information"
playlistdata = tree.findall('dict/array/dict')
moviesync = getplaylistcontents()
print " Getting list of TV Shows to sync"
syncfolder = None
for file in moviesync:
path, name = os.path.split(file)
print path
print MOVIEFOLDER
if path is MOVIEFOLDER:
print "Match? Yes"
else:
print "Match? Nope"
这是我的输出:
/Volumes/Data/Media/Movies
/Volumes/Data/Media/Movies
Match? Nope
/Volumes/Data/Media/Movies
/Volumes/Data/Media/Movies
Match? Nope
/Volumes/Data/Media/Movies
/Volumes/Data/Media/Movies
Match? Nope
真的很有趣,如果我使用os.walk(MOVIEFOLDER)并将路径与MOVIEFOLDER进行比较,那么它就可以了。
为什么这不匹配?它们在屏幕上看起来完全一样。我尝试将两者放在str()中,但这并没有帮助。有什么想法吗?