import os
      import shutil
      import subprocess
      import time
      import datetime

      # **The podhome variable will need to be set and the script expects an RSS file named pmoney.rss

      episodes = {}
      podcasts = {}

      podhome="/{location of MP3 files}/PlanetMoney"

      def gettheepisodes(fileinname):
          filein = open(fileinname, 'r')
          line = filein.readline();

          while (line != ''):
               #print("****************************************************************************")
               #print(line)
               linesplit = line.split('#')
               if len(linesplit) > 1:
                  for num in range(1, len(linesplit)):
                      target = linesplit[num]
                      #print(target)
                      charcount = 0
                      bfound = False
                      for char in target:
                          charcount += 1
                          if char == "<" and not bfound:
                              bfound = True
                              episode = target[:charcount - 1]
                              #print(episode)
                              episodesplit = episode.split(':')
                              if len(episodesplit) > 1:
                                  episodes[episodesplit[0]] = episodesplit[1].strip()
                              else:
                                  print("error---" + episodesplit[0])


               line = filein.readline()

      def getthepodcasts():
          ts = time.time()
          st = datetime.datetime.fromtimestamp(ts).strftime('%Y_%m_%d__%H_%M_%S')
          fileoutname = st + '_podcasttitles.txt'
          fileout = open(fileoutname, 'w')
          for filename in os.listdir(podhome):
              if filename.endswith(".mp3"):
                   #print   filename
                   podcastfilename = filename
                   itemsplit = podcastfilename.split('pmpod')
                   #print itemsplit
                   if len(itemsplit)>1:
                       episodenum = ''
                       bfound = False
                       for char in itemsplit[1]:
                           if not bfound:
                               if char == 'v' or char == '.':
                                   bfound = True
                               else:
                                  episodenum += char
                   episodename = episodenum + "_" + episodes.get(episodenum, "not found")
                   #print episodenum, episodename
                   subprocess.call(["mp3info", "-t" ,episodename,podcastfilename ])
                   fileout.write(episodename + '\n')
          fileout.close()

      gettheepisodes('pmoney.rss')
      #print episodes
      #print episodes.keys()
      getthepodcasts()