support caching local files, lookup by oshash
This commit is contained in:
parent
81ade83945
commit
b121b58a86
4 changed files with 65 additions and 18 deletions
|
@ -711,6 +711,16 @@ class Stream(models.Model):
|
|||
_self.update_status(ok, error)
|
||||
return _self
|
||||
|
||||
def get_index(self):
|
||||
index = 1
|
||||
for s in self.file.item.streams():
|
||||
if self.source and self.source == s:
|
||||
return index
|
||||
if s == self:
|
||||
return index
|
||||
index += 1
|
||||
return None
|
||||
|
||||
def update_status(self, ok, error):
|
||||
if ok:
|
||||
if not self.media:
|
||||
|
|
|
@ -668,13 +668,19 @@ def getMediaInfo(request, data):
|
|||
returns {
|
||||
item: string, // item id
|
||||
file: string // oshash of source file
|
||||
resolution: int // stream resolution
|
||||
index: int // stream index
|
||||
}
|
||||
'''
|
||||
f = None
|
||||
resolution = None
|
||||
index = None
|
||||
qs = models.Stream.objects.filter(oshash=data['id'])
|
||||
if qs.count() > 0:
|
||||
s = qs[0]
|
||||
f = s.file
|
||||
resolution = s.resolution
|
||||
index = s.get_index()
|
||||
else:
|
||||
qs = models.File.objects.filter(oshash=data['id'])
|
||||
if qs.count() > 0:
|
||||
|
@ -685,6 +691,10 @@ def getMediaInfo(request, data):
|
|||
'file': f.oshash,
|
||||
'item': f.item.public_id
|
||||
}
|
||||
if resolution:
|
||||
response['data']['resolution'] = resolution
|
||||
if index:
|
||||
response['data']['index'] = index
|
||||
return render_to_json_response(response)
|
||||
actions.register(getMediaInfo)
|
||||
|
||||
|
|
|
@ -134,17 +134,41 @@ pandora.ui.cacheDialog = function() {
|
|||
.appendTo($item),
|
||||
|
||||
$fileButton = Ox.FileButton({
|
||||
title: 'Select Video...',
|
||||
title: 'Select Videos...',
|
||||
width: 128,
|
||||
disabled: pandora.user.ui.section != 'items'
|
||||
|| pandora.user.ui.item == ''
|
||||
|| !!pandora.fs.getVideoURL(pandora.user.ui.item, pandora.user.ui.videoResolution, 1)
|
||||
disabled: false,
|
||||
})
|
||||
.css({
|
||||
margin: '8px'
|
||||
})
|
||||
.bindEvent({
|
||||
click: selectVideo
|
||||
click: function selectVideos(data) {
|
||||
$fileButton.options({disabled: true});
|
||||
var files = [];
|
||||
for (var i = 0; i < data.files.length; i++) {
|
||||
files.push(data.files[i]);
|
||||
}
|
||||
Ox.serialForEach(files, function(blob, index, array, next) {
|
||||
Ox.oshash(blob, function(oshash) {
|
||||
pandora.api.getMediaInfo({id: oshash}, function(result) {
|
||||
var index = parseInt(result.data.index || 1);
|
||||
if (result.data.item && result.data.resolution) {
|
||||
pandora.fs.cacheBlob(blob, result.data.item, result.data.resolution, index, function(response) {
|
||||
next();
|
||||
});
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
});
|
||||
});
|
||||
}, function() {
|
||||
$fileButton.options({disabled: false});
|
||||
getCachedVideos(function(files) {
|
||||
cachedVideos = Ox.api(files);
|
||||
$list.reloadList(true);
|
||||
});
|
||||
});
|
||||
}
|
||||
})
|
||||
.appendTo($item),
|
||||
|
||||
|
@ -310,17 +334,6 @@ pandora.ui.cacheDialog = function() {
|
|||
});
|
||||
}
|
||||
|
||||
function selectVideo(data) {
|
||||
var blob = data.files[0],
|
||||
name = pandora.fs.getVideoName(pandora.user.ui.item, pandora.user.ui.videoResolution, 1);
|
||||
pandora.fs.storeBlob(blob, name, function() {
|
||||
getCachedVideos(function(files) {
|
||||
cachedVideos = Ox.api(files);
|
||||
cachedVideos(data, callback);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function updateActiveDownloads() {
|
||||
pandora.fs.getVideos(function(files) {
|
||||
files.forEach(function(file) {
|
||||
|
|
|
@ -170,6 +170,20 @@ pandora.fs = (function() {
|
|||
|
||||
};
|
||||
|
||||
that.cacheBlob = function(blob, id, resolution, index, callback) {
|
||||
var key = id[0] + '/' + id + '::' + resolution,
|
||||
name = that.getVideoName(id, resolution, index);
|
||||
createTree(key, function(folder) {
|
||||
that.storeBlob(blob, name[0] + '/' + name, function(response) {
|
||||
if (response.progress == -1) {
|
||||
callback(response);
|
||||
} else {
|
||||
that.storeBlob(new Blob(['ok']), key + '/done', callback);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
that.getVideoName = function(id, resolution, part, track) {
|
||||
return pandora.getVideoURLName(id, resolution, part, track).replace(id + '\/', id + '::' + resolution + '/');
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue