make youtube videos sort've work

This commit is contained in:
Sanj 2012-12-13 04:02:53 +05:30
parent 8653073d75
commit efa48df80b
3 changed files with 25 additions and 9 deletions

View File

@ -55,7 +55,8 @@ class YoutubeVideo(GalleryItem):
def __unicode__(self):
return self.title
def thumbnail(self):
return "http://i.ytimg.com/vi/%s/default.jpg" % self.youtube_id
#class Video(GalleryItem):
# ...

View File

@ -2,7 +2,7 @@
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.http import HttpResponse, HttpResponseRedirect
from models import GalleryAlbum, GalleryItem, Photo
from models import GalleryAlbum, GalleryItem, Photo, YoutubeVideo
from django.contrib.contenttypes.models import ContentType
from django.views.decorators.csrf import csrf_exempt
from django import forms
@ -63,19 +63,21 @@ def delete_photo(request, id):
def add_youtube(request, id):
gallery = get_object_or_404(GalleryAlbum, pk=id)
url = request.POST.get("url", None)
url = request.GET.get("url", None)
if not url:
return render_to_json_response({'error': 'No URL supplied'})
youtube_id = url.replace("http://youtu.be/", "")
thumbnail = "http://i.ytimg.com/vi/%s/default.jpg" % youtube_id
# info = youtube.info(youtube_id)
yt = YoutubeVideo()
yt = YoutubeVideo(album=gallery)
yt.youtube_id = youtube_id
yt.title = "fixme"
yt.save()
return render_to_json_response({
'title': yt.title
'thumbnail': thumbnail
'id': yt.id,
'title': yt.title,
'thumbnail': yt.thumbnail()
})

View File

@ -55,8 +55,17 @@ $(function() {
$(this).attr("disabled", "disabled");
$(this).text("Adding...");
var url = "/mediagallery/add_youtube/" + GALLERY_ID;
$.post(url, {'url': yt_url}, function(response) {
console.log(response);
$.get(url, {'url': yt_url}, function(data) {
var $ul = $('#youtubeVideos');
var $li = $('<li />')
.attr("data-id", data.id)
.appendTo($ul);
var $img = $('<img />').attr("src", data.thumbnail).appendTo($li);
var $title = $('<div />').addClass("videoTitle").text(data.title).appendTo($li);
var $delete = $('<span />')
.addClass("deleteVideo")
.text("X")
.appendTo($li);
}, "json");
});
@ -111,6 +120,10 @@ $(function() {
<div id="addYoutubeVideos">
Youtube Share Link: <input type="text" id="youtubeURL" placeholder="eg. http://youtu.be/Wo_mFYW-jLU" />
<button id="addYoutubeVideo">Add</button>
<ul id="youtubeVideos">
</ul>
</div>
</div>