2011-03-04, 02:40
Hi there,
I wrote my first script as a learning experience for Python and so far it's been a GREAT tool for learning. Right now it is just designed to be run from a command line or from the interpreter because the results simply get printed on screen.
This script is for XBMC users. It essentially provides the tools to compare the video files that you have in a particular folder with what is stored in the XBMC database, and lets you know if anything is missing. It identifies unscraped files.
Right now, it works as advertised but I am not sure if it will work with a network path i.e., Samba. Will os.walk(//samba/path) work? I also don't have anything built in to identify and/or correct errors.
I would greatly appreciate any feedback and/or testing that people could provide.
It is in a very basic form, only uses two quick GUI elements to allow the user to select first the directory they want to check, and secondly the location of their XBMC database. My future goals with this app are as follows:
-Make a singular GUI interface that looks something like this:
[BOX TO PICK DIRECTORY ]
[BOX TO IDENTIFY XBMC VIDEO DATABASE]
[] .avi
[] .mkv
...etc (checkboxes to select video types to look for)
-Output results to a file
-Identify the OS that you are on and have a default database location
-Eventually turn it into an XBMC addon that will allow you to manually scrape the missing files
I wrote my first script as a learning experience for Python and so far it's been a GREAT tool for learning. Right now it is just designed to be run from a command line or from the interpreter because the results simply get printed on screen.
This script is for XBMC users. It essentially provides the tools to compare the video files that you have in a particular folder with what is stored in the XBMC database, and lets you know if anything is missing. It identifies unscraped files.
Right now, it works as advertised but I am not sure if it will work with a network path i.e., Samba. Will os.walk(//samba/path) work? I also don't have anything built in to identify and/or correct errors.
I would greatly appreciate any feedback and/or testing that people could provide.
It is in a very basic form, only uses two quick GUI elements to allow the user to select first the directory they want to check, and secondly the location of their XBMC database. My future goals with this app are as follows:
-Make a singular GUI interface that looks something like this:
[BOX TO PICK DIRECTORY ]
[BOX TO IDENTIFY XBMC VIDEO DATABASE]
[] .avi
[] .mkv
...etc (checkboxes to select video types to look for)
-Output results to a file
-Identify the OS that you are on and have a default database location
-Eventually turn it into an XBMC addon that will allow you to manually scrape the missing files
Code:
"""Provides functions for comparing the XBMC video database against the
contents of a path.
This module has two primary functions. pathList() scans a directory recursively
looking for video files, dbList() queries the XBMC video database for video
file names. The two can then be compared, which will reveal which files are
not scraped.
It also contains requestPath() and requestDb() which provide GUIs for selecting
a directory and database path to compare.
"""
__author__ = "Pasquale Ranalli"
__version__ = "0.1"
__maintainer__ = "Pasquale Ranalli"
__email__ = "[email protected]"
__status__ = "Development"
import os
import sqlite3
from Tkinter import Tk
from tkFileDialog import askopenfilename, askdirectory
VIDEOTYPES = ('.avi','.mpg','.mkv','.mpeg','.mp4','.wmv','.iso','.vob',\
'.m2v','.ts')
def path_list(path):
"""Takes a path in the form of a string and returns its file contents as a
list."""
# Walks recursively through the specified path and pulls files of type
# "videotypes" only. os.walk places a list of file names, per directory,
# in the [2] position of a tuple. This data is extracted and returned.
#
# Future revisions will turn each entry of "videotypes" into a series of
# check boxes.
filelist = []
for file in os.walk(path):
for items in file[2]:
if items.endswith(VIDEOTYPES):
filelist.append(items)
return filelist
def db_list(dblocation):
""" Takes an XBMC video database location, as a string, and returns all of
the video filenames it contains in the form of a list.
Standard XBMC Video Database Locations:
Win XP: C:\\Documents and Settings\\[user]\\Application Data\\XBMC\\
Win Vista/7: C:\\Users\\[user]\\AppData\\Roaming\\XBMC\\userdata\\Database\\
Linux: $HOME/.xbmc/userdata/
"""
database = sqlite3.connect(dblocation)
cursor = database.cursor()
cursor.execute('SELECT strFilename FROM files')
datalist = []
for row in cursor:
datalist.append(row[0])
return datalist
def request_db():
"""Provides a graphical file browser for the user to specify the location
of their XBMC database.
"""
root = Tk()
response = askopenfilename\
(title="Choose your XBMC Video Database (MyVideos34.db)",\
filetypes=[("allfiles","*"),("dbfiles","*.db*")])
root.destroy()
return response
def request_path():
"""Provides a graphical directory browser for the user to specify a
desired folder.
"""
root = Tk()
response = askdirectory(title="Select the folder containing \
your video files")
root.destroy()
return response
if __name__ == '__main__':
folder = request_path()
db = request_db()
filelist = path_list(folder)
xbmclist = db_list(db)
# Compares what is in the filelist to what is in the XBMC Database and
# prints any files missing from the db.
#
# Future revision will generate a results file.
for item in filelist:
if item not in xbmclist:
print item