1

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?

Brian
  • 93
  • 1
  • 11
  • Your are using `path is ..` instead of `path == ...`. Isn't that your problem? – Guedes Nov 28 '17 at 01:14
  • That's it!!! Thank you so much, I was pulling my hair out. Having said that, what is the difference between using "is" and "==" besides the obvious that one way worked and the other didn't. lol! – Brian Nov 28 '17 at 01:48
  • Maybe will could be interested in this: https://stackoverflow.com/questions/132988/is-there-a-difference-between-and-is-in-python – Guedes Nov 30 '17 at 22:59

0 Answers0