Skip to content

Instantly share code, notes, and snippets.

@jrhames
Created August 10, 2010 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrhames/517992 to your computer and use it in GitHub Desktop.
Save jrhames/517992 to your computer and use it in GitHub Desktop.
Moovr reads the movingpictures (a Media Portal Plugin - http://code.google.com/p/moving-pictures/) database and generates a movie list in HTML that you can share with your friends.
'''
Moovr 0.1
by Jr. Hames
http://github.com/jrhames
DESCRIPTION:
Moovr reads the movingpictures (a Media Portal Plugin - http://code.google.com/p/moving-pictures/) database and generates a movie list in HTML that you can share with your friends.
LICENSE:
This software is distribute under Creative Commons Attribution-Noncommercial-Share Alike 3.0. You can read the entire license on: http://creativecommons.org/licenses/by-nc-sa/3.0/
'''
import sqlite3
import os
import hashlib
from shutil import copyfile
APPDATA = r'C:\Documents and Settings\All Users\Application Data\Team MediaPortal\MediaPortal'
MOVIES = []
class Movie:
id = None
path = None
resolution = None
audio = None
subtitles = None
title = None
imdb = None
cover = None
def get_hash(self):
name = self.path
readsize = 64 * 1024
with open(name, 'rb') as f:
size = os.path.getsize(name)
data = f.read(readsize)
f.seek(-readsize, os.SEEK_END)
data += f.read(readsize)
return hashlib.md5(data).hexdigest()
def __init__(self, id, path, resolution, audio, subtitles):
self.id = id
self.path = path
self.resolution = resolution
self.audio = audio
self.subtitles = subtitles
def escape(string):
string = string.replace(r"'", r"\'").replace('\n', ' ')
return string
def get_movies():
global MOVIES
db_file = os.path.join(APPDATA, r'database\movingpictures.db3')
if not os.path.isfile(db_file):
return
conn = sqlite3.connect(db_file)
query = conn.cursor()
query.execute("select * from local_media order by substr(fullpath,3)")
for movie in query:
tmp = Movie(movie[0], #id
escape(movie[1]), #path
escape(movie[12]), #resolution
escape(movie[16]) + ' ' + escape(movie[17]), #audio
movie[18]) #subtitles
MOVIES.append(tmp)
conn.close()
def get_info():
global MOVIES
db_file = os.path.join(APPDATA, r'database\movingpictures.db3')
if not os.path.isfile(db_file):
return
conn = sqlite3.connect(db_file)
query = conn.cursor()
for movie in MOVIES:
query.execute("select * from local_media__movie_info where local_media_id = '%s'" % movie.id)
id = query.fetchone()[1]
query.execute("select * from movie_info where id = '%s'" % id)
info = query.fetchone()
movie.title = info[1]
movie.imdb = escape(info[18])
movie.cover = info[21]
conn.close()
def header(file):
file.write('''
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
<title>Movie List</title>
<style>
body {
font-family:"Arial";
font-size:9pt;
background:#000;
color:#eee;
}
a.movie:link {
opacity:.5;
width:175px;
height:270px;
}
a.movie:hover, a.movie:active {
opacity:1;
}
a img {
border:none;
border-style:none;
}
div#movie_info {
display:block;
position:fixed;
top:0px;
right:0px;
padding:2px;
background:#333;
color:#fff;
font-weight:bold;
}
</style>
<script type="text/javascript">
function $(id) { return document.getElementById(id); }
function details(title, res, audio, subs) {
d = $('movie_info');
d.innerHTML = title + " [" + res + ", " + audio + ((subs > 0) ? ', with subtitle' : '') + "]";
}
</script>
</head>
<body>
<h1>Movie List</h1>
''')
def generate_list():
global MOVIES
#create dirs/files
if not os.path.isdir('./movielist/images'):
os.mkdir('./movielist')
os.mkdir('./movielist/images')
file = open('./movielist/index.html', 'w')
header(file)
last_movie = ""
for movie in MOVIES:
coverpath, cover = os.path.split(movie.cover)
if last_movie == cover:
continue
last_movie = cover
copyfile(movie.cover, './movielist/images/' + cover)
file.write('''
<a class="movie" href="http://www.imdb.com/title/%s/" title="%s" onmouseover="details('%s','%s', '%s', '%s')"><img src="images/%s" /></a>
''' % (movie.imdb, movie.title, escape(movie.title), movie.resolution, movie.audio, movie.subtitles, cover))
footer(file)
def footer(file):
file.write('''
<div id="movie_info"></div>
</body>
</html>
''')
if __name__ == '__main__':
get_movies()
get_info()
generate_list()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment