def Lookup(id): oc = ObjectContainer() id = int(id) client = putio.Client(Prefs['access_token']) f = client.File.get(id) if f.content_type.startswith('video/'): oc.add(VideoClipObject( key=Callback(Lookup, id=f.id), items=[MediaObject(parts=[PartObject(key=Callback(PlayMedia, url=f.stream_url))])], rating_key=f.id, title=f.name, thumb=f.screenshot)) elif f.content_type.startswith('audio/'): oc.add(TrackObject( key=Callback(Lookup, id=f.id), items=[MediaObject(parts=[PartObject(key=Callback(PlayMedia, url=f.stream_url))])], rating_key=f.id, title=f.name, thumb=f.screenshot)) else: Log.Info("Unsupported content type '%s'" % f.content_type) return oc
def __init__(self, downloadstation_credentials, putio_credentials, feeds_details): nas_api = NasApi(downloadstation_credentials.url, downloadstation_credentials.username, downloadstation_credentials.password) putio_client = putio.Client(putio_credentials.token) self.download_queue_processor = DownloadQueueProcessor( nas_api, putio_client) self.feeds_details = feeds_details logging.basicConfig() self.scheduler = BlockingScheduler() self.scheduler.add_job(self.process_feeds, 'interval', minutes=feeds_details.refresh_period_in_minutes) self.scheduler.start()
def putio_callback(): code = request.args.get('code') if not code: abort(401) #generate url to get/access token. url = TOKEN_URL % (CLIENT_ID, CLIENT_SECRET, REDIRECT_URI, code) r = requests.get(url) assert r.status_code == 200 #held token if exists... token = json.loads(r.content)['access_token'] #check user's token exist or not in DB user = db.users.find_one({'token': token}) if user: user_id = user['_id'] else: user_id = db.users.insert({'token': token}) session['logged_in'] = True session['user_id'] = str(user_id) #------- Get files from server ------# #Generate a client with token we already had. client = putio.Client(token) #get user information. account_info = client.request("/account/info", method='GET') account = account_info['info'] #check extension is in suitable audio format or not and fetch files. dict = client.request("/files/search/ext:mp3", method='GET') files = dict['files'] files = [file for file in files] #get number of files. length = len(files) #Insert Files into DB. db.user_files.insert(sorted(files)) return render_template('home.html', files=files, length=length, account=account)
def ParseDirectory(id, name): oc = ObjectContainer(title1=name, view_group='InfoList') oc.add(PrefsObject(title = L('Preferences'))) token = Prefs['access_token'] if token == "": return ObjectContainer(header="Login", message="Enter your access token in Preferences.") client = putio.Client(token) try: for f in client.File.list(id): if f.content_type == 'application/x-directory': oc.add(DirectoryObject( key = Callback(ParseDirectory, id=f.id, name=f.name), title = f.name)) elif f.content_type.startswith('video/'): oc.add(VideoClipObject( key=Callback(Lookup, id=f.id), items=[MediaObject(parts=[PartObject(key=Callback(PlayMedia, url=f.stream_url))])], rating_key=f.id, title=f.name, thumb=f.screenshot)) elif f.content_type.startswith('audio/'): oc.add(TrackObject( key=Callback(Lookup, id=f.id), items=[MediaObject(parts=[PartObject(key=Callback(PlayMedia, url=f.stream_url))])], rating_key=f.id, title=f.name, thumb=f.screenshot)) else: Log.Info("Unsupported content type '%s'" % f.content_type) except: Log.Exception("Files couldn't fetch. Access token is wrong or missing.") return oc
def main(): args = parse_arguments() # Restore or obtain a valid token token_manager = TokenManager() token = token_manager.get_token() while not token_manager.is_valid_token(token): print "No valid token found! Please provide one." token = token_manager.obtain_token() token_manager.save_token(token) # Let's start syncing! putio_client = putio.Client(token) db_manager = DatabaseManager() download_manager = DownloadManager(token=token) if args.post_process_command is not None: download_manager.add_download_completion_callback( build_postprocess_download_completion_callback(args.post_process_command)) if args.watch_directory is not None: torrent_watcher = TorrentWatcher(args.watch_directory, putio_client) torrent_watcher.start() download_manager.start() synchronizer = PutioSynchronizer( download_directory=args.download_directory, putio_client=putio_client, db_manager=db_manager, download_manager=download_manager, keep_files=args.keep, poll_frequency=args.poll_frequency) t = threading.Thread(target=synchronizer.run_forever) t.setDaemon(True) t.start() web_interface = WebInterface(db_manager, download_manager, putio_client, synchronizer) web_interface.run() return 0
def setUp(self): self.client = putio.Client('123456') self.destination = tempfile.mkdtemp()
count = count + 1 os.remove(os.path.join(path, file)) if count > 0: time.sleep(30) def PutioDownload(path1, path2, folderid): TransferList = client.Transfer.list() transferlen = len(TransferList) files = client.File.list(folderid) if transferlen != 0: os.chdir(path2) for file in files: client.File.download(file) client.File.delete(file) client.Transfer.clean() Settings = GetSettings() client = putio.Client(Settings[2]) # Instanciate Client Object PutioUpload(Settings[0]) # Upload Magnet Files TorrentFolderCleanup(Settings[0]) # Cleanup Uploaded File PutioDownload(Settings[0], Settings[1], Settings[3]) #Download TV Files
def start_sync(args): formatter = logging.Formatter( '%(asctime)s | %(name)-12s | %(levelname)-8s | %(message)s') log_level = logging.ERROR if args.log_level is not None: if args.log_level == "debug": log_level = logging.DEBUG elif args.log_level == "info": log_level = logging.INFO elif args.log_level == "warning": log_level = logging.WARNING elif args.log_level == "error": log_level = logging.ERROR elif args.log_level == "critical": log_level = logging.CRITICAL else: print("Invalid log-level argument") ch = logging.StreamHandler() ch.setLevel(log_level) ch.setFormatter(formatter) if args.log is not None: fh = logging.FileHandler(args.log) fh.setLevel(log_level) fh.setFormatter(formatter) logger.addHandler(fh) else: logger.addHandler(ch) log_webif = logging.getLogger('werkzeug') log_webif.setLevel(log_level) log_webif.disabled = True if args.log_webif is not None: fh = logging.FileHandler(args.log_webif) fh.setLevel(log_level) fh.setFormatter(formatter) log_webif.addHandler(fh) else: log_webif.addHandler(ch) # Restore or obtain a valid token token_manager = TokenManager() token = token_manager.get_token() while not token_manager.is_valid_token(token): print("No valid token found! Please provide one.") token = token_manager.obtain_token() token_manager.save_token(token) # Let's start syncing! putio_client = putio.Client(token) db_manager = DatabaseManager() download_manager = DownloadManager(token=token) if args.post_process_command is not None: download_manager.add_download_completion_callback( build_postprocess_download_completion_callback( args.post_process_command)) if args.watch_directory is not None: torrent_watcher = TorrentWatcher(args.watch_directory, putio_client) torrent_watcher.start() filter_compiled = None if args.filter is not None: try: filter_compiled = re.compile(args.filter) except re.error as e: print("Invalid filter regex: {0}".format(e)) exit(1) force_keep_compiled = None if args.force_keep is not None: try: force_keep_compiled = re.compile(args.force_keep) except re.error as e: print("Invalid force_keep regex: {0}".format(e)) exit(1) download_manager.start() synchronizer = PutioSynchronizer( download_directory=args.download_directory, putio_client=putio_client, db_manager=db_manager, download_manager=download_manager, keep_files=args.keep, poll_frequency=args.poll_frequency, download_filter=filter_compiled, force_keep=force_keep_compiled, disable_progress=args.log is not None) t = threading.Thread(target=synchronizer.run_forever) t.setDaemon(True) t.start() web_interface = WebInterface(db_manager, download_manager, putio_client, synchronizer, launch_browser=(not args.quiet), host=args.host, port=args.port) web_interface.run()