Videos can now be added. Still missing caching of current track and passing of the start-argument to integrate properly

This commit is contained in:
nikolark committed 2011-05-19 03:53:35 +02:00
1 parent 502e45c5f2
commit 06a9336f8e
8 files changed
+46 -21

No files matched your search

+1
View File
@@ -0,0 +1 @@
[{"pk": 1, "model": "tracks.lastfmuser", "fields": {"active": true, "name": "kakdns"}}, {"pk": 1, "model": "tracks.youtubevideo", "fields": {"active": true, "start": 0, "artist": "Nero", "videoId": "bE47er6qnqg", "title": "Me & You - Original Mix"}}]
File renamed without changes.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

+7 -10
View File
@@ -15,11 +15,12 @@
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: 'u1zgFlCw8Aw',
controls: 0,
border: 0,
height: '600',
width: '1066',
videoId: 'bE47er6qnqg',
playerVars: {
controls: 0
},
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
@@ -30,19 +31,15 @@
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.playVideo();
// stop timer
}
// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.ENDED) {
// restart timer
}
}
function stopVideo() {
player.stopVideo();
}
</script>
</body>
</html>
@@ -1,12 +1,12 @@
{% if now_playing %}
{% if now_playing.video %}
<iframe src="{{ now_playing.video }}" width="100%" height="100%" />
<iframe src="http://www.youtube.com/embed/{{ now_playing.video.videoId }}?enablejsapi=1" frameborder="0" width="1066px" height="600px" />
{% else %}
{% if now_playing.image %}
<img src="{{ now_playing.image}}" class="now_playing" /><br />
{% endif %}
{% endif %}
<img src="{{ MEDIA_URL}}eq.gif" /> {{ now_playing.artist}} - {{ now_playing.title }} ♪♫<br />
<img src="{{ MEDIA_URL}}spectrum-analyzer.gif" /> {{ now_playing.artist}} - {{ now_playing.title }} ♪♫<br />
{% else %}
<img src="{{ MEDIA_URL}}no_music_makes_me_sick_by_sakgaa.jpg" /><br />
:[
+7 -1
View File
@@ -1,4 +1,4 @@
from oliver_screen.tracks.models import LastFMUser
from oliver_screen.tracks.models import LastFMUser, YouTubeVideo
from django.contrib import admin
class LastFMAdmin(admin.ModelAdmin):
@@ -6,4 +6,10 @@ class LastFMAdmin(admin.ModelAdmin):
(None, {'fields': ['name','active']})
]
class VideoAdmin(admin.ModelAdmin):
fieldsets = [
(None, {'fields': ['title','artist', 'videoId', 'start', 'active']})
]
admin.site.register(LastFMUser, LastFMAdmin)
admin.site.register(YouTubeVideo, VideoAdmin)
+17 -6
View File
@@ -4,13 +4,24 @@ from django.db import models
#
class LastFMUser(models.Model):
name = models.CharField(max_length=200)
ACTIVE_CHOICES = (
('yes', 'Yes'),
('no', 'No'),
)
active = models.CharField(choices=ACTIVE_CHOICES, max_length=3)
active = models.BooleanField()
def __unicode__(self):
if self.active == "yes":
if self.active:
return self.name + ": active"
return self.name + ": NOT active"
class YouTubeVideo(models.Model):
title = models.CharField(max_length=200)
artist = models.CharField(max_length=200)
videoId = models.CharField(max_length=200)
start = models.IntegerField()
active = models.BooleanField()
def __unicode__(self):
if self.active:
return self.artist + " - " + self.title + ": active"
return self.artist +" - " + self.title + " : NOT active"
# TODO: cache current track. avoids overwriting video-iframe if the song is still the same.
+12 -2
View File
@@ -2,7 +2,7 @@ from django.http import HttpResponse
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from oliver_screen.tracks.models import LastFMUser
from oliver_screen.tracks.models import LastFMUser, YouTubeVideo
import pylast
from datetime import datetime
@@ -11,13 +11,22 @@ from oliver_screen import settings
network = pylast.LastFMNetwork(api_key = settings.LASTFM_API_KEY, api_secret = settings.LASTFM_API_SECRET)
def get_lastfmuser():
lastfmusers = LastFMUser.objects.filter(active='yes')
lastfmusers = LastFMUser.objects.filter(active=True)
if len(lastfmusers) != 1:
# default
return network.get_user('kakdns')
return network.get_user(lastfmusers[0].name)
def get_youtubevideo(artist, title):
videos = YouTubeVideo.objects.filter(artist=artist, title=title)
if len(videos) != 1:
# should only be one
return ""
return videos[0]
# My views
def get_last_track(request):
user = get_lastfmuser()
@@ -38,6 +47,7 @@ def get_now_playing(request):
video = ""
if not track is None:
artist = track.get_artist()
video = get_youtubevideo(artist.get_name(), track.get_title())
image = artist.get_images(limit=1)
if len(image) > 0:
image = image[0].sizes.original