Renamer, movie searcher, Library scanning
New theme for UI and more..
This commit is contained in:
@@ -8,7 +8,9 @@ from couchpotato.core.plugins.base import Plugin
|
||||
from couchpotato.core.settings.model import FileType, File
|
||||
from couchpotato.environment import Env
|
||||
from flask.helpers import send_from_directory
|
||||
from sqlalchemy.sql.expression import or_
|
||||
import os.path
|
||||
import traceback
|
||||
import urllib2
|
||||
|
||||
log = CPLog(__name__)
|
||||
@@ -51,15 +53,15 @@ class FileManager(Plugin):
|
||||
|
||||
return dest
|
||||
|
||||
except Exception, e:
|
||||
log.error('Unable to download file "%s": %s' % (url, e))
|
||||
except Exception:
|
||||
log.error('Unable to download file "%s": %s' % (url, traceback.format_exc()))
|
||||
|
||||
return False
|
||||
|
||||
def add(self, path = '', part = 1, type = (), available = 1, properties = {}):
|
||||
db = get_session()
|
||||
|
||||
f = db.query(File).filter_by(path = toUnicode(path)).first()
|
||||
f = db.query(File).filter(or_(File.path == toUnicode(path), File.path == path)).first()
|
||||
if not f:
|
||||
f = File()
|
||||
db.add(f)
|
||||
@@ -78,7 +80,6 @@ class FileManager(Plugin):
|
||||
def getType(self, type):
|
||||
|
||||
db = get_session()
|
||||
|
||||
type, identifier = type
|
||||
|
||||
ft = db.query(FileType).filter_by(identifier = identifier).first()
|
||||
|
||||
@@ -2,6 +2,11 @@ var File = new Class({
|
||||
|
||||
initialize: function(file){
|
||||
var self = this;
|
||||
|
||||
if(!file){
|
||||
self.el = new Element('div');
|
||||
return
|
||||
}
|
||||
|
||||
self.data = file;
|
||||
self.type = File.Type.get(file.type_id);
|
||||
|
||||
@@ -41,9 +41,7 @@ class LibraryPlugin(Plugin):
|
||||
if update_after:
|
||||
fireEventAsync('library.update', identifier = l.identifier, default_title = attrs.get('title', ''))
|
||||
|
||||
library_dict = l.to_dict()
|
||||
|
||||
return library_dict
|
||||
return l.to_dict({'titles': {}, 'files':{}})
|
||||
|
||||
def update(self, identifier, default_title = '', force = False):
|
||||
|
||||
@@ -51,22 +49,27 @@ class LibraryPlugin(Plugin):
|
||||
library = db.query(Library).filter_by(identifier = identifier).first()
|
||||
done_status = fireEvent('status.get', 'done', single = True)
|
||||
|
||||
library_dict = library.to_dict({'titles': {}, 'files':{}})
|
||||
|
||||
if library.status_id == done_status.get('id') and not force:
|
||||
return
|
||||
return library_dict
|
||||
|
||||
info = fireEvent('provider.movie.info', merge = True, identifier = identifier)
|
||||
if not info or len(info) == 0:
|
||||
log.error('Could not update, no movie info to work with: %s' % identifier)
|
||||
return
|
||||
return library_dict
|
||||
|
||||
# Main info
|
||||
library.plot = info.get('plot', '')
|
||||
library.tagline = info.get('tagline', '')
|
||||
library.year = info.get('year', 0)
|
||||
library.status_id = done_status.get('id')
|
||||
db.commit()
|
||||
|
||||
# Titles
|
||||
[db.delete(title) for title in library.titles]
|
||||
db.commit()
|
||||
|
||||
titles = info.get('titles', [])
|
||||
|
||||
log.debug('Adding titles: %s' % titles)
|
||||
@@ -83,6 +86,9 @@ class LibraryPlugin(Plugin):
|
||||
images = info.get('images', [])
|
||||
for type in images:
|
||||
for image in images[type]:
|
||||
if not isinstance(image, str):
|
||||
continue
|
||||
|
||||
file_path = fireEvent('file.download', url = image, single = True)
|
||||
file = fireEvent('file.add', path = file_path, type = ('image', type[:-1]), single = True)
|
||||
try:
|
||||
@@ -94,3 +100,5 @@ class LibraryPlugin(Plugin):
|
||||
#log.debug('Failed to attach to library: %s' % traceback.format_exc())
|
||||
|
||||
fireEvent('library.update.after')
|
||||
|
||||
return library.to_dict({'titles': {}, 'files':{}})
|
||||
|
||||
@@ -22,6 +22,9 @@ class MoviePlugin(Plugin):
|
||||
path = self.registerStatic(__file__)
|
||||
fireEvent('register_script', path + 'search.js')
|
||||
fireEvent('register_style', path + 'search.css')
|
||||
fireEvent('register_script', path + 'movie.js')
|
||||
fireEvent('register_style', path + 'movie.css')
|
||||
fireEvent('register_script', path + 'list.js')
|
||||
|
||||
def list(self):
|
||||
|
||||
@@ -35,7 +38,7 @@ class MoviePlugin(Plugin):
|
||||
movies = []
|
||||
for movie in results:
|
||||
temp = movie.to_dict(deep = {
|
||||
'releases': {'status': {}, 'quality': {}},
|
||||
'releases': {'status': {}, 'quality': {}, 'files':{}},
|
||||
'library': {'titles': {}, 'files':{}},
|
||||
'files': {}
|
||||
})
|
||||
@@ -62,7 +65,13 @@ class MoviePlugin(Plugin):
|
||||
|
||||
if movie:
|
||||
#addEvent('library.update.after', )
|
||||
fireEventAsync('library.update', library = movie.library, default_title = default_title)
|
||||
fireEventAsync('library.update', identifier = movie.library.identifier, default_title = default_title, force = True)
|
||||
fireEventAsync('searcher.single', movie.to_dict(deep = {
|
||||
'profile': {'types': {'quality': {}}},
|
||||
'releases': {'status': {}, 'quality': {}},
|
||||
'library': {'titles': {}, 'files':{}},
|
||||
'files': {}
|
||||
}))
|
||||
|
||||
return jsonified({
|
||||
'success': True,
|
||||
@@ -98,7 +107,7 @@ class MoviePlugin(Plugin):
|
||||
library = fireEvent('library.add', single = True, attrs = params)
|
||||
status = fireEvent('status.add', 'active', single = True)
|
||||
|
||||
m = db.query(Movie).filter_by(library_id = library.id).first()
|
||||
m = db.query(Movie).filter_by(library_id = library.get('id')).first()
|
||||
if not m:
|
||||
m = Movie(
|
||||
library_id = library.get('id'),
|
||||
@@ -108,7 +117,7 @@ class MoviePlugin(Plugin):
|
||||
|
||||
m.status_id = status.get('id')
|
||||
db.commit()
|
||||
|
||||
|
||||
movie_dict = m.to_dict(deep = {
|
||||
'releases': {'status': {}, 'quality': {}},
|
||||
'library': {'titles': {}}
|
||||
@@ -121,7 +130,22 @@ class MoviePlugin(Plugin):
|
||||
})
|
||||
|
||||
def edit(self):
|
||||
pass
|
||||
|
||||
params = getParams()
|
||||
db = get_session();
|
||||
|
||||
m = db.query(Movie).filter_by(id = params.get('id')).first()
|
||||
m.profile_id = params.get('profile_id')
|
||||
|
||||
# Default title
|
||||
for title in m.library.titles:
|
||||
title.default = params.get('default_title').lower() == title.title.lower()
|
||||
|
||||
db.commit()
|
||||
|
||||
return jsonified({
|
||||
'success': True,
|
||||
})
|
||||
|
||||
def delete(self):
|
||||
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
var MovieList = new Class({
|
||||
|
||||
Implements: [Options],
|
||||
|
||||
options: {
|
||||
navigation: true
|
||||
},
|
||||
|
||||
movies: [],
|
||||
|
||||
initialize: function(options){
|
||||
var self = this;
|
||||
self.setOptions(options);
|
||||
|
||||
self.el = new Element('div.movies');
|
||||
self.getMovies();
|
||||
},
|
||||
|
||||
create: function(){
|
||||
var self = this;
|
||||
|
||||
// Create the alphabet nav
|
||||
if(self.options.navigation)
|
||||
self.createNavigation();
|
||||
|
||||
Object.each(self.movies, function(info){
|
||||
var m = new Movie(self, {
|
||||
'actions': self.options.actions
|
||||
}, info);
|
||||
$(m).inject(self.el);
|
||||
m.fireEvent('injected');
|
||||
});
|
||||
|
||||
self.el.addEvents({
|
||||
'mouseenter:relay(.movie)': function(e, el){
|
||||
el.addClass('hover')
|
||||
},
|
||||
'mouseleave:relay(.movie)': function(e, el){
|
||||
el.removeClass('hover')
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
createNavigation: function(){
|
||||
var self = this;
|
||||
var chars = '#ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
var selected = 'Z';
|
||||
|
||||
self.navigation = new Element('div.alph_nav').adopt(
|
||||
self.alpha = new Element('ul.inlay'),
|
||||
self.input = new Element('input.inlay'),
|
||||
self.view = new Element('ul.inlay').adopt(
|
||||
new Element('li.list'),
|
||||
new Element('li.thumbnails'),
|
||||
new Element('li.text')
|
||||
)
|
||||
).inject(this.el, 'top')
|
||||
|
||||
chars.split('').each(function(c){
|
||||
new Element('li', {
|
||||
'text': c,
|
||||
'class': c == selected ? 'selected' : ''
|
||||
}).inject(self.alpha)
|
||||
})
|
||||
|
||||
},
|
||||
|
||||
getMovies: function(status, onComplete){
|
||||
var self = this
|
||||
|
||||
if(self.movies.length == 0)
|
||||
Api.request('movie.list', {
|
||||
'data': {
|
||||
'status': self.options.status
|
||||
},
|
||||
'onComplete': function(json){
|
||||
self.store(json.movies);
|
||||
self.create();
|
||||
}
|
||||
})
|
||||
else
|
||||
self.list()
|
||||
},
|
||||
|
||||
store: function(movies){
|
||||
var self = this;
|
||||
|
||||
self.movies = movies;
|
||||
},
|
||||
|
||||
toElement: function(){
|
||||
return this.el;
|
||||
}
|
||||
|
||||
});
|
||||
@@ -0,0 +1,166 @@
|
||||
/* @override http://localhost:5000/static/movie_plugin/movie.css */
|
||||
|
||||
.movies {
|
||||
padding: 20px 0;
|
||||
}
|
||||
|
||||
.movies .movie {
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
|
||||
border-radius: 4px;
|
||||
-moz-border-radius: 4px;
|
||||
-webkit-border-radius: 4px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
.movies .movie:hover {
|
||||
border-color: #ddd #fff #fff #ddd;
|
||||
}
|
||||
.movies .movie:hover .data {
|
||||
}
|
||||
.movies .data {
|
||||
padding: 2%;
|
||||
position: absolute;
|
||||
width: 96.1%;
|
||||
top: 0;
|
||||
left: 0;
|
||||
|
||||
border-radius: 4px;
|
||||
-moz-border-radius: 4px;
|
||||
-webkit-border-radius: 4px;
|
||||
}
|
||||
.movies .data:after {
|
||||
content: "";
|
||||
display: block;
|
||||
height: 0;
|
||||
clear: both;
|
||||
visibility: hidden;
|
||||
}
|
||||
.movies .data .poster, .options .poster {
|
||||
overflow: hidden;
|
||||
float: left;
|
||||
max-width: 10%;
|
||||
margin: 0 2% 0 0;
|
||||
border-radius:3px;
|
||||
-moz-border-radius: 3px;
|
||||
-webkit-border-radius: 3px;
|
||||
box-shadow: 0 0 10px rgba(0,0,0,0.35);
|
||||
-moz-box-shadow: 0 0 10px rgba(0,0,0,0.35);
|
||||
-webkit-box-shadow: 0 0 10px rgba(0,0,0,0.35);
|
||||
line-height: 0;
|
||||
}
|
||||
|
||||
.movies .info {
|
||||
float: right;
|
||||
width: 88%;
|
||||
}
|
||||
|
||||
.movies .info .title {
|
||||
font-size: 30px;
|
||||
font-weight: bold;
|
||||
margin-bottom: 10px;
|
||||
float: left;
|
||||
width: 80%;
|
||||
}
|
||||
|
||||
.movies .info .year {
|
||||
font-size: 30px;
|
||||
margin-bottom: 10px;
|
||||
float: right;
|
||||
color: #bbb;
|
||||
width: 10%;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.movies .info .rating {
|
||||
font-size: 30px;
|
||||
margin-bottom: 10px;
|
||||
color: #444;
|
||||
float: left;
|
||||
width: 5%;
|
||||
padding: 0 0 0 3%;
|
||||
background: url('../images/rating.png') no-repeat left center;
|
||||
}
|
||||
|
||||
.movies .info .description {
|
||||
clear: both;
|
||||
width: 95%;
|
||||
}
|
||||
.movies .data .actions {
|
||||
position: absolute;
|
||||
right: 15px;
|
||||
bottom: 15px;
|
||||
line-height: 0;
|
||||
}
|
||||
.movies .data:hover .action { opacity: 0.6; }
|
||||
.movies .data:hover .action:hover { opacity: 1; }
|
||||
|
||||
.movies .data .action {
|
||||
background: no-repeat center;
|
||||
display: inline-block;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
padding: 3px;
|
||||
opacity: 0;
|
||||
}
|
||||
.movies .data .action.refresh { background-image: url('../images/reload.png'); }
|
||||
.movies .data .action.delete { background-image: url('../images/delete.png'); }
|
||||
.movies .data .action.edit { background-image: url('../images/edit.png'); }
|
||||
.movies .data .action.imdb { background-image: url('../images/imdb.png'); }
|
||||
|
||||
.movies .delete_container {
|
||||
clear: both;
|
||||
text-align: center;
|
||||
font-size: 20px;
|
||||
position: relative;
|
||||
}
|
||||
.movies .delete_container .cancel {
|
||||
}
|
||||
.movies .delete_container .or {
|
||||
padding: 10px;
|
||||
}
|
||||
.movies .delete_container .delete {
|
||||
background-color: #ff321c;
|
||||
font-weight: normal;
|
||||
}
|
||||
.movies .delete_container .delete:hover {
|
||||
color: #fff;
|
||||
background-color: #d32917;
|
||||
}
|
||||
|
||||
.movies .options .form {
|
||||
margin-top: -2%;
|
||||
float: left;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.movies .options .form select {
|
||||
margin-right: 20px;
|
||||
}
|
||||
|
||||
.movies .options {
|
||||
padding: 2%;
|
||||
}
|
||||
|
||||
.movies .alph_nav ul {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.movies .alph_nav li {
|
||||
display: inline-block;
|
||||
vertical-align: top;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
line-height: 26px;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
margin: 0 -1px 0 0;
|
||||
}
|
||||
|
||||
.movies .alph_nav li:hover, .movies .alph_nav li.onlay {
|
||||
font-weight: bold;
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
var Movie = new Class({
|
||||
|
||||
Extends: BlockBase,
|
||||
|
||||
action: {},
|
||||
|
||||
initialize: function(self, options, data){
|
||||
var self = this;
|
||||
|
||||
self.data = data;
|
||||
|
||||
self.profile = Quality.getProfile(data.profile_id);
|
||||
self.parent(self, options);
|
||||
self.addEvent('injected', self.afterInject.bind(self))
|
||||
},
|
||||
|
||||
create: function(){
|
||||
var self = this;
|
||||
|
||||
self.el = new Element('div.movie.inlay').adopt(
|
||||
self.data_container = new Element('div.data.inlay.light', {
|
||||
'tween': {
|
||||
duration: 400,
|
||||
transition: 'quint:in:out'
|
||||
}
|
||||
}).adopt(
|
||||
self.thumbnail = File.Select.single('poster', self.data.library.files),
|
||||
self.info_container = new Element('div.info').adopt(
|
||||
self.title = new Element('div.title', {
|
||||
'text': self.getTitle()
|
||||
}),
|
||||
self.year = new Element('div.year', {
|
||||
'text': self.data.library.year || 'Unknown'
|
||||
}),
|
||||
self.rating = new Element('div.rating', {
|
||||
'text': self.data.library.rating
|
||||
}),
|
||||
self.description = new Element('div.description', {
|
||||
'text': self.data.library.plot
|
||||
}),
|
||||
self.quality = new Element('div.quality', {
|
||||
'text': self.profile ? self.profile.get('label') : ''
|
||||
})
|
||||
),
|
||||
self.actions = new Element('div.actions')
|
||||
)
|
||||
);
|
||||
|
||||
Object.each(self.options.actions, function(action, key){
|
||||
self.actions.adopt(
|
||||
self.action[key.toLowerCase()] = new self.options.actions[key](self)
|
||||
)
|
||||
});
|
||||
|
||||
if(!self.data.library.rating)
|
||||
self.rating.hide();
|
||||
|
||||
},
|
||||
|
||||
afterInject: function(){
|
||||
var self = this;
|
||||
|
||||
var height = self.getHeight();
|
||||
self.el.setStyle('height', height);
|
||||
},
|
||||
|
||||
getTitle: function(){
|
||||
var self = this;
|
||||
|
||||
var titles = self.data.library.titles;
|
||||
|
||||
var title = titles.filter(function(title){
|
||||
return title['default']
|
||||
}).pop()
|
||||
|
||||
if(title)
|
||||
return title.title
|
||||
else if(titles.length > 0)
|
||||
return titles[0].title
|
||||
|
||||
return 'Unknown movie'
|
||||
},
|
||||
|
||||
slide: function(direction){
|
||||
var self = this;
|
||||
|
||||
if(direction == 'in'){
|
||||
self.el.addEvent('outerClick', self.slide.bind(self, 'out'))
|
||||
self.data_container.tween('left', 0, self.getWidth());
|
||||
}
|
||||
else {
|
||||
self.el.removeEvents('outerClick')
|
||||
self.data_container.tween('left', self.getWidth(), 0);
|
||||
}
|
||||
},
|
||||
|
||||
getHeight: function(){
|
||||
var self = this;
|
||||
|
||||
if(!self.height)
|
||||
self.height = self.data_container.getCoordinates().height;
|
||||
|
||||
return self.height;
|
||||
},
|
||||
|
||||
getWidth: function(){
|
||||
var self = this;
|
||||
|
||||
if(!self.width)
|
||||
self.width = self.data_container.getCoordinates().width;
|
||||
|
||||
return self.width;
|
||||
},
|
||||
|
||||
get: function(attr){
|
||||
return this.data[attr] || this.data.library[attr]
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
var MovieAction = new Class({
|
||||
|
||||
class_name: 'action',
|
||||
|
||||
initialize: function(movie){
|
||||
var self = this;
|
||||
self.movie = movie;
|
||||
|
||||
self.create();
|
||||
self.el.addClass(self.class_name)
|
||||
},
|
||||
|
||||
create: function(){},
|
||||
|
||||
disable: function(){
|
||||
this.el.addClass('disable')
|
||||
},
|
||||
|
||||
enable: function(){
|
||||
this.el.removeClass('disable')
|
||||
},
|
||||
|
||||
toElement: function(){
|
||||
return this.el
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
var IMDBAction = new Class({
|
||||
|
||||
Extends: MovieAction,
|
||||
id: null,
|
||||
|
||||
create: function(){
|
||||
var self = this;
|
||||
|
||||
self.id = self.movie.get('identifier');
|
||||
|
||||
self.el = new Element('a.imdb', {
|
||||
'title': 'Go to the IMDB page of ' + self.movie.getTitle(),
|
||||
'events': {
|
||||
'click': self.gotoIMDB.bind(self)
|
||||
}
|
||||
});
|
||||
|
||||
if(!self.id) self.disable();
|
||||
},
|
||||
|
||||
gotoIMDB: function(e){
|
||||
var self = this;
|
||||
(e).stop();
|
||||
|
||||
window.open('http://www.imdb.com/title/'+self.id+'/');
|
||||
}
|
||||
|
||||
})
|
||||
@@ -1,4 +1,4 @@
|
||||
/* @override http://localhost:5000/static/style/plugin/movie_add.css */
|
||||
/* @override http://localhost:5000/static/movie_plugin/search.css */
|
||||
|
||||
.search_form {
|
||||
display: inline-block;
|
||||
@@ -7,52 +7,46 @@
|
||||
|
||||
.search_form input {
|
||||
padding-right: 25px;
|
||||
border: 1px solid #aaa;
|
||||
padding: 4px;
|
||||
margin: 0;
|
||||
font-size: 14px;
|
||||
width: 90%;
|
||||
|
||||
border-radius: 3px;
|
||||
-webkit-border-radius: 3px;
|
||||
-moz-border-radius: 3px;
|
||||
}
|
||||
.search_form .input a {
|
||||
width: 12px;
|
||||
width: 17px;
|
||||
height: 20px;
|
||||
display: inline-block;
|
||||
margin: 0 0 -5px -20px;
|
||||
top: 4px;
|
||||
right: 5px;
|
||||
background: url('../../images/close_button.png') 0 center no-repeat;
|
||||
background: url('../images/checks.png') right -36px no-repeat;
|
||||
cursor: pointer;
|
||||
}
|
||||
.search_form .input a:hover { background-position: -12px center; }
|
||||
|
||||
.search_form .results_container {
|
||||
padding: 10px 0;
|
||||
position: absolute;
|
||||
background: #fff;
|
||||
margin: 11px 0 0 -243px;
|
||||
background: #5c697b;
|
||||
margin: 6px 0 0 -246px;
|
||||
width: 470px;
|
||||
min-height: 140px;
|
||||
|
||||
box-shadow: 0 0 30px rgba(0,0,0,0.2);
|
||||
-moz-box-shadow: 0 0 30px rgba(0,0,0,0.2);
|
||||
-webkit-box-shadow: 0 0 30px rgba(0,0,0,0.2);
|
||||
|
||||
border-radius: 3px;
|
||||
-webkit-border-radius: 3px;
|
||||
-moz-border-radius: 3px;
|
||||
|
||||
box-shadow: 0 0 50px rgba(0,0,0,0.55);
|
||||
-moz-box-shadow: 0 0 50px rgba(0,0,0,0.55);
|
||||
-webkit-box-shadow: 0 0 50px rgba(0,0,0,0.55);
|
||||
}
|
||||
.search_form .spinner {
|
||||
background: #fff url('../../images/spinner.gif') no-repeat center 70px;
|
||||
background: rgba(0,0,0,0.8) url('../images/spinner.gif') no-repeat center 70px;
|
||||
}
|
||||
|
||||
.search_form .pointer {
|
||||
border-right: 10px solid transparent;
|
||||
border-left: 10px solid transparent;
|
||||
border-bottom: 10px solid #fff;
|
||||
border-bottom: 10px solid #5c697b;
|
||||
display: block;
|
||||
position: absolute;
|
||||
width: 0px;
|
||||
@@ -62,16 +56,24 @@
|
||||
|
||||
.search_form .results .movie {
|
||||
overflow: hidden;
|
||||
background: #666;
|
||||
min-height: 140px;
|
||||
}
|
||||
|
||||
.search_form .results .movie .options {
|
||||
height: 140px;
|
||||
height: 139px;
|
||||
border: 1px solid transparent;
|
||||
border-width: 1px 0;
|
||||
border-radius: 0;
|
||||
-webkit-border-radius: 0;
|
||||
-moz-border-radius: 0;
|
||||
box-shadow: inset 0 1px 8px rgba(0,0,0,0.25);
|
||||
-moz-box-shadow: inset 0 1px 8px rgba(0,0,0,0.25);
|
||||
-webkit-box-shadow: inset 0 1px 8px rgba(0,0,0,0.25);
|
||||
}
|
||||
|
||||
.search_form .results .movie .options > div {
|
||||
padding: 0 15px;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.search_form .results .movie .options .thumbnail {
|
||||
@@ -105,11 +107,17 @@
|
||||
position: relative;
|
||||
min-height: 100px;
|
||||
top: 0;
|
||||
margin: -140px 0 0 0;
|
||||
background: #fff;
|
||||
margin: -143px 0 0 0;
|
||||
min-height: 140px;
|
||||
background: #5c697b;
|
||||
|
||||
border-bottom: 1px solid #333;
|
||||
border-top: 1px solid rgba(255,255,255, 0.15);
|
||||
}
|
||||
|
||||
.search_form .results .movie:first-child .data { border-top: 0; }
|
||||
.search_form .results .movie:last-child .data { border-bottom: 0; }
|
||||
|
||||
.search_form .results .movie .thumbnail {
|
||||
width: 17%;
|
||||
display: inline-block;
|
||||
@@ -129,7 +137,6 @@
|
||||
display: inline-block;
|
||||
vertical-align: top;
|
||||
padding: 15px 0;
|
||||
background: #fff;
|
||||
}
|
||||
.search_form .results .movie .add +.info {
|
||||
margin-left: 20%;
|
||||
|
||||
@@ -9,7 +9,7 @@ Block.Search = new Class({
|
||||
|
||||
self.el = new Element('div.search_form').adopt(
|
||||
new Element('div.input').adopt(
|
||||
self.input = new Element('input', {
|
||||
self.input = new Element('input.inlay', {
|
||||
'events': {
|
||||
'keyup': self.keyup.bind(self),
|
||||
'focus': self.hideResults.bind(self, false)
|
||||
@@ -164,7 +164,7 @@ Block.Search.Item = new Class({
|
||||
self.el = new Element('div.movie', {
|
||||
'id': info.imdb
|
||||
}).adopt(
|
||||
self.options = new Element('div.options'),
|
||||
self.options = new Element('div.options.inlay'),
|
||||
self.data_container = new Element('div.data', {
|
||||
'tween': {
|
||||
duration: 400,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from couchpotato import get_session
|
||||
from couchpotato.api import addApiView
|
||||
from couchpotato.core.event import addEvent
|
||||
from couchpotato.core.event import addEvent, fireEvent
|
||||
from couchpotato.core.helpers.request import jsonified, getParams, getParam
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
@@ -17,6 +17,10 @@ class ProfilePlugin(Plugin):
|
||||
addApiView('profile.save', self.save)
|
||||
addApiView('profile.delete', self.delete)
|
||||
|
||||
path = self.registerStatic(__file__)
|
||||
fireEvent('register_script', path + 'profile.js')
|
||||
fireEvent('register_style', path + 'profile.css')
|
||||
|
||||
def all(self):
|
||||
|
||||
db = get_session()
|
||||
@@ -59,7 +63,7 @@ class ProfilePlugin(Plugin):
|
||||
order += 1
|
||||
|
||||
db.commit()
|
||||
|
||||
|
||||
profile_dict = p.to_dict(deep = {'types': {}})
|
||||
|
||||
return jsonified({
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
.profile > .delete {
|
||||
background-position: center;
|
||||
height: 20px;
|
||||
width: 20px;
|
||||
}
|
||||
|
||||
.profile .types .type .handle {
|
||||
background: url('../../images/handle.png') center;
|
||||
display: inline-block;
|
||||
height: 20px;
|
||||
width: 20px;
|
||||
}
|
||||
|
||||
.profile .types .type .delete {
|
||||
background-position: center;
|
||||
height: 20px;
|
||||
width: 20px;
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
var Profile = new Class({
|
||||
|
||||
data: {},
|
||||
types: [],
|
||||
|
||||
initialize: function(data){
|
||||
var self = this;
|
||||
|
||||
self.data = data;
|
||||
self.types = [];
|
||||
|
||||
self.create();
|
||||
|
||||
self.el.addEvents({
|
||||
'change:relay(select, input[type=checkbox])': self.save.bind(self, 0),
|
||||
'keyup:relay(input[type=text])': self.save.bind(self, [300])
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
create: function(){
|
||||
var self = this;
|
||||
|
||||
var data = self.data;
|
||||
|
||||
self.el = new Element('div.profile').adopt(
|
||||
self.header = new Element('h4', {'text': data.label}),
|
||||
new Element('span.delete.icon', {
|
||||
'events': {
|
||||
'click': self.del.bind(self)
|
||||
}
|
||||
}),
|
||||
new Element('div', {
|
||||
'class': 'ctrlHolder'
|
||||
}).adopt(
|
||||
new Element('label', {'text':'Name'}),
|
||||
new Element('input.label.textInput.large', {
|
||||
'type':'text',
|
||||
'value': data.label,
|
||||
'events': {
|
||||
'keyup': function(){
|
||||
self.header.set('text', this.get('value'))
|
||||
}
|
||||
}
|
||||
})
|
||||
),
|
||||
new Element('div.ctrlHolder').adopt(
|
||||
new Element('label', {'text':'Wait'}),
|
||||
new Element('input.wait_for.textInput.xsmall', {
|
||||
'type':'text',
|
||||
'value': data.types && data.types.length > 0 ? data.types[0].wait_for : 0
|
||||
}),
|
||||
new Element('span', {'text':' day(s) for better quality.'})
|
||||
),
|
||||
new Element('div.ctrlHolder').adopt(
|
||||
new Element('label', {'text': 'Qualities'}),
|
||||
new Element('div.head').adopt(
|
||||
new Element('span.quality_type', {'text': 'Search for'}),
|
||||
new Element('span.finish', {'html': '<acronym title="Won\'t download anything else if it has found this quality.">Finish</acronym>'})
|
||||
),
|
||||
self.type_container = new Element('ol.types'),
|
||||
new Element('a.addType', {
|
||||
'text': 'Add another quality to search for.',
|
||||
'href': '#',
|
||||
'events': {
|
||||
'click': self.addType.bind(self)
|
||||
}
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
self.makeSortable()
|
||||
|
||||
if(data.types)
|
||||
Object.each(data.types, self.addType.bind(self))
|
||||
},
|
||||
|
||||
save: function(delay){
|
||||
var self = this;
|
||||
|
||||
if(self.save_timer) clearTimeout(self.save_timer);
|
||||
self.save_timer = (function(){
|
||||
|
||||
var data = self.getData();
|
||||
if(data.types.length < 2) return;
|
||||
|
||||
Api.request('profile.save', {
|
||||
'data': self.getData(),
|
||||
'useSpinner': true,
|
||||
'spinnerOptions': {
|
||||
'target': self.el
|
||||
},
|
||||
'onComplete': function(json){
|
||||
if(json.success){
|
||||
self.data = json.profile
|
||||
}
|
||||
}
|
||||
});
|
||||
}).delay(delay, self)
|
||||
|
||||
},
|
||||
|
||||
getData: function(){
|
||||
var self = this;
|
||||
|
||||
var data = {
|
||||
'id' : self.data.id,
|
||||
'label' : self.el.getElement('.label').get('value'),
|
||||
'wait_for' : self.el.getElement('.wait_for').get('value'),
|
||||
'types': []
|
||||
}
|
||||
|
||||
Array.each(self.type_container.getElements('.type'), function(type){
|
||||
if(!type.hasClass('deleted'))
|
||||
data.types.include({
|
||||
'quality_id': type.getElement('select').get('value'),
|
||||
'finish': +type.getElement('input[type=checkbox]').checked
|
||||
});
|
||||
})
|
||||
|
||||
return data
|
||||
},
|
||||
|
||||
addType: function(data){
|
||||
var self = this;
|
||||
|
||||
var t = new Profile.Type(data);
|
||||
$(t).inject(self.type_container);
|
||||
self.sortable.addItems($(t));
|
||||
|
||||
self.types.include(t);
|
||||
|
||||
},
|
||||
|
||||
del: function(){
|
||||
var self = this;
|
||||
|
||||
if(!confirm('Are you sure you want to delete this profile?')) return
|
||||
|
||||
Api.request('profile.delete', {
|
||||
'data': {
|
||||
'id': self.data.id
|
||||
},
|
||||
'useSpinner': true,
|
||||
'spinnerOptions': {
|
||||
'target': self.el
|
||||
},
|
||||
'onComplete': function(json){
|
||||
if(json.success)
|
||||
self.el.destroy();
|
||||
else
|
||||
alert(json.message)
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
makeSortable: function(){
|
||||
var self = this;
|
||||
|
||||
self.sortable = new Sortables(self.type_container, {
|
||||
'revert': true,
|
||||
//'clone': true,
|
||||
'handle': '.handle',
|
||||
'opacity': 0.5,
|
||||
'onComplete': self.save.bind(self, 300)
|
||||
});
|
||||
},
|
||||
|
||||
get: function(attr){
|
||||
return this.data[attr]
|
||||
},
|
||||
|
||||
isCore: function(){
|
||||
return this.data.core
|
||||
},
|
||||
|
||||
toElement: function(){
|
||||
return this.el
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Profile.Type = Class({
|
||||
|
||||
deleted: false,
|
||||
|
||||
initialize: function(data){
|
||||
var self = this;
|
||||
|
||||
self.data = data;
|
||||
self.create();
|
||||
|
||||
},
|
||||
|
||||
create: function(){
|
||||
var self = this;
|
||||
var data = self.data;
|
||||
|
||||
self.el = new Element('li.type').adopt(
|
||||
new Element('span.quality_type').adopt(
|
||||
self.fillQualities()
|
||||
),
|
||||
new Element('span.finish').adopt(
|
||||
self.finish = new Element('input', {
|
||||
'type':'checkbox',
|
||||
'class':'finish',
|
||||
'checked': data.finish
|
||||
})
|
||||
),
|
||||
new Element('span.delete.icon', {
|
||||
'events': {
|
||||
'click': self.del.bind(self)
|
||||
}
|
||||
}),
|
||||
new Element('span.handle')
|
||||
)
|
||||
|
||||
},
|
||||
|
||||
fillQualities: function(){
|
||||
var self = this;
|
||||
|
||||
self.qualities = new Element('select');
|
||||
|
||||
Object.each(Quality.qualities, function(q){
|
||||
new Element('option', {
|
||||
'text': q.label,
|
||||
'value': q.id
|
||||
}).inject(self.qualities)
|
||||
});
|
||||
|
||||
self.qualities.set('value', self.data.quality_id);
|
||||
|
||||
return self.qualities;
|
||||
|
||||
},
|
||||
|
||||
getData: function(){
|
||||
var self = this;
|
||||
|
||||
return {
|
||||
'quality_id': self.qualities.get('value'),
|
||||
'finish': +self.finish.checked
|
||||
}
|
||||
},
|
||||
|
||||
del: function(){
|
||||
var self = this;
|
||||
|
||||
self.el.addClass('deleted');
|
||||
self.el.hide();
|
||||
self.deleted = true;
|
||||
},
|
||||
|
||||
toElement: function(){
|
||||
return this.el;
|
||||
}
|
||||
|
||||
})
|
||||
@@ -4,6 +4,8 @@ from couchpotato.core.helpers.encoding import toUnicode
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
from couchpotato.core.settings.model import Quality, Profile, ProfileType
|
||||
import os.path
|
||||
import re
|
||||
|
||||
log = CPLog(__name__)
|
||||
|
||||
@@ -11,10 +13,10 @@ log = CPLog(__name__)
|
||||
class QualityPlugin(Plugin):
|
||||
|
||||
qualities = [
|
||||
{'identifier': 'bd50', 'size': (15000, 60000), 'label': 'BR-Disk', 'alternative': ['1080p', 'bd25'], 'allow': [], 'ext':[], 'tags': ['x264', 'h264', 'blu ray']},
|
||||
{'identifier': '1080p', 'size': (5000, 20000), 'label': '1080P', 'alternative': [], 'allow': [], 'ext':['mkv', 'm2ts'], 'tags': ['x264', 'h264', 'bluray']},
|
||||
{'identifier': '720p', 'size': (3500, 10000), 'label': '720P', 'alternative': [], 'allow': [], 'ext':['mkv', 'm2ts'], 'tags': ['x264', 'h264', 'bluray']},
|
||||
{'identifier': 'brrip', 'size': (700, 7000), 'label': 'BR-Rip', 'alternative': ['bdrip'], 'allow': ['720p'], 'ext':['mkv', 'avi']},
|
||||
{'identifier': 'bd50', 'size': (15000, 60000), 'label': 'BR-Disk', 'width': 1920, 'alternative': ['1080p', 'bd25'], 'allow': [], 'ext':[], 'tags': ['x264', 'h264', 'blu ray']},
|
||||
{'identifier': '1080p', 'size': (5000, 20000), 'label': '1080P', 'width': 1920, 'alternative': [], 'allow': [], 'ext':['mkv', 'm2ts'], 'tags': ['x264', 'h264', 'bluray']},
|
||||
{'identifier': '720p', 'size': (3500, 10000), 'label': '720P', 'width': 1280, 'alternative': [], 'allow': [], 'ext':['mkv', 'm2ts'], 'tags': ['x264', 'h264', 'bluray']},
|
||||
{'identifier': 'brrip', 'size': (700, 7000), 'label': 'BR-Rip', 'alternative': ['bdrip'], 'allow': ['720p'], 'ext':['avi']},
|
||||
{'identifier': 'dvdr', 'size': (3000, 10000), 'label': 'DVD-R', 'alternative': [], 'allow': [], 'ext':['iso', 'img'], 'tags': ['pal', 'ntsc']},
|
||||
{'identifier': 'dvdrip', 'size': (600, 2400), 'label': 'DVD-Rip', 'alternative': [], 'allow': [], 'ext':['avi', 'mpg', 'mpeg']},
|
||||
{'identifier': 'scr', 'size': (600, 1600), 'label': 'Screener', 'alternative': ['dvdscr'], 'allow': ['dvdr'], 'ext':['avi', 'mpg', 'mpeg']},
|
||||
@@ -28,6 +30,7 @@ class QualityPlugin(Plugin):
|
||||
def __init__(self):
|
||||
addEvent('quality.all', self.all)
|
||||
addEvent('quality.single', self.single)
|
||||
addEvent('quality.guess', self.guess)
|
||||
addEvent('app.load', self.fill)
|
||||
|
||||
path = self.registerStatic(__file__)
|
||||
@@ -50,9 +53,11 @@ class QualityPlugin(Plugin):
|
||||
def single(self, identifier = ''):
|
||||
|
||||
db = get_session()
|
||||
quality_dict = {}
|
||||
|
||||
quality = db.query(Quality).filter_by(identifier = identifier).first()
|
||||
quality_dict = dict(self.getQuality(quality.identifier), **quality.to_dict())
|
||||
if quality:
|
||||
quality_dict = dict(self.getQuality(quality.identifier), **quality.to_dict())
|
||||
|
||||
return quality_dict
|
||||
|
||||
@@ -110,3 +115,41 @@ class QualityPlugin(Plugin):
|
||||
db.commit()
|
||||
|
||||
return True
|
||||
|
||||
def guess(self, files, extra = {}):
|
||||
found = False
|
||||
|
||||
for file in files:
|
||||
size = (os.path.getsize(file) / 1024 / 1024)
|
||||
words = re.split('\W+', file.lower())
|
||||
for quality in self.all():
|
||||
correctSize = False
|
||||
|
||||
if size >= quality['size_min'] and size <= quality['size_max']:
|
||||
correctSize = True
|
||||
|
||||
# Check tags
|
||||
if type in words:
|
||||
found = True
|
||||
|
||||
for alt in quality.get('alternative'):
|
||||
if alt in words:
|
||||
found = True
|
||||
|
||||
for tag in quality.get('tags', []):
|
||||
if tag in words:
|
||||
found = True
|
||||
|
||||
# Check extension + filesize
|
||||
for ext in quality.get('ext'):
|
||||
if ext in words and correctSize:
|
||||
found = True
|
||||
|
||||
# Last check on resolution only
|
||||
if quality.get('width', 480) == extra.get('resolution_width', 0):
|
||||
found = True
|
||||
|
||||
if found:
|
||||
return quality
|
||||
|
||||
return ''
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
/* @override http://localhost:5000/static/style/plugin/quality.css */
|
||||
|
||||
|
||||
.profile > .delete {
|
||||
background-position: center;
|
||||
height: 20px;
|
||||
width: 20px;
|
||||
}
|
||||
|
||||
.profile .types .type .handle {
|
||||
background: url('../../images/handle.png') center;
|
||||
display: inline-block;
|
||||
height: 20px;
|
||||
width: 20px;
|
||||
}
|
||||
|
||||
.profile .types .type .delete {
|
||||
background-position: center;
|
||||
height: 20px;
|
||||
width: 20px;
|
||||
}
|
||||
@@ -33,7 +33,6 @@ var QualityBase = new Class({
|
||||
self.content = tab.content;
|
||||
|
||||
self.createProfiles();
|
||||
self.createOrdering();
|
||||
self.createSizes();
|
||||
|
||||
})
|
||||
@@ -83,291 +82,36 @@ var QualityBase = new Class({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Ordering
|
||||
*/
|
||||
createOrdering: function(){
|
||||
var self = this;
|
||||
|
||||
self.settings.createGroup({
|
||||
'label': 'Order',
|
||||
'description': 'Discriptions'
|
||||
}).inject(self.content)
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Sizes
|
||||
*/
|
||||
createSizes: function(){
|
||||
var self = this;
|
||||
|
||||
self.settings.createGroup({
|
||||
var group = self.settings.createGroup({
|
||||
'label': 'Sizes',
|
||||
'description': 'Discriptions',
|
||||
'advanced': true
|
||||
}).inject(self.content)
|
||||
}
|
||||
|
||||
});
|
||||
window.Quality = new QualityBase();
|
||||
|
||||
var Profile = new Class({
|
||||
|
||||
data: {},
|
||||
types: [],
|
||||
|
||||
initialize: function(data){
|
||||
var self = this;
|
||||
|
||||
self.data = data;
|
||||
self.types = [];
|
||||
|
||||
self.create();
|
||||
|
||||
self.el.addEvents({
|
||||
'change:relay(select, input[type=checkbox])': self.save.bind(self, 0),
|
||||
'keyup:relay(input[type=text])': self.save.bind(self, [300])
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
create: function(){
|
||||
var self = this;
|
||||
|
||||
var data = self.data;
|
||||
|
||||
self.el = new Element('div.profile').adopt(
|
||||
self.header = new Element('h4', {'text': data.label}),
|
||||
new Element('span.delete.icon', {
|
||||
'events': {
|
||||
'click': self.del.bind(self)
|
||||
}
|
||||
}),
|
||||
new Element('div', {
|
||||
'class': 'ctrlHolder'
|
||||
}).adopt(
|
||||
new Element('label', {'text':'Name'}),
|
||||
new Element('input.label.textInput.large', {
|
||||
'type':'text',
|
||||
'value': data.label,
|
||||
'events': {
|
||||
'keyup': function(){
|
||||
self.header.set('text', this.get('value'))
|
||||
}
|
||||
}
|
||||
})
|
||||
),
|
||||
new Element('div.ctrlHolder').adopt(
|
||||
new Element('label', {'text':'Wait'}),
|
||||
new Element('input.wait_for.textInput.xsmall', {
|
||||
'type':'text',
|
||||
'value': data.types && data.types.length > 0 ? data.types[0].wait_for : 0
|
||||
}),
|
||||
new Element('span', {'text':' day(s) for better quality.'})
|
||||
),
|
||||
new Element('div.ctrlHolder').adopt(
|
||||
new Element('label', {'text': 'Qualities'}),
|
||||
new Element('div.head').adopt(
|
||||
new Element('span.quality_type', {'text': 'Search for'}),
|
||||
new Element('span.finish', {'html': '<acronym title="Won\'t download anything else if it has found this quality.">Finish</acronym>'})
|
||||
),
|
||||
self.type_container = new Element('ol.types'),
|
||||
new Element('a.addType', {
|
||||
'text': 'Add another quality to search for.',
|
||||
'href': '#',
|
||||
'events': {
|
||||
'click': self.addType.bind(self)
|
||||
}
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
self.makeSortable()
|
||||
|
||||
if(data.types)
|
||||
Object.each(data.types, self.addType.bind(self))
|
||||
},
|
||||
|
||||
save: function(delay){
|
||||
var self = this;
|
||||
|
||||
if(self.save_timer) clearTimeout(self.save_timer);
|
||||
self.save_timer = (function(){
|
||||
|
||||
var data = self.getData();
|
||||
if(data.types.length < 2) return;
|
||||
|
||||
Api.request('profile.save', {
|
||||
'data': self.getData(),
|
||||
'useSpinner': true,
|
||||
'spinnerOptions': {
|
||||
'target': self.el
|
||||
},
|
||||
'onComplete': function(json){
|
||||
if(json.success){
|
||||
self.data = json.profile
|
||||
}
|
||||
}
|
||||
});
|
||||
}).delay(delay, self)
|
||||
|
||||
},
|
||||
|
||||
getData: function(){
|
||||
var self = this;
|
||||
|
||||
var data = {
|
||||
'id' : self.data.id,
|
||||
'label' : self.el.getElement('.label').get('value'),
|
||||
'wait_for' : self.el.getElement('.wait_for').get('value'),
|
||||
'types': []
|
||||
}
|
||||
|
||||
Array.each(self.type_container.getElements('.type'), function(type){
|
||||
if(!type.hasClass('deleted'))
|
||||
data.types.include({
|
||||
'quality_id': type.getElement('select').get('value'),
|
||||
'finish': +type.getElement('input[type=checkbox]').checked
|
||||
});
|
||||
|
||||
new Element('div.item.header').adopt(
|
||||
new Element('span.label', {'text': 'Quality'}),
|
||||
new Element('span.min', {'text': 'Min'}),
|
||||
new Element('span.max', {'text': 'Max'})
|
||||
).inject(group)
|
||||
|
||||
Object.each(self.qualities, function(quality){
|
||||
new Element('div.item').adopt(
|
||||
new Element('span.label', {'text': quality.label}),
|
||||
new Element('input.min', {'value': quality.size_min}),
|
||||
new Element('input.max', {'value': quality.size_max})
|
||||
).inject(group)
|
||||
})
|
||||
|
||||
return data
|
||||
},
|
||||
|
||||
addType: function(data){
|
||||
var self = this;
|
||||
|
||||
var t = new Profile.Type(data);
|
||||
$(t).inject(self.type_container);
|
||||
self.sortable.addItems($(t));
|
||||
|
||||
self.types.include(t);
|
||||
|
||||
},
|
||||
|
||||
del: function(){
|
||||
var self = this;
|
||||
|
||||
if(!confirm('Are you sure you want to delete this profile?')) return
|
||||
|
||||
Api.request('profile.delete', {
|
||||
'data': {
|
||||
'id': self.data.id
|
||||
},
|
||||
'useSpinner': true,
|
||||
'spinnerOptions': {
|
||||
'target': self.el
|
||||
},
|
||||
'onComplete': function(json){
|
||||
if(json.success)
|
||||
self.el.destroy();
|
||||
else
|
||||
alert(json.message)
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
makeSortable: function(){
|
||||
var self = this;
|
||||
|
||||
self.sortable = new Sortables(self.type_container, {
|
||||
'revert': true,
|
||||
//'clone': true,
|
||||
'handle': '.handle',
|
||||
'opacity': 0.5,
|
||||
'onComplete': self.save.bind(self, 300)
|
||||
});
|
||||
},
|
||||
|
||||
get: function(attr){
|
||||
return this.data[attr]
|
||||
},
|
||||
|
||||
isCore: function(){
|
||||
return this.data.core
|
||||
},
|
||||
|
||||
toElement: function(){
|
||||
return this.el
|
||||
|
||||
p(group)
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Profile.Type = Class({
|
||||
|
||||
deleted: false,
|
||||
|
||||
initialize: function(data){
|
||||
var self = this;
|
||||
|
||||
self.data = data;
|
||||
self.create();
|
||||
|
||||
},
|
||||
|
||||
create: function(){
|
||||
var self = this;
|
||||
var data = self.data;
|
||||
|
||||
self.el = new Element('li.type').adopt(
|
||||
new Element('span.quality_type').adopt(
|
||||
self.fillQualities()
|
||||
),
|
||||
new Element('span.finish').adopt(
|
||||
self.finish = new Element('input', {
|
||||
'type':'checkbox',
|
||||
'class':'finish',
|
||||
'checked': data.finish
|
||||
})
|
||||
),
|
||||
new Element('span.delete.icon', {
|
||||
'events': {
|
||||
'click': self.del.bind(self)
|
||||
}
|
||||
}),
|
||||
new Element('span.handle')
|
||||
)
|
||||
|
||||
},
|
||||
|
||||
fillQualities: function(){
|
||||
var self = this;
|
||||
|
||||
self.qualities = new Element('select');
|
||||
|
||||
Object.each(Quality.qualities, function(q){
|
||||
new Element('option', {
|
||||
'text': q.label,
|
||||
'value': q.id
|
||||
}).inject(self.qualities)
|
||||
});
|
||||
|
||||
self.qualities.set('value', self.data.quality_id);
|
||||
|
||||
return self.qualities;
|
||||
|
||||
},
|
||||
|
||||
getData: function(){
|
||||
var self = this;
|
||||
|
||||
return {
|
||||
'quality_id': self.qualities.get('value'),
|
||||
'finish': +self.finish.checked
|
||||
}
|
||||
},
|
||||
|
||||
del: function(){
|
||||
var self = this;
|
||||
|
||||
self.el.addClass('deleted');
|
||||
self.el.hide();
|
||||
self.deleted = true;
|
||||
},
|
||||
|
||||
toElement: function(){
|
||||
return this.el;
|
||||
}
|
||||
|
||||
})
|
||||
window.Quality = new QualityBase();
|
||||
|
||||
@@ -8,9 +8,8 @@ config = [{
|
||||
'groups': [
|
||||
{
|
||||
'tab': 'renamer',
|
||||
'name': 'tmdb',
|
||||
'label': 'TheMovieDB',
|
||||
'advanced': True,
|
||||
'name': 'renamer',
|
||||
'label': 'Folders',
|
||||
'description': 'Move and rename your downloaded movies to your movie directory.',
|
||||
'options': [
|
||||
{
|
||||
@@ -29,12 +28,52 @@ config = [{
|
||||
'description': 'Folder where the movies will be moved to.',
|
||||
},
|
||||
{
|
||||
'name': 'folder_name',
|
||||
'label': 'Folder naming',
|
||||
'description': 'Name of the folder',
|
||||
},
|
||||
{
|
||||
'name': 'file_name',
|
||||
'label': 'File naming',
|
||||
'description': 'Name of the file',
|
||||
},
|
||||
{
|
||||
'advanced': True,
|
||||
'name': 'separator',
|
||||
'label': 'Separator',
|
||||
'description': 'Replace all the spaces with a character. Example: ".", "-". Leave empty to use spaces.',
|
||||
},
|
||||
{
|
||||
'advanced': True,
|
||||
'name': 'run_every',
|
||||
'label': 'Run every',
|
||||
'default': 1,
|
||||
'type': 'int',
|
||||
'unit': 'min(s)',
|
||||
'description': 'Search for new movies inside the folder every X minutes.',
|
||||
},
|
||||
],
|
||||
}, {
|
||||
'tab': 'renamer',
|
||||
'name': 'meta_renamer',
|
||||
'label': 'Advanced renaming',
|
||||
'description': 'Meta data file renaming. Use <filename> to use the above "File naming" settings, without the file extention.',
|
||||
'advanced': True,
|
||||
'options': [
|
||||
{
|
||||
'name': 'trailer_name',
|
||||
'label': 'Trailer naming',
|
||||
'default': '<filename>-trailer.<ext>',
|
||||
},
|
||||
{
|
||||
'name': 'nfo_name',
|
||||
'label': 'NFO naming',
|
||||
'default': '<filename>.<ext>',
|
||||
},
|
||||
{
|
||||
'name': 'backdrop_name',
|
||||
'label': 'Backdrop naming',
|
||||
'default': '<filename>-backdrop.<ext>',
|
||||
}
|
||||
],
|
||||
},
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
from couchpotato import get_session
|
||||
from couchpotato.core.event import addEvent, fireEvent
|
||||
from couchpotato.core.helpers.encoding import toUnicode
|
||||
from couchpotato.core.helpers.variable import getExt
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
from couchpotato.core.settings.model import Library
|
||||
import os.path
|
||||
import re
|
||||
import shutil
|
||||
import traceback
|
||||
|
||||
log = CPLog(__name__)
|
||||
|
||||
@@ -8,12 +16,208 @@ log = CPLog(__name__)
|
||||
class Renamer(Plugin):
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
addEvent('renamer.scan', self.scan)
|
||||
addEvent('app.load', self.scan)
|
||||
#addEvent('app.load', self.scan)
|
||||
|
||||
#fireEvent('schedule.interval', 'renamer.scan', self.scan, minutes = self.conf('run_every'))
|
||||
|
||||
def scan(self):
|
||||
pass
|
||||
|
||||
groups = fireEvent('scanner.scan', folder = self.conf('from'), single = True)
|
||||
|
||||
destination = self.conf('to')
|
||||
folder_name = self.conf('folder_name')
|
||||
file_name = self.conf('file_name')
|
||||
trailer_name = self.conf('trailer_name')
|
||||
backdrop_name = self.conf('fanart_name')
|
||||
nfo_name = self.conf('nfo_name')
|
||||
separator = self.conf('separator')
|
||||
|
||||
for group_identifier in groups:
|
||||
|
||||
group = groups[group_identifier]
|
||||
rename_files = {}
|
||||
|
||||
# Add _UNKNOWN_ if no library is connected
|
||||
if not group['library']:
|
||||
if group['dirname']:
|
||||
rename_files[group['parentdir']] = group['parentdir'].replace(group['dirname'], '_UNKNOWN_%s' % group['dirname'])
|
||||
else: # Add it to filename
|
||||
for file_type in group['files']:
|
||||
for rename_me in group['files'][file_type]:
|
||||
filename = os.path.basename(rename_me)
|
||||
rename_files[rename_me] = rename_me.replace(filename, '_UNKNOWN_%s' % filename)
|
||||
|
||||
# Rename the files using the library data
|
||||
else:
|
||||
group['library'] = fireEvent('library.update', identifier = group['library']['identifier'], single = True)
|
||||
library = group['library']
|
||||
|
||||
# Find subtitle for renaming
|
||||
fireEvent('renamer.before', group)
|
||||
|
||||
# Remove weird chars from moviename
|
||||
movie_name = re.sub(r"[\x00\/\\:\*\?\"<>\|]", '', group['library']['titles'][0]['title'])
|
||||
|
||||
# Put 'The' at the end
|
||||
name_the = movie_name
|
||||
if movie_name[:4].lower() == 'the ':
|
||||
name_the = movie_name[4:] + ', The'
|
||||
|
||||
replacements = {
|
||||
'ext': 'mkv',
|
||||
'namethe': name_the.strip(),
|
||||
'thename': movie_name.strip(),
|
||||
'year': library['year'],
|
||||
'first': name_the[0].upper(),
|
||||
'dirname': group['dirname'],
|
||||
'quality': group['meta_data']['quality']['label'],
|
||||
'quality_type': group['meta_data']['quality_type'],
|
||||
'video': group['meta_data'].get('video'),
|
||||
'audio': group['meta_data'].get('audio'),
|
||||
'group': group['meta_data']['group'],
|
||||
'source': group['meta_data']['source'],
|
||||
'resolution_width': group['meta_data'].get('resolution_width'),
|
||||
'resolution_height': group['meta_data'].get('resolution_height'),
|
||||
}
|
||||
|
||||
for file_type in group['files']:
|
||||
|
||||
# Move DVD files (no renaming)
|
||||
if group['is_dvd'] and file_type is 'movie':
|
||||
continue
|
||||
|
||||
# Move nfo depending on settings
|
||||
if file_type is 'nfo' and not self.conf('rename_nfo'):
|
||||
continue
|
||||
|
||||
# Subtitle extra
|
||||
if file_type is 'subtitle_extra':
|
||||
continue
|
||||
|
||||
# Move other files
|
||||
multiple = len(group['files']['movie']) > 1
|
||||
cd = 1 if multiple else 0
|
||||
|
||||
for file in sorted(list(group['files'][file_type])):
|
||||
|
||||
# Original filename
|
||||
replacements['original'] = os.path.basename(file)
|
||||
|
||||
# Extension
|
||||
replacements['ext'] = getExt(file)
|
||||
|
||||
# cd #
|
||||
replacements['cd'] = ' cd%d' % cd if cd else ''
|
||||
replacements['cd_nr'] = cd
|
||||
|
||||
# Naming
|
||||
final_folder_name = self.doReplace(folder_name, replacements)
|
||||
final_file_name = self.doReplace(file_name, replacements)
|
||||
replacements['filename'] = final_file_name[:-(len(getExt(final_file_name)) + 1)]
|
||||
|
||||
# Meta naming
|
||||
if file_type is 'trailer':
|
||||
final_file_name = self.doReplace(trailer_name, replacements)
|
||||
elif file_type is 'nfo':
|
||||
final_file_name = self.doReplace(nfo_name, replacements)
|
||||
elif file_type is 'backdrop':
|
||||
final_file_name = self.doReplace(backdrop_name, replacements)
|
||||
|
||||
# Seperator replace
|
||||
if separator:
|
||||
final_file_name = final_file_name.replace(' ', separator)
|
||||
|
||||
# Main file
|
||||
rename_files[file] = os.path.join(destination, final_folder_name, final_file_name)
|
||||
|
||||
# Check for extra subtitle files
|
||||
if file_type is 'subtitle':
|
||||
|
||||
def test(s):
|
||||
return file[:-len(replacements['ext'])] in s
|
||||
|
||||
for subtitle_extra in set(filter(test, group['files']['subtitle_extra'])):
|
||||
replacements['ext'] = getExt(subtitle_extra)
|
||||
|
||||
final_folder_name = self.doReplace(folder_name, replacements)
|
||||
final_file_name = self.doReplace(file_name, replacements)
|
||||
rename_files[subtitle_extra] = os.path.join(destination, final_folder_name, final_file_name)
|
||||
|
||||
if multiple:
|
||||
cd += 1
|
||||
|
||||
# Before renaming, remove the lower quality files
|
||||
db = get_session()
|
||||
library = db.query(Library).filter_by(identifier = group['library']['identifier']).first()
|
||||
for movie in library.movies:
|
||||
for release in movie.releases:
|
||||
if release.quality.order < group['meta_data']['quality']['order']:
|
||||
log.info('Removing older release for %s, with quality %s' % (movie.library.titles[0].title, release.quality.label))
|
||||
elif release.quality.order is group['meta_data']['quality']['order']:
|
||||
log.info('Same quality release already exists for %s, with quality %s. Assuming repack.' % (movie.library.titles[0].title, release.quality.label))
|
||||
else:
|
||||
log.info('Better quality release already exists for %s, with quality %s' % (movie.library.titles[0].title, release.quality.label))
|
||||
|
||||
# Add _EXISTS_ to the parent dir
|
||||
if group['dirname']:
|
||||
for rename_me in rename_files: # Don't rename anything in this group
|
||||
rename_files[rename_me] = None
|
||||
rename_files[group['parentdir']] = group['parentdir'].replace(group['dirname'], '_EXISTS_%s' % group['dirname'])
|
||||
else: # Add it to filename
|
||||
for rename_me in rename_files:
|
||||
filename = os.path.basename(rename_me)
|
||||
rename_files[rename_me] = rename_me.replace(filename, '_EXISTS_%s' % filename)
|
||||
|
||||
break
|
||||
|
||||
for file in release.files:
|
||||
log.info('Removing "%s"' % file.path)
|
||||
|
||||
# Rename
|
||||
for rename_me in rename_files:
|
||||
if rename_files[rename_me]:
|
||||
log.info('Renaming "%s" to "%s"' % (rename_me, rename_files[rename_me]))
|
||||
|
||||
path = os.path.dirname(rename_files[rename_me])
|
||||
try:
|
||||
if not os.path.isdir(path): os.makedirs(path)
|
||||
except:
|
||||
log.error('Failed creating dir %s: %s' % (path, traceback.format_exc()))
|
||||
continue
|
||||
|
||||
#print rename_me, rename_files[rename_me]
|
||||
|
||||
# Search for trailers
|
||||
fireEvent('renamer.after', group)
|
||||
|
||||
def moveFile(self, old, dest, suppress = True):
|
||||
try:
|
||||
shutil.move(old, dest)
|
||||
except:
|
||||
log.error("Couldn't move file '%s' to '%s': %s" % (old, dest, traceback.format_exc()))
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def doReplace(self, string, replacements):
|
||||
'''
|
||||
replace confignames with the real thing
|
||||
'''
|
||||
|
||||
replaced = toUnicode(string)
|
||||
for x, r in replacements.iteritems():
|
||||
if r is not None:
|
||||
replaced = replaced.replace('<%s>' % toUnicode(x), toUnicode(r))
|
||||
else:
|
||||
#If information is not available, we don't want the tag in the filename
|
||||
replaced = replaced.replace('<' + x + '>', '')
|
||||
|
||||
replaced = re.sub(r"[\x00:\*\?\"<>\|]", '', replaced)
|
||||
|
||||
sep = self.conf('separator')
|
||||
return self.replaceDoubles(replaced).replace(' ', ' ' if not sep else sep)
|
||||
|
||||
def replaceDoubles(self, string):
|
||||
return string.replace(' ', ' ').replace(' .', '.')
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
from couchpotato import get_session
|
||||
from couchpotato.core.event import fireEvent, addEvent
|
||||
from couchpotato.core.helpers.encoding import toUnicode
|
||||
from couchpotato.core.helpers.encoding import toUnicode, simplifyString
|
||||
from couchpotato.core.helpers.variable import getExt
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
from couchpotato.core.settings.model import File, Library, Release, Movie
|
||||
from couchpotato.core.settings.model import File, Release, Movie
|
||||
from couchpotato.environment import Env
|
||||
from flask.helpers import json
|
||||
from themoviedb.tmdb import opensubtitleHashFile
|
||||
@@ -23,7 +23,7 @@ class Scanner(Plugin):
|
||||
'trailer': 1048576, # 1MB
|
||||
}
|
||||
ignored_in_path = ['_unpack', '_failed_', '_unknown_', '_exists_', '.appledouble', '.appledb', '.appledesktop', os.path.sep + '._', '.ds_store', 'cp.cpnfo'] #unpacking, smb-crap, hidden files
|
||||
ignore_names = ['extract', 'extracting', 'extracted', 'movie', 'movies', 'film', 'films']
|
||||
ignore_names = ['extract', 'extracting', 'extracted', 'movie', 'movies', 'film', 'films', 'download', 'downloads']
|
||||
extensions = {
|
||||
'movie': ['mkv', 'wmv', 'avi', 'mpg', 'mpeg', 'mp4', 'm2ts', 'iso', 'img'],
|
||||
'dvd': ['vts_*', 'vob'],
|
||||
@@ -42,7 +42,7 @@ class Scanner(Plugin):
|
||||
|
||||
codecs = {
|
||||
'audio': ['dts', 'ac3', 'ac3d', 'mp3'],
|
||||
'video': ['x264', 'divx', 'xvid']
|
||||
'video': ['x264', 'h264', 'divx', 'xvid']
|
||||
}
|
||||
|
||||
source_media = {
|
||||
@@ -52,12 +52,16 @@ class Scanner(Plugin):
|
||||
'hdtv': ['hdtv']
|
||||
}
|
||||
|
||||
clean = '(?i)[^\s](ac3|dts|custom|dc|divx|divx5|dsr|dsrip|dutch|dvd|dvdrip|dvdscr|dvdscreener|screener|dvdivx|cam|fragment|fs|hdtv|hdrip|hdtvrip|internal|limited|multisubs|ntsc|ogg|ogm|pal|pdtv|proper|repack|rerip|retail|r3|r5|bd5|se|svcd|swedish|german|read.nfo|nfofix|unrated|ws|telesync|ts|telecine|tc|brrip|bdrip|480p|480i|576p|576i|720p|720i|1080p|1080i|hrhd|hrhdtv|hddvd|bluray|x264|h264|xvid|xvidvd|xxx|www.www|cd[1-9]|\[.*\])[^\s]*'
|
||||
clean = '[ _\,\.\(\)\[\]\-](french|swedisch|danish|dutch|swesub|spanish|german|ac3|dts|custom|dc|divx|divx5|dsr|dsrip|dutch|dvd|dvdrip|dvdscr|dvdscreener|screener|dvdivx|cam|fragment|fs|hdtv|hdrip|hdtvrip|internal|limited|multisubs|ntsc|ogg|ogm|pal|pdtv|proper|repack|rerip|retail|r3|r5|bd5|se|svcd|swedish|german|read.nfo|nfofix|unrated|ws|telesync|ts|telecine|tc|brrip|bdrip|video_ts|audio_ts|480p|480i|576p|576i|720p|720i|1080p|1080i|hrhd|hrhdtv|hddvd|bluray|x264|h264|xvid|xvidvd|xxx|www.www|cd[1-9]|\[.*\])([ _\,\.\(\)\[\]\-]|$)'
|
||||
multipart_regex = [
|
||||
'[ _\.-]+cd[ _\.-]*([0-9a-d]+)', #*cd1
|
||||
'[ _\.-]+dvd[ _\.-]*([0-9a-d]+)', #*dvd1
|
||||
'[ _\.-]+part[ _\.-]*([0-9a-d]+)', #*part1.mkv
|
||||
'[ _\.-]+dis[ck][ _\.-]*([0-9a-d]+)', #*disk1.mkv
|
||||
'[ _\.-]+part[ _\.-]*([0-9a-d]+)', #*part1
|
||||
'[ _\.-]+dis[ck][ _\.-]*([0-9a-d]+)', #*disk1
|
||||
'cd[ _\.-]*([0-9a-d]+)$', #cd1.ext
|
||||
'dvd[ _\.-]*([0-9a-d]+)$', #dvd1.ext
|
||||
'part[ _\.-]*([0-9a-d]+)$', #part1.mkv
|
||||
'dis[ck][ _\.-]*([0-9a-d]+)$', #disk1.mkv
|
||||
'()[ _\.-]+([0-9]*[abcd]+)(\.....?)$',
|
||||
'([a-z])([0-9]+)(\.....?)$',
|
||||
'()([ab])(\.....?)$' #*a.mkv
|
||||
@@ -65,42 +69,54 @@ class Scanner(Plugin):
|
||||
|
||||
def __init__(self):
|
||||
|
||||
addEvent('app.load', self.scan)
|
||||
#addEvent('app.load', self.scanLibrary)
|
||||
|
||||
def scan(self, folder = '/Volumes/Media/Test/'):
|
||||
addEvent('scanner.scan', self.scan)
|
||||
|
||||
"""
|
||||
Get all files
|
||||
def scanLibrary(self):
|
||||
|
||||
For each file larger then 350MB
|
||||
create movie "group", this is where all movie files will be grouped
|
||||
group multipart together
|
||||
check if its DVD (VIDEO_TS)
|
||||
folder = '/Volumes/Media/Test/'
|
||||
|
||||
# This should work for non-folder based structure
|
||||
for each moviegroup
|
||||
groups = self.scan(folder = folder)
|
||||
|
||||
for each file smaller then 350MB, allfiles.filter(moviename*)
|
||||
# Open up the db
|
||||
db = get_session()
|
||||
|
||||
# Assuming the beginning of the filename is the same for this structure
|
||||
Movie is masterfile, moviename-cd1.ext -> moviename
|
||||
Find other files connected to moviename, moviename*.nfo, moviename*.sub, moviename*trailer.ext
|
||||
# Mark all files as "offline" before a adding them to the database (again)
|
||||
files_in_path = db.query(File).filter(File.path.like(toUnicode(folder) + u'%%'))
|
||||
files_in_path.update({'available': 0}, synchronize_session = False)
|
||||
db.commit()
|
||||
|
||||
Remove found file from allfiles
|
||||
update_after = []
|
||||
for group in groups.itervalues():
|
||||
|
||||
# This should work for folder based structure
|
||||
for each leftover file
|
||||
Loop over leftover files, use dirname as moviename
|
||||
# Save to DB
|
||||
if group['library']:
|
||||
#library = db.query(Library).filter_by(id = library.get('id')).one()
|
||||
|
||||
# Add release
|
||||
self.addRelease(group)
|
||||
|
||||
# Add identifier for library update
|
||||
update_after.append(group['library'].get('identifier'))
|
||||
|
||||
for identifier in update_after:
|
||||
fireEvent('library.update', identifier = identifier)
|
||||
|
||||
# If cleanup option is enabled, remove offline files from database
|
||||
if self.conf('cleanup_offline'):
|
||||
files_in_path = db.query(File).filter(File.path.like(folder + '%%')).filter_by(available = 0)
|
||||
[db.delete(x) for x in files_in_path]
|
||||
db.commit()
|
||||
|
||||
db.remove()
|
||||
|
||||
|
||||
For each found movie
|
||||
def scan(self, folder = None):
|
||||
|
||||
determine filetype
|
||||
|
||||
Check if it's already in the db
|
||||
|
||||
Add it to database
|
||||
"""
|
||||
if not folder or not os.path.isdir(folder):
|
||||
log.error('Folder doesn\'t exists: %s' % folder)
|
||||
return {}
|
||||
|
||||
# Get movie "master" files
|
||||
movie_files = {}
|
||||
@@ -153,22 +169,16 @@ class Scanner(Plugin):
|
||||
# Remove the found files from the leftover stack
|
||||
leftovers = leftovers - found_files
|
||||
|
||||
# Open up the db
|
||||
db = get_session()
|
||||
|
||||
# Mark all files as "offline" before a adding them to the database (again)
|
||||
files_in_path = db.query(File).filter(File.path.like(toUnicode(folder) + u'%%'))
|
||||
files_in_path.update({'available': 0}, synchronize_session = False)
|
||||
db.commit()
|
||||
|
||||
# Determine file types
|
||||
update_after = []
|
||||
for identifier, group in movie_files.iteritems():
|
||||
for identifier in movie_files:
|
||||
group = movie_files[identifier]
|
||||
|
||||
# Group extra (and easy) files first
|
||||
images = self.getImages(group['unsorted_files'])
|
||||
group['files'] = {
|
||||
'subtitle': self.getSubtitles(group['unsorted_files']),
|
||||
'subtitle_extra': self.getSubtitlesExtras(group['unsorted_files']),
|
||||
'nfo': self.getNfo(group['unsorted_files']),
|
||||
'trailer': self.getTrailers(group['unsorted_files']),
|
||||
'backdrop': images['backdrop'],
|
||||
@@ -180,7 +190,22 @@ class Scanner(Plugin):
|
||||
group['files']['movie'] = self.getDVDFiles(group['unsorted_files'])
|
||||
else:
|
||||
group['files']['movie'] = self.getMediaFiles(group['unsorted_files'])
|
||||
group['meta_data'] = self.getMetaData(group['files']['movie'])
|
||||
group['meta_data'] = self.getMetaData(group)
|
||||
|
||||
# Get parent dir from movie files
|
||||
for movie_file in group['files']['movie']:
|
||||
group['parentdir'] = os.path.dirname(movie_file)
|
||||
group['dirname'] = None
|
||||
|
||||
folders = group['parentdir'].replace(folder, '').split(os.path.sep)
|
||||
|
||||
# Try and get a proper dirname, so no "A", "Movie", "Download"
|
||||
for folder in folders:
|
||||
if folder.lower() in self.ignore_names or len(folder) < 2:
|
||||
group['dirname'] = folder
|
||||
break
|
||||
|
||||
break
|
||||
|
||||
# Leftover "sorted" files
|
||||
for type in group['files']:
|
||||
@@ -191,34 +216,16 @@ class Scanner(Plugin):
|
||||
|
||||
# Determine movie
|
||||
group['library'] = self.determineMovie(group)
|
||||
if not group['library']:
|
||||
log.error('Unable to determin movie: %s' % group['identifiers'])
|
||||
|
||||
# Save to DB
|
||||
if group['library']:
|
||||
#library = db.query(Library).filter_by(id = library.get('id')).one()
|
||||
|
||||
# Add release
|
||||
release = self.addRelease(group)
|
||||
return
|
||||
|
||||
# Add identifier for library update
|
||||
update_after.append(group['library'].get('identifier'))
|
||||
|
||||
for identifier in update_after:
|
||||
fireEvent('library.update', identifier = identifier)
|
||||
|
||||
# If cleanup option is enabled, remove offline files from database
|
||||
if self.conf('cleanup_offline'):
|
||||
files_in_path = db.query(File).filter(File.path.like(folder + '%%')).filter_by(available = 0)
|
||||
[db.delete(x) for x in files_in_path]
|
||||
db.commit()
|
||||
|
||||
db.remove()
|
||||
return movie_files
|
||||
|
||||
|
||||
def addRelease(self, group):
|
||||
db = get_session()
|
||||
|
||||
identifier = '%s.%s.%s' % (group['library']['identifier'], group['meta_data']['audio'], group['meta_data']['quality'])
|
||||
identifier = '%s.%s.%s' % (group['library']['identifier'], group['meta_data'].get('audio', 'unknown'), group['meta_data']['quality']['identifier'])
|
||||
|
||||
# Add movie
|
||||
done_status = fireEvent('status.get', 'done', single = True)
|
||||
@@ -233,13 +240,13 @@ class Scanner(Plugin):
|
||||
db.commit()
|
||||
|
||||
# Add release
|
||||
quality = fireEvent('quality.single', group['meta_data']['quality'], single = True)
|
||||
release = db.query(Release).filter_by(identifier = identifier).first()
|
||||
if not release:
|
||||
|
||||
release = Release(
|
||||
identifier = identifier,
|
||||
movie = movie,
|
||||
quality_id = quality.get('id'),
|
||||
quality_id = group['meta_data']['quality'].get('id'),
|
||||
status_id = done_status.get('id')
|
||||
)
|
||||
db.add(release)
|
||||
@@ -259,18 +266,36 @@ class Scanner(Plugin):
|
||||
|
||||
db.remove()
|
||||
|
||||
def getMetaData(self, files):
|
||||
def getMetaData(self, group):
|
||||
|
||||
return {
|
||||
'audio': 'AC3',
|
||||
'quality': '720p',
|
||||
'quality_type': 'HD',
|
||||
'resolution_width': 1280,
|
||||
'resolution_height': 720
|
||||
}
|
||||
data = {}
|
||||
files = group['files']['movie']
|
||||
|
||||
for file in files:
|
||||
self.getMeta(file)
|
||||
if os.path.getsize(file) < self.minimal_filesize['media']: continue # Ignore smaller files
|
||||
|
||||
meta = self.getMeta(file)
|
||||
|
||||
try:
|
||||
data['video'] = self.getCodec(file, self.codecs['video'])
|
||||
data['audio'] = meta['audio stream'][0]['compression']
|
||||
data['resolution_width'] = meta['video stream'][0]['image width']
|
||||
data['resolution_height'] = meta['video stream'][0]['image height']
|
||||
except:
|
||||
pass
|
||||
|
||||
if data.get('audio'): break
|
||||
|
||||
data['quality'] = fireEvent('quality.guess', files = files, extra = data, single = True)
|
||||
if not data['quality']:
|
||||
data['quality'] = fireEvent('quality.single', 'dvdr' if group['is_dvd'] else 'dvdrip', single = True)
|
||||
|
||||
data['quality_type'] = 'HD' if data.get('resolution_width', 0) >= 720 else 'SD'
|
||||
|
||||
data['group'] = self.getGroup(file[0])
|
||||
data['source'] = self.getSourceMedia(file[0])
|
||||
|
||||
return data
|
||||
|
||||
def getMeta(self, filename):
|
||||
lib_dir = os.path.join(Env.get('app_dir'), 'libs')
|
||||
@@ -281,40 +306,58 @@ class Scanner(Plugin):
|
||||
|
||||
try:
|
||||
meta = json.loads(z)
|
||||
log.info('Retrieved metainfo: %s' % meta)
|
||||
return meta
|
||||
except Exception, e:
|
||||
print e
|
||||
log.error('Couldn\'t get metadata from file')
|
||||
except Exception:
|
||||
log.error('Couldn\'t get metadata from file: %s' % traceback.format_exc())
|
||||
|
||||
def determineMovie(self, group):
|
||||
imdb_id = None
|
||||
|
||||
files = group['files']
|
||||
# Check and see if nfo contains the imdb-id
|
||||
try:
|
||||
for nfo_file in files['nfo']:
|
||||
imdb_id = self.getImdb(nfo_file)
|
||||
if imdb_id: break
|
||||
except:
|
||||
pass
|
||||
|
||||
# Check if path is already in db
|
||||
db = get_session()
|
||||
# Check for CP(imdb_id) string in the file paths
|
||||
for file in files['movie']:
|
||||
f = db.query(File).filter_by(path = toUnicode(file)).first()
|
||||
imdb_id = self.getCPImdb(file)
|
||||
if imdb_id: break
|
||||
|
||||
# Check and see if nfo contains the imdb-id
|
||||
if not imdb_id:
|
||||
try:
|
||||
imdb_id = f.library[0].identifier
|
||||
break
|
||||
for nfo_file in files['nfo']:
|
||||
imdb_id = self.getImdb(nfo_file)
|
||||
if imdb_id: break
|
||||
except:
|
||||
pass
|
||||
db.remove()
|
||||
|
||||
# Check if path is already in db
|
||||
if not imdb_id:
|
||||
db = get_session()
|
||||
for file in files['movie']:
|
||||
f = db.query(File).filter_by(path = toUnicode(file)).first()
|
||||
try:
|
||||
imdb_id = f.library[0].identifier
|
||||
break
|
||||
except:
|
||||
pass
|
||||
db.remove()
|
||||
|
||||
# Search based on OpenSubtitleHash
|
||||
if not imdb_id and not group['is_dvd']:
|
||||
for file in files['movie']:
|
||||
movie = fireEvent('provider.movie.by_hash', file = file, merge = True)
|
||||
|
||||
if len(movie) > 0:
|
||||
imdb_id = movie[0]['imdb']
|
||||
if imdb_id: break
|
||||
|
||||
# Search based on identifiers
|
||||
if not imdb_id:
|
||||
for identifier in group['identifiers']:
|
||||
|
||||
if len(identifier) > 2:
|
||||
|
||||
movie = fireEvent('provider.movie.search', q = identifier, merge = True, limit = 1)
|
||||
|
||||
if len(movie) > 0:
|
||||
imdb_id = movie[0]['imdb']
|
||||
if imdb_id: break
|
||||
@@ -329,7 +372,7 @@ class Scanner(Plugin):
|
||||
}, update_after = False, single = True)
|
||||
|
||||
log.error('No imdb_id found for %s.' % group['identifiers'])
|
||||
return False
|
||||
return {}
|
||||
|
||||
def saveFile(self, file, type = 'unknown', include_media_info = False):
|
||||
|
||||
@@ -342,6 +385,17 @@ class Scanner(Plugin):
|
||||
# Check database and update/insert if necessary
|
||||
return fireEvent('file.add', path = file, part = self.getPartNumber(file), type = self.file_types[type], properties = properties, single = True)
|
||||
|
||||
def getCPImdb(self, string):
|
||||
|
||||
try:
|
||||
m = re.search('(cp\((?P<id>tt[0-9{7}]+)\))', string.lower())
|
||||
id = m.group('id')
|
||||
if id: return id
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
return False
|
||||
|
||||
def getImdb(self, txt):
|
||||
|
||||
if os.path.isfile(txt):
|
||||
@@ -375,6 +429,9 @@ class Scanner(Plugin):
|
||||
def getSubtitles(self, files):
|
||||
return set(filter(lambda s: getExt(s.lower()) in self.extensions['subtitle'], files))
|
||||
|
||||
def getSubtitlesExtras(self, files):
|
||||
return set(filter(lambda s: getExt(s.lower()) in self.extensions['subtitle_extra'], files))
|
||||
|
||||
def getNfo(self, files):
|
||||
return set(filter(lambda s: getExt(s.lower()) in self.extensions['nfo'], files))
|
||||
|
||||
@@ -447,20 +504,42 @@ class Scanner(Plugin):
|
||||
return set(filter(lambda s:identifier in self.createFileIdentifier(s, folder), file_pile))
|
||||
|
||||
def createFileIdentifier(self, file_path, folder, exclude_filename = False):
|
||||
|
||||
identifier = file_path.replace(folder, '') # root folder
|
||||
identifier = os.path.splitext(identifier)[0] # ext
|
||||
|
||||
if exclude_filename:
|
||||
identifier = identifier[:len(identifier) - len(os.path.split(identifier)[-1])]
|
||||
identifier = self.removeMultipart(identifier) # multipart
|
||||
|
||||
return identifier
|
||||
# multipart
|
||||
identifier = self.removeMultipart(identifier)
|
||||
|
||||
# groups, release tags, scenename cleaner, regex isn't correct
|
||||
identifier = re.sub(self.clean, '::', simplifyString(identifier))
|
||||
|
||||
year = self.findYear(identifier)
|
||||
if year:
|
||||
identifier = '%s %s' % (identifier.split(year)[0].strip(), year)
|
||||
else:
|
||||
identifier = identifier.split('::')[0]
|
||||
|
||||
# Remove duplicates
|
||||
out = []
|
||||
for word in identifier.split():
|
||||
if not word in out:
|
||||
out.append(word)
|
||||
|
||||
identifier = ' '.join(out)
|
||||
|
||||
return simplifyString(identifier)
|
||||
|
||||
|
||||
def removeMultipart(self, name):
|
||||
for regex in self.multipart_regex:
|
||||
try:
|
||||
found = re.sub(regex, '', name)
|
||||
if found != name:
|
||||
return found
|
||||
name = found
|
||||
except:
|
||||
pass
|
||||
return name
|
||||
@@ -475,3 +554,33 @@ class Scanner(Plugin):
|
||||
except:
|
||||
pass
|
||||
return name
|
||||
|
||||
def getCodec(self, filename, codecs):
|
||||
codecs = map(re.escape, codecs)
|
||||
try:
|
||||
codec = re.search('[^A-Z0-9](?P<codec>' + '|'.join(codecs) + ')[^A-Z0-9]', filename, re.I)
|
||||
return (codec and codec.group('codec')) or ''
|
||||
except:
|
||||
return ''
|
||||
|
||||
def getGroup(self, file):
|
||||
try:
|
||||
group = re.search('-(?P<group>[A-Z0-9]+)$', file, re.I)
|
||||
return group.group('group') or ''
|
||||
except:
|
||||
return ''
|
||||
|
||||
def getSourceMedia(self, file):
|
||||
for media in self.source_media:
|
||||
for alias in self.source_media[media]:
|
||||
if alias in file.lower():
|
||||
return media
|
||||
|
||||
return None
|
||||
|
||||
def findYear(self, text):
|
||||
matches = re.search('(?P<year>[0-9]{4})', text)
|
||||
if matches:
|
||||
return matches.group('year')
|
||||
|
||||
return ''
|
||||
|
||||
@@ -19,7 +19,7 @@ class Searcher(Plugin):
|
||||
|
||||
# Schedule cronjob
|
||||
fireEvent('schedule.cron', 'searcher.all', self.all, day = self.conf('cron_day'), hour = self.conf('cron_hour'), minute = self.conf('cron_minute'))
|
||||
addEvent('app.load', self.all)
|
||||
#addEvent('app.load', self.all)
|
||||
|
||||
def all(self):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user