Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Revert "Merge pull request #10 from maihde/channel."

This reverts commit 23c75dc, reversing
changes made to 19c6690.
  • Loading branch information...
commit 71ccae6dece27bba3f0b3d061a9f06e016760e16 1 parent 23c75dc
@netguy204 netguy204 authored
View
14 README.textile
@@ -14,20 +14,6 @@ h1(#install). INSTALLATION
# Enjoy!
-h2. Adding support for auto-generated video thumbnails
-
-# "Download pyffmpeg 2.0":http://pyffmpeg.googlecode.com/files/pyffmpeg-2.0.tar.gz
-
-# Extract pyffmpeg-2.0.tar.gz
-
-# Install the dependencies, on Ubuntu
-
-## sudo apt-get install cython python-numpy libavfilter-dev libavformat-dev libavutil-dev libavcodec-dev libswscale-dev python-dev
-
-## python setup.py build
-
-## sudo python setup.py install
-
h2. License
The server code in this package is to be distributed under the terms of the GPL. The client code is also GPL but with a special attribution exception for the Roku business entity (per their SDK license agreement.)
View
56 server/mymedia.py
@@ -21,13 +21,12 @@
import simplejson
import socket
import sys
+
from eyeD3 import *
from common import *
from PyRSS2Gen import *
from time import time
-import thumbnail
-
from django.template import Template, Context
from django.conf import settings
@@ -283,8 +282,7 @@ def make_addl_link(fname):
link = media_url(config, {'name':to_utf8(path), 'key': key})
if image:
- if os.path.splitext(image)[1] != ".thumbnail":
- image = relpath26(image, base_dir)
+ image = relpath26(image, base_dir)
image = media_url(config, {'name':to_utf8(image), 'key': key, 'res': tuple2str(THB_DIM)})
logging.debug(link)
@@ -345,16 +343,7 @@ def getart(path):
for test_ext in (".jpg", ".jpeg", ".png"):
if os.path.exists(no_ext + test_ext):
return no_ext + test_ext
-
- # create an thumbnail if possible
- thmb = thumbnail.create_thumbnail(path, size="large")
- if thmb != None:
- # Since ROKU caches images based off URL, include mtime of the
- # thumbnail in the image URL
- mtime = int(os.path.getmtime(thmb))
- thmb = os.path.basename(thmb)
- thmb = os.path.splitext(thmb)[0] + "-%s.thumbnail" % (mtime)
- return thmb
+ return None
if is_photo(path):
return path
@@ -615,7 +604,7 @@ def getdoc(key, path, base_dir, dirrange, config, recurse=False):
range = ""
doc = RSSDoc(
- title="A Personal %s Feed" % key.capitalize(),
+ title="A Personal Music Feed",
link="%s/feed?key=%s&dir=%s%s" % (key, server_base(config), relpath26(path, base_dir), range),
description="My Media",
lastBuildDate=datetime.datetime.now(),
@@ -805,38 +794,21 @@ class MediaHandler:
def GET(self):
song = web.input(name = None, key = None, res = tuple2str(FULL_DIM))
- if not song.name or not song.key:
- raise web.internalerror("missing required parameters")
+ if not song.name:
+ return
config = parse_config(config_file)
- # refuse anything that is an absolute path
- if os.path.isabs(song.name):
+ # refuse anything that isn't in the media directory
+ # IE, refuse anything containing pardir
+ fragments = song.name.split(os.sep)
+ if os.path.pardir in fragments:
logging.warning("SECURITY WARNING: Someone was trying to access %s. The MyMedia client shouldn't do this" % song.name)
- raise web.unauthorized("Cannot access file")
- # if the normalized path doesn't equal the input path,
- # most likely someone is trying to use ".." or other trickery
- # the old approach of searching the path for ".." essentially does the
- # same thing, but hopefully using normpath will help catch edge
- # conditions that were not expected
- if os.path.normpath(song.name) != song.name:
- logging.warning("SECURITY WARNING: Someone was trying to access %s. The MyMedia client shouldn't do this" % song.name)
- raise web.unauthorized("Cannot access file")
+ return
- # The .thumbnail extension means the image is in the ~/.thumbnail directory
name = song.name
+ name = key_to_path(config, song.key, name)
ext = os.path.splitext(os.path.split(name)[1] or "")[1].lower()
- if ext == ".thumbnail":
- name, mtime = name.split("-", 1)
- name = os.path.splitext(name)[0] + ".png"
- # Get the basename since the mtime is only used to keep the roku from caching the file
- # even if the thumbnail is updated
- ext = ".png"
- logging.debug("retrieving image data from thumbnail %s" % name)
- name = os.path.join(thumbnail.THUMBNAIL_DIRECTORY, "large", name)
- else:
- name = key_to_path(config, song.key, name)
-
logging.debug("serving request for %s" % name)
# the .image extension means the image is embedded in an mp3
@@ -854,7 +826,7 @@ def GET(self):
# in all other cases if the file doesn't exist, bail
if not (name and os.path.exists(name)):
logging.debug("file %s doesn't exist" % name)
- raise web.notfound("file %s doesn't exist" % name)
+ return
size = os.stat(name).st_size
@@ -862,7 +834,7 @@ def GET(self):
mimetype = ext2mime(ext)
if not mimetype:
logging.debug("couldn't determine mimetype for %s" % name)
- raise web.internalerror("couldn't determine mimetype for %s" % name)
+ return
logging.debug("guessing mimetype of %s for %s. filesize is %d" % (mimetype, name, size))
View
2  server/rss_template.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0">
<channel>
- <title>MyMedia Feed</title>
+ <title>MyMusic Feed</title>
{% for item in items %}
<item>
<title>{{ item.title }}</title>
View
145 server/thumbnail.py
@@ -1,145 +0,0 @@
-#!/usr/bin/env python
-# Copyright 2011, Michael Ihde
-# Distribute under the terms of the GNU General Public License
-# Version 2 or better
-
-# A python module that helps implement the thumbnail management standard
-# http://jens.triq.net/thumbnail-spec/index.html
-
-import os
-import sys
-import hashlib
-import random
-import binascii
-import mimetypes
-import re
-import tempfile
-import StringIO
-from PIL import Image
-from PIL import PngImagePlugin
-
-try:
- import pyffmpeg
-except ImportError:
- pyffmpeg = None
-
-# Per the specification, this is the only place but if you really
-# want to change THUMBNAIL_DIRECTORY, go ahead
-THUMBNAIL_DIRECTORY = os.path.expanduser("~/.thumbnails")
-NORMAL_SIZE = (128, 128)
-LARGE_SIZE = (256, 256)
-
-# Add some types that don't appear in the default list on some systems
-mimetypes.add_type("video/mp4", ".m4v")
-
-def create_thumbnail(filename, size="normal"):
- # TODO If path is in THUMBNAIL_DIRECTORY, don't create a thumbnail
-
- mimetype = mimetypes.guess_type(filename)[0]
-
- uri = "file://%s" % os.path.normpath(os.path.abspath(filename))
- m = hashlib.md5()
- m.update(uri)
- hashedname = binascii.hexlify(m.digest())
- if size == "normal":
- res = NORMAL_SIZE
- elif size == "large":
- res = LARGE_SIZE
- else:
- raise ValueError, "Invalid Size"
-
- outfile = os.path.join(THUMBNAIL_DIRECTORY, size, hashedname + ".png")
-
- # Determine if we really need to recreate a thumbnail
- if os.path.exists(outfile):
- stat = os.stat(filename)
- im = Image.open(outfile)
- try:
- thmb_mtime = int(im.info["Thumb::MTime"])
- except KeyError:
- pass
- except ValueError:
- pass
- else:
- if (int(stat.st_mtime) == thmb_mtime):
- return outfile
-
-
- data = None
- if re.match("video/\.*", mimetype):
- data = create_video_thumbnail(filename)
-
- if data == None:
- return
- # The temporary file should be placed into the same directory as the final
- # thumbnail, because then you are sure that they lay on the same
- # filesystem. This guarantees a fast renaming of the temporary file.
- tmp_output = None
- try:
- if data != None:
- tmp_fd, tmp_path = tempfile.mkstemp(prefix=hashedname, suffix="-tmp.png" , dir=THUMBNAIL_DIRECTORY)
- tmp_output = os.fdopen(tmp_fd, "w")
- tmp_output.write(data)
- finally:
- if tmp_output != None:
- tmp_output.close()
-
- stat = os.stat(filename)
-
- info = {"Thumb::URI": uri,
- "Thumb::MTime": int(stat.st_mtime),
- "Thumb::Size": stat.st_size,
- "Thumb::Mimetype": mimetype}
-
- if not os.path.exists(tmp_path):
- print "Failure to create thumbnail"
- return None
-
- generate_png_thumb(tmp_path, res, info=info)
-
- if os.path.exists(tmp_path):
- os.rename(tmp_path, outfile)
-
- return outfile
-
-def create_video_thumbnail(filename):
- if pyffmpeg == None:
- return None
- reader = pyffmpeg.FFMpegReader(False)
- reader.open(filename, pyffmpeg.TS_VIDEO_PIL)
- vt=reader.get_tracks()[0]
- # Pick something near the middle, the very start and very ends aren't
- # usually very interesting
- s = int(vt.duration() * 0.25)
- f = int(vt.duration() * 0.75)
- i = random.randint(s, f)
- vt.seek_to_pts(i)
- image=vt.get_current_frame()[2]
- output = StringIO.StringIO()
- image.save(output, "PNG")
- return output.getvalue()
-
-def generate_png_thumb(filename, res, info={}):
- """
- Uses code from public domain, Nick Galbreath
- http://blog.modp.com/2007/08/python-pil-and-png-metadata-take-2.html
- """
- print filename
- im = Image.open(filename)
- im.thumbnail(res)
-
- # these can be automatically added to Image.info dict
- # they are not user-added metadata
- reserved = ('interlace', 'gamma', 'dpi', 'transparency', 'aspect')
-
- meta = PngImagePlugin.PngInfo()
- for k,v in info.items():
- meta.add_text(k, str(v), 0)
-
- # 8-bit, non-interlaced, PNG with full alpha transparency
- im.save(filename, "PNG", pnginfo=meta)
-
-if __name__ == "__main__":
- for f in sys.argv[1:]:
- outfile = create_thumbnail(os.path.abspath(f))
- print "Created", outfile
Please sign in to comment.
Something went wrong with that request. Please try again.