def torrents_status(): session.forget(response) settings_ = w2p_tvseries_settings() gsettings = settings_.global_settings() tclient = w2p_tvseries_torrent_client_loader(gsettings.tclient) res = tclient.get_status() if res is None: response.flash = 'Unable to connect' res = [] #res = [] return dict(res=res)
def torrents_status(): session.forget(response) settings_ = w2p_tvseries_settings() gsettings = settings_.global_settings() tclient = w2p_tvseries_torrent_client_loader(gsettings.tclient) res = tclient.get_status() if res is None: response.flash = "Unable to connect" res = [] # res = [] return dict(res=res)
def client_settings_validate(): if request.vars.tclient not in ('transmission', 'deluge', 'utorrent'): return sj.dumps(dict(error="Client is not supported")) tclient = w2p_tvseries_torrent_client_loader(request.vars.tclient) tclient.username = request.vars.tusername tclient.password = request.vars.tpassword tclient.url = request.vars.turl status = tclient.get_status() if status is None: return dict(status='error', message="Connection error, please check it out") else: return dict(status='ok', message='all ok')
def client_settings_validate(): if request.vars.tclient not in ('transmission', 'deluge', 'utorrent'): return sj.dumps(dict(error="Client is not supported")) tclient = w2p_tvseries_torrent_client_loader(request.vars.tclient) tclient.username = request.vars.tusername tclient.password = request.vars.tpassword tclient.url = request.vars.turl status = tclient.get_status() if status is None: return dict(status='error', message="Connection error, please check it out") else: return dict(status='ok', message='all ok')
def download_torrents(self, seriesid, seasonnumber): fname = "down_torrents" db = current.w2p_tvseries.database dw = db.downloads ep = db.episodes gs = w2p_tvseries_settings().global_settings() torrent_path = gs.torrent_path torrent_magnet = gs.torrent_magnet or 'N' if not torrent_path: self.error(fname, "torrent_path not set") return if not os.path.exists(torrent_path): self.error(fname, "torrent_path %s not found" % (torrent_path)) return if torrent_magnet == 'ST': #retrieve current torrent client configured tclient = gs.tclient from w2p_tvseries_clients import w2p_tvseries_torrent_client_loader tc = w2p_tvseries_torrent_client_loader(tclient, gsettings=gs) if torrent_magnet <> 'N': #find magnets to serialize res = db( (dw.queued == False) & (dw.magnet != None) & (dw.magnet != '') & (dw.series_id == seriesid) & (dw.seasonnumber == seasonnumber) ).select() for row in res: if not self.magnetdnr.search(row.magnet): ep_name = db(ep.id == row.episode_id).select(ep.name).first() ep_name = ep_name and ep_name.name or row.episode_id ep_name = urllib.urlencode({'dn' : ep_name}) row.magnet = "%s&%s" % (row.magnet, ep_name) if torrent_magnet == 'ST': if tc.add_magnet(row.magnet): row.update_record(queued=True, queued_at=datetime.datetime.utcnow()) db.commit() time.sleep(1) #avoid DDoS to the client else: db.rollback() else: filename = os.path.join(torrent_path, "catalog.magnet") if torrent_magnet == 'MF': filename = os.path.join(torrent_path, "%s.magnet" % (row.id)) try: with open(filename, 'a') as g: g.write(row.magnet + '\n') row.update_record(queued=True, queued_at=datetime.datetime.utcnow()) db.commit() except: self.error(fname, "Cannot write to %s" % (filename)) db.rollback() if torrent_magnet in ('N', 'ST'): #find torrents to download (also for adding to client if no magnet link is there) res = db( (dw.queued == False) & (dw.series_id == seriesid) & (dw.seasonnumber == seasonnumber) ).select() for row in res: if not row.link: row.link = self.get_torrent_from_magnet(row.magnet) row.update_record(link=row.link) if not row.down_file: content = self.downloader(row.link) if content == None and row.magnet: newurl = self.get_torrent_from_magnet(row.magnet) if newurl: content = self.downloader(newurl) if content == None: self.error(fname, "Can't download %s " % row.link) continue else: row.update_record(down_file=content) else: content = row.down_file filename = row.link.split('/')[-1] filename = os.path.join(torrent_path, filename) try: with open(filename, 'wb') as g: g.write(content) except: self.error(fname, "Cannot write to %s" % (filename)) db.rollback() continue if torrent_magnet == 'ST': if tc.add_torrent(filename): row.update_record(queued=True, queued_at=datetime.datetime.utcnow()) self.log(fname, "added to client %s" % (row.link)) db.commit() time.sleep(1) #avoid DDoS to the client else: row.update_record(queued=True, queued_at=datetime.datetime.utcnow()) self.log(fname, "added to client %s" % (row.link)) db.commit()