2011-01-19, 17:19
Hello Guys
I'm trying to write a script for XBMC that looks in a predefined directory for all folders (music albums), and grabs the folder.jpg in within this folders. It should then display the 6 latest folders (folder.jpg) in xbmc
Unfortunately my Python skills are non-existent and I have no plan how to get things to work. This is what I have come up with so far (google + copy and paste):
This script lists all files and folders chronologically (via last modified), being above the latest items. As you see there isn't any xbmc-specific code, because it's too complex for me at this time.
Are here any skilled python-programmers who could help me with this script ?
Thank you a lot, Dendamin
I'm trying to write a script for XBMC that looks in a predefined directory for all folders (music albums), and grabs the folder.jpg in within this folders. It should then display the 6 latest folders (folder.jpg) in xbmc
Unfortunately my Python skills are non-existent and I have no plan how to get things to work. This is what I have come up with so far (google + copy and paste):
Code:
# retrieve the file information from a selected folder
# sort the folders by last modified date/time and display in order newest folder first
import os, glob, time
# use a folder you have ...
root = 'C:\\Users\\patrik\\Music\\*'
date_folder_list = []
for folder in glob.glob(root):
# retrieves the stats for the current folder as a tuple
# (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime)
# the tuple element mtime at index 8 is the last-modified-date
stats = os.stat(folder)
# create tuple (year yyyy, month(1-12), day(1-31), hour(0-23), minute(0-59), second(0-59),
# weekday(0-6, 0 is monday), Julian day(1-366), daylight flag(-1,0 or 1)) from seconds since epoch
# note: this tuple can be sorted properly by date and time
lastmod_date = time.localtime(stats[8])
#print image_file, lastmod_date # test
# create list of tuples ready for sorting by date
date_folder_tuple = lastmod_date, folder
date_folder_list.append(date_folder_tuple)
date_folder_list.sort()
date_folder_list.reverse() # newest mod date now first
for folder in date_folder_list:
# extract just the foldername
folder_name = os.path.split(folder[1])
# convert date tuple to MM/DD/YYYY HH:MM:SS format
folder_date = time.strftime("%m/%d/%y %H:%M:%S", folder[0])
print "%-40s %s" % (folder_name)
This script lists all files and folders chronologically (via last modified), being above the latest items. As you see there isn't any xbmc-specific code, because it's too complex for me at this time.
Are here any skilled python-programmers who could help me with this script ?
Thank you a lot, Dendamin