I'm writing a script to build nfo files from contents of an mp4 file. I'm using the itunes.xml file to find items on a playlist, then search the XML to convert the item number to the location. That works fine. My problem is when I try to see if "path" and "MOVIEFOLDER" match. By the screen it looks like it does, but programmatically it doesn't.
Here is my code:
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"
Here is my output:
/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
What's really funny, if I use os.walk(MOVIEFOLDER) and compare path to MOVIEFOLDER it works.
Why doesn't this match? They look exactly the same on the screen. I tried putting both within str(), but that didn't help. Any ideas?