Where possible you should avoid importing things unless you really really need them. It's hard to keep it consistent because of the differences between the PMS versions across different OSes. Some use the built-in python (I think OSX does this), others use a bundled version of python (Windows?) .. which means you may not always have the modules available on all platforms.
What are you trying to do with these URLs shopgirl? You can usually use built-in framework type stuff to get a lot of things done without it being too painful as far as parsing URLs.
That consistency and whether the modules were supported was my concern. I still wonder about the splitext command since it uses os.path so you are also supposed to specify a path. I tested this function by cutting it out of my code and making it a separate Python file and running it locally in the Python GUI I have installed on my computer . And when I ran it locally, I had to include the following lines to the beginning of my code to get the modules to work:
from urlparse import urlparse
from os import path
from ntpath import splitext
BTW, is there an easy way for me to run python code directly through my PMS server so I could see print commands and error messages? Maybe through the URL of the server (http://localhost:32400/) or a command prompt. If I want to add a specialized Python function to the code of a channel, it would be nice to know that I could test it out by just saving that particular function as a python file and run it separately from the rest of the channel code through the Plex Media Server.
Basically the reason I was using these modules was to create a corresponding XML video info file for URLs that were passed through my URL Service. I just looked back at the Plex API documentation and couldn't find anything that appears to help you manipulate the URL itself.
I had found that for every HTML page that played a video on the site that I am building the channel for, there was a corresponding XML video info file with the same file name that provided all the data I needed to collect in the URL Service including the exact location of the video file. So, I knew if I could figure out a way to take the user defined HTML video page that was passed to my URL service and create the corresponding XML video info page, then I would be able to easily use XMLElementforURL to pull out all the info I needed. But the XML video info pages are in a separate double layered directory called /xml/video-page/ .
So for example a video page that has a URL of:
http://www.lstudio.com/web-therapy/season-4-morals-to-the-max.html
has a corresponding video info xml page at:
http://www.lstudio.com/xml/video-page/web-therapy/season-4-morals-to-the-max.xml
So I used the urlparse command from the Python module urlparse to cut the "page" or folder and filename (web-therapy/season-4-morals-to-the-max.html) out of the URL and then added that to a constant variable I gave a value of http://www.lstudio.com/xml/video-page. Then I used the splitext command from the os.path module to change the extension from .html to .xml.
I then tested the function by making it a separate python file and using my locally installed Python GUI and used some print commands at different points in the function to make sure it was changing the value properly through all the steps.