Archigos 0 Newbie Poster

Below is code that I'm using that essentially creates fake *.avi files and puts them in a directory structure so that they can be later added into a database. The whole purpose of this is to be able to index the files without the risk of screwing up the originals.
The code copied here will not run correctly for others because I have removed the original API key, if it is absolutely needed to help me with my problem then I can provide it as needed.

import urllib
import os
import openAnything
from xml.dom import minidom

def parseShow(seriesID, show_name):
    safe_show_name = show_name.replace(":", "")
    details_url = "http://thetvdb.com/api/REMOVED FOR PRIVACY/series/"+seriesID+"/all/en.xml"
    details = openAnything.fetch(details_url)
    details_xml = minidom.parseString(details['data'])
    seasons = details_xml.getElementsByTagName("SeasonNumber")
    episodes = details_xml.getElementsByTagName("EpisodeNumber")
    # check to see if parent show path needs to be made
    if not os.access(safe_show_name, os.F_OK):
        os.makedirs(safe_show_name)
    i = 0
    for item in episodes:
        season = seasons[i].firstChild.data
        episode = item.firstChild.data
        filename = episode+".avi"
        # seeif season path exists or not, and make it if not
        if os.access(safe_show_name + "\\Season " + season, os.F_OK):
            # just go ahead and create the file
            file = open(safe_show_name + "\\Season " + season + "\\" + filename, "w")
            file.close()
        else:
            os.makedirs(safe_show_name + "\\Season " + season)
            file = open(safe_show_name + "\\Season " + season + "\\" + filename, "w")
            file.close()
        print "Creating %s" % filename
        i = i + 1
        
show_file = open("shows.txt")
shows = show_file.read().split("\n")
show_file.close()
for item in shows:
    show_url = "http://thetvdb.com/api/GetSeries.php?"+urllib.urlencode({"seriesname":item})
    print "Building "+item+"..."
    show_xml = openAnything.fetch(show_url)
    xmldoc = minidom.parseString(show_xml['data'])
    node = xmldoc.getElementsByTagName("seriesid")
    if ("node" in dir()):
        seriesID = node[0].firstChild.data
        parseShow(seriesID, item)
    else:
        print "Could not find any data for "+show_name+" on TVDB.\nURL: "+show_url

In this example, I'm running this from the root of my G drive, so the end results would be:
G:\TV Show Name\Season #\$.avi
(Where, TV Show Name=Correct name, #=season number, $=episode number
Ex. G:\7 Days\Season 1\1.avi)
The problem I'm having is that I need it to be a 2 digit season and episode number
Ex. G:\7 Days\Season 01\01.avi but I don't want to just stick a 0 before each number because most shows have more then 10 episodes each season and some shows have more then 10 seasons.

Any help would be greatly appreciated.
Archigos

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.