Initial trailer support

This commit is contained in:
Ruud
2012-02-21 18:50:43 +01:00
parent e011a59a52
commit 6a58816729
4 changed files with 92 additions and 22 deletions
@@ -0,0 +1,34 @@
from .main import Trailer
def start():
return Trailer()
config = [{
'name': 'trailer',
'groups': [
{
'tab': 'metadata',
'name': 'trailer',
'options': [
{
'name': 'enabled',
'label': 'Search and download trailers',
'default': False,
'type': 'enabler',
},
{
'name': 'quality',
'default': '720p',
'type': 'dropdown',
'values': [('1080P', '1080p'), ('720P', '720p'), ('480P', '480p')],
},
{
'name': 'automatic',
'default': False,
'type': 'bool',
'description': 'Automaticly search & download for movies in library',
},
],
},
],
}]
+32
View File
@@ -0,0 +1,32 @@
from couchpotato.core.event import addEvent, fireEvent
from couchpotato.core.helpers.variable import getExt
from couchpotato.core.logger import CPLog
from couchpotato.core.plugins.base import Plugin
import os
log = CPLog(__name__)
class Trailer(Plugin):
def __init__(self):
addEvent('renamer.after', self.searchSingle)
def searchSingle(self, group):
if self.isDisabled() or len(group['files']['trailer']) > 0: return
trailers = fireEvent('trailer.search', group = group, merge = True)
for trailer in trailers.get(self.conf('quality'), []):
destination = '%s-trailer.%s' % (self.getRootName(group), getExt(trailer))
if not os.path.isfile(destination):
fireEvent('file.download', url = trailer, dest = destination, urlopen_kwargs = {'headers': {'User-Agent': 'Quicktime'}}, single = True)
else:
log.debug('Trailer already exists: %s' % destination)
# Download first and break
break
def getRootName(self, data = {}):
return os.path.join(data['destination_dir'], data['filename'])