Skip to content

seblu/xbmc-script-sort-movies-by-file-date

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Purpose

This script will re-sort your Media Libraries by looking at the timestamps on your files.

The main use case for this would be to run this after you reset your XBMC Library and all of your media are now sorted alphabetically instead of by the date you added the files to your library.

This was inspired by my own personal needs, and apparantly many others on this thread: http://forum.xbmc.org/showthread.php?t=58525

(1/21/2012) Important Note: This plugin is only functional on XBMC 10.x (Dharma), it will not work on 11.x (Eden) at this time. See here for additional discussion on why and what we need to do before this will work on Eden: joemiller#4 (comment)

How to install and run

  • Download a zip file from github by clicking on the Downloads link on the github page at https://github.com/joemiller/xbmc-script-sort-movies-by-file-date

  • Unzip the contents of the zip into a directory in your addons folder:

    (Vista,Win7): c:\Users<username>\AppData\Roaming\XBMC\addons\script.sort-media

    For other platforms, find your "special://home" path in the wiki: http://wiki.xbmc.org/?title=Special_protocol

  • Launch XBMC

  • Go into "Programs"

  • Execute "Sort Media Library"

  • Re-launch XBMC (not required, but a good idea to reload the database)

This script should only be ran once, after you create your media Library for the first time (or after you reset your library.), since all future media added to the library will be added in the correct chronological order.

How it works

First, some background: The XBMC Libraries are contained in a SQLite (or MySQL) database with each resource contained in a row in the respective table. There is no timestamp in the database indicating "Date Added", instead, XBMC simply relies on the order of the rows in the DB. This is why sorting by Date Added looks more like sorting by alphabetical order when you reset your library.

This script changes the order of the resources by modifiying the ID ('idMovie', 'idEpisode' etc.) column in the respective table to be in the same order as the creation-timestamps of the files themselves. The id of the resource is also changed in all the additional join tables, the 'idFile' column is updated in all the required tables.

In order to accomplish this, the first thing the script will do is find the largest id value in the media table. If you have 100 movies, then the largest id will probably be 100. All of the ID's in the 'movie' table will then be shifted from 1-100 to 101-200. The same is done for file ID's ('idFile') in the 'files' table.

Caveats:

  • Warning! I have only done limited testing on this script.

  • It was tested on Windows 7, XBMC 10.0 and Linux, XBMC 10.1

  • All of my movies were stored remotely via SMB. It works for local media, too, but other protocols may or may not work.

  • xbmc.makeLegalFilename() is called on each file returned from XBMC's database before trying to access the file, but this may not work on all platforms. Tested on Windows 7 with remote SMB files and on Linux with local files.

Known Bugs

To-Do

  • better/simpler installation. publish to official xbmc plugin repo
  • support the Music Library, too
  • localize the plugin properly
  • enclose updates in a transaction
  • handle cancel button in progress dialog

Author

Joe Miller - 1/23/2011 www.joeym.net

Michał (Saviq) Sawicz - 4/4/2011 michal@sawicz.net

About

XBMC addon for sorting your Movie Library by the creation date from the movie files

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%