committed by
GitHub
17 changed files with 390 additions and 24 deletions
@ -0,0 +1,136 @@ |
|||||
|
from datetime import datetime |
||||
|
from couchpotato.core.helpers.variable import tryInt |
||||
|
from couchpotato.core.logger import CPLog |
||||
|
from couchpotato.core.helpers.variable import getTitle |
||||
|
from couchpotato.core.media._base.providers.torrent.base import TorrentMagnetProvider |
||||
|
import random |
||||
|
|
||||
|
log = CPLog(__name__) |
||||
|
|
||||
|
|
||||
|
class Base(TorrentMagnetProvider): |
||||
|
# Only qualities allowed: 720p/1080p/3D - the rest will fail. |
||||
|
# All YTS.ag torrents are verified |
||||
|
urls = { |
||||
|
'detail': 'https://yts.ag/api#list_movies', |
||||
|
'search': 'https://yts.ag/api/v2/list_movies.json?query_term=%s&limit=%s&page=%s' |
||||
|
} |
||||
|
|
||||
|
def _search(self, movie, quality, results): |
||||
|
limit = 10 |
||||
|
page = 1 |
||||
|
data = self.getJsonData(self.urls['search'] % (getTitle(movie), limit, page)) |
||||
|
|
||||
|
if data: |
||||
|
movie_count = tryInt(data['data']['movie_count']) |
||||
|
|
||||
|
if movie_count == 0: |
||||
|
log.debug('%s - found no results', (self.getName())) |
||||
|
else: |
||||
|
|
||||
|
movie_results = data['data']['movies'] |
||||
|
for i in range(0,len(movie_results)): |
||||
|
result = data['data']['movies'][i] |
||||
|
name = result['title'] |
||||
|
|
||||
|
t = movie['info']['original_title'].split(' ') |
||||
|
|
||||
|
if all(word in name for word in t) and movie['info']['year'] == result['year']: |
||||
|
|
||||
|
year = result['year'] |
||||
|
detail_url = result['url'] |
||||
|
|
||||
|
for torrent in result['torrents']: |
||||
|
t_quality = torrent['quality'] |
||||
|
|
||||
|
if t_quality in quality['label']: |
||||
|
hash = torrent['hash'] |
||||
|
size = tryInt(torrent['size_bytes'] / 1048576) |
||||
|
seeders = tryInt(torrent['seeds']) |
||||
|
leechers = tryInt(torrent['peers']) |
||||
|
pubdate = torrent['date_uploaded'] # format: 2017-02-17 18:40:03 |
||||
|
pubdate = datetime.strptime(pubdate, '%Y-%m-%d %H:%M:%S') |
||||
|
age = (datetime.now() - pubdate).days |
||||
|
|
||||
|
results.append({ |
||||
|
'id': random.randint(100, 9999), |
||||
|
'name': '%s (%s) %s %s %s' % (name, year, 'YTS', t_quality, 'BR-Rip'), |
||||
|
'url': self.make_magnet(hash, name), |
||||
|
'size': size, |
||||
|
'seeders': seeders, |
||||
|
'leechers': leechers, |
||||
|
'age': age, |
||||
|
'detail_url': detail_url, |
||||
|
'score': 1 |
||||
|
}) |
||||
|
|
||||
|
return |
||||
|
|
||||
|
def make_magnet(self, hash, name): |
||||
|
url_encoded_trackers = 'udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce&tr=%0Audp%3A%2F%2Ftracker.openbittorr' \ |
||||
|
'ent.com%3A80&tr=%0Audp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=%0Audp%3A%2F%2Fglot' \ |
||||
|
'orrents.pw%3A6969%2Fannounce&tr=%0Audp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannou' \ |
||||
|
'nce&tr=%0Audp%3A%2F%2Ftorrent.gresille.org%3A80%2Fannounce&tr=%0Audp%3A%2F%2Fp4p.are' \ |
||||
|
'nabg.com%3A1337&tr=%0Audp%3A%2F%2Ftracker.leechers-paradise.org%3A6969]' |
||||
|
|
||||
|
return 'magnet:?xt=urn:btih:%s&dn=%s&tr=%s' % (hash, name.replace(' ', '+'), url_encoded_trackers) |
||||
|
|
||||
|
|
||||
|
config = [{ |
||||
|
'name': 'yts', |
||||
|
'groups': [ |
||||
|
{ |
||||
|
'tab': 'searcher', |
||||
|
'list': 'torrent_providers', |
||||
|
'name': 'YTS', |
||||
|
'description': '<a href="https://yts.ag/" target="_blank">YTS</a>', |
||||
|
'wizard': True, |
||||
|
'icon': 'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAACL0lEQVR4AS1SPW/UQBAd23fxne/Ld2dvzvHuzPocEBAKokCBqG' |
||||
|
'iQ6IgACYmvUKRBFEQgKKGg4BAlUoggggYUEQpSHOI7CIEoQs/fYcbLaU/efTvvvZlnA1qydoxU5kcxX0CkgmQZtPy0hCUjvK+W' |
||||
|
'gEByOZ5dns1O5bzna8fRVkgsxH8B0YouIvBhdD5T11NiVOoKrsttyUcpRW0InUrFnwe9HzuP2uaQZYhF2LQ76TTXw2RVMTK8mY' |
||||
|
'Ybjfh+zNquMVCrqn93aArLSixPxnafdGDLaz1tjY5rmNa8z5BczEQOxQfCl1GyoqoWxYRN1bkh7ELw3q/vhP6HIL4TG9Kumpjg' |
||||
|
'vwuyM7OsjSj98E/vszMfZ7xvPtMaWxGO5crwIumKCR5HxDtJ0AWKGG204RfUd/3smJYqwem/Q7BTS1ZGfM4LNpVwuKAz6cMeRO' |
||||
|
'st0S2EwNE7GjTehO2H3dxqIpdkydat15G3F8SXBi4GlpBNlSz012L/k2+W0CLLk/jbcf13rf41yJeMQ8QWUZiHCfCA9ad+81nE' |
||||
|
'KPtoS9mJOf9v0NmMJHgUT6xayheK9EIK7JJeU/AF4scDF7Y5SPlJrRcxJ+um4ibNEdObxLiIwJim+eT2AL5D9CIcnZ5zvSJi9e' |
||||
|
'IlNHVVtZ831dk5svPgvjPWTq+ktWkd/kD0qtm71x+sDQe3kt6DXnM7Ct+GajmTxKlkAokWljyAKSm5oWa2w+BH4P2UuVub7eTy' |
||||
|
'iGOQYapY/wEztHduSDYz5gAAAABJRU5ErkJggg==', |
||||
|
|
||||
|
'options': [ |
||||
|
{ |
||||
|
'name': 'enabled', |
||||
|
'type': 'enabler', |
||||
|
'default': False |
||||
|
}, |
||||
|
{ |
||||
|
'name': 'seed_ratio', |
||||
|
'label': 'Seed ratio', |
||||
|
'type': 'float', |
||||
|
'default': 1, |
||||
|
'description': 'Will not be (re)moved until this seed ratio is met.', |
||||
|
}, |
||||
|
{ |
||||
|
'name': 'seed_time', |
||||
|
'label': 'Seed time', |
||||
|
'type': 'int', |
||||
|
'default': 40, |
||||
|
'description': 'Will not be (re)moved until this seed time (in hours) is met.', |
||||
|
}, |
||||
|
{ |
||||
|
'name': 'info', |
||||
|
'label': 'Info', |
||||
|
'type':'bool', |
||||
|
'default':'False', |
||||
|
'description': 'YTS will only work if you set the minimum size for 720p to 500 and 1080p to 800', |
||||
|
}, |
||||
|
{ |
||||
|
'name': 'extra_score', |
||||
|
'advanced': True, |
||||
|
'label': 'Extra Score', |
||||
|
'type': 'int', |
||||
|
'default': 0, |
||||
|
'description': 'Starting score for each release found via this provider.', |
||||
|
} |
||||
|
], |
||||
|
} |
||||
|
] |
||||
|
}] |
@ -0,0 +1,10 @@ |
|||||
|
from couchpotato.core.logger import CPLog |
||||
|
from couchpotato.core.media._base.providers.torrent.yts import Base |
||||
|
from couchpotato.core.media.movie.providers.base import MovieProvider |
||||
|
|
||||
|
log = CPLog(__name__) |
||||
|
|
||||
|
autoload = 'Yts' |
||||
|
|
||||
|
class Yts(MovieProvider, Base): |
||||
|
pass |
@ -0,0 +1,93 @@ |
|||||
|
from couchpotato.core.logger import CPLog |
||||
|
from couchpotato.core.notifications.base import Notification |
||||
|
import json |
||||
|
import requests |
||||
|
|
||||
|
log = CPLog(__name__) |
||||
|
autoload = 'Discord' |
||||
|
|
||||
|
|
||||
|
class Discord(Notification): |
||||
|
required_confs = ('webhook_url',) |
||||
|
|
||||
|
def notify(self, message='', data=None, listener=None): |
||||
|
for key in self.required_confs: |
||||
|
if not self.conf(key): |
||||
|
log.warning('Discord notifications are enabled, but ' |
||||
|
'"{0}" is not specified.'.format(key)) |
||||
|
return False |
||||
|
|
||||
|
data = data or {} |
||||
|
message = message.strip() |
||||
|
|
||||
|
if self.conf('include_imdb') and 'identifier' in data: |
||||
|
template = ' http://www.imdb.com/title/{0[identifier]}/' |
||||
|
message += template.format(data) |
||||
|
|
||||
|
headers = {b"Content-Type": b"application/json"} |
||||
|
try: |
||||
|
r = requests.post(self.conf('webhook_url'), data=json.dumps(dict(content=message, username=self.conf('bot_name'), avatar_url=self.conf('avatar_url'), tts=self.conf('discord_tts'))), headers=headers) |
||||
|
r.status_code |
||||
|
except Exception as e: |
||||
|
log.warning('Error Sending Discord response error code: {0}'.format(r.status_code)) |
||||
|
return False |
||||
|
return True |
||||
|
|
||||
|
|
||||
|
config = [{ |
||||
|
'name': 'discord', |
||||
|
'groups': [ |
||||
|
{ |
||||
|
'tab': 'notifications', |
||||
|
'list': 'notification_providers', |
||||
|
'name': 'discord', |
||||
|
'options': [ |
||||
|
{ |
||||
|
'name': 'enabled', |
||||
|
'default': 0, |
||||
|
'type': 'enabler', |
||||
|
}, |
||||
|
{ |
||||
|
'name': 'webhook_url', |
||||
|
'description': ( |
||||
|
'Your Discord authentication webhook URL.', |
||||
|
'Created under channel settings.' |
||||
|
) |
||||
|
}, |
||||
|
{ |
||||
|
'name': 'include_imdb', |
||||
|
'default': True, |
||||
|
'type': 'bool', |
||||
|
'descrpition': 'Include a link to the movie page on IMDB.' |
||||
|
}, |
||||
|
{ |
||||
|
'name': 'bot_name', |
||||
|
'description': 'Name of bot.', |
||||
|
'default': 'CouchPotato', |
||||
|
'advanced': True, |
||||
|
}, |
||||
|
{ |
||||
|
'name': 'avatar_url', |
||||
|
'description': 'URL to an image to use as the avatar for ' |
||||
|
'notifications.', |
||||
|
'default': 'https://couchpota.to/media/images/couch.png', |
||||
|
'advanced': True, |
||||
|
}, |
||||
|
{ |
||||
|
'name': 'discord_tts', |
||||
|
'default': 0, |
||||
|
'type': 'bool', |
||||
|
'advanced': True, |
||||
|
'description': 'Send notification using text-to-speech.', |
||||
|
}, |
||||
|
{ |
||||
|
'name': 'on_snatch', |
||||
|
'default': 0, |
||||
|
'type': 'bool', |
||||
|
'advanced': True, |
||||
|
'description': 'Also send message when movie is snatched.', |
||||
|
}, |
||||
|
], |
||||
|
} |
||||
|
], |
||||
|
}] |
@ -0,0 +1,58 @@ |
|||||
|
import traceback |
||||
|
import subprocess |
||||
|
|
||||
|
from couchpotato.core.helpers.encoding import toUnicode |
||||
|
from couchpotato.core.helpers.variable import getIdentifier |
||||
|
from couchpotato.core.logger import CPLog |
||||
|
from couchpotato.core.notifications.base import Notification |
||||
|
|
||||
|
|
||||
|
log = CPLog(__name__) |
||||
|
|
||||
|
autoload = 'Script' |
||||
|
|
||||
|
class Script(Notification): |
||||
|
|
||||
|
def notify(self, message = '', data = None, listener = None): |
||||
|
if not data: data = {} |
||||
|
|
||||
|
script_data = { |
||||
|
'message': toUnicode(message) |
||||
|
} |
||||
|
|
||||
|
if getIdentifier(data): |
||||
|
script_data.update({ |
||||
|
'imdb_id': getIdentifier(data) |
||||
|
}) |
||||
|
|
||||
|
try: |
||||
|
subprocess.call([self.conf('path'), message]) |
||||
|
return True |
||||
|
except: |
||||
|
log.error('Script notification failed: %s', traceback.format_exc()) |
||||
|
|
||||
|
return False |
||||
|
|
||||
|
|
||||
|
config = [{ |
||||
|
'name': 'script', |
||||
|
'groups': [ |
||||
|
{ |
||||
|
'tab': 'notifications', |
||||
|
'list': 'notification_providers', |
||||
|
'name': 'script', |
||||
|
'label': 'Script', |
||||
|
'options': [ |
||||
|
{ |
||||
|
'name': 'enabled', |
||||
|
'default': 0, |
||||
|
'type': 'enabler', |
||||
|
}, |
||||
|
{ |
||||
|
'name': 'path', |
||||
|
'description': 'The path to the script to execute.' |
||||
|
} |
||||
|
] |
||||
|
} |
||||
|
] |
||||
|
}] |
Loading…
Reference in new issue