本文整理汇总了Python中cache.Cache.play_position方法的典型用法代码示例。如果您正苦于以下问题:Python Cache.play_position方法的具体用法?Python Cache.play_position怎么用?Python Cache.play_position使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cache.Cache
的用法示例。
在下文中一共展示了Cache.play_position方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BaseClient
# 需要导入模块: from cache import Cache [as 别名]
# 或者: from cache.Cache import play_position [as 别名]
class BaseClient(object):
class Monitor(BaseMonitor):
def __init__(self, client):
super(BaseClient.Monitor,self).__init__(client, name="Status Monitor" )
self._client=client
def run(self):
while (self._running):
s = self._client.status
with self._lock:
for cb in self._listeners:
cb(s, client=self._client)
self._wait_event.wait(1.0)
def __init__(self, path_to_store, args=None):
self._base_path=path_to_store
self._ready=False
self._file = None
self._cache=Cache(path_to_store)
self._on_ready_action=None
self._monitor= BaseClient.Monitor(self)
if not args or not args.quiet:
self.add_monitor_listener(self.print_status)
self._delete_on_close=True if args and args.delete_on_finish else False
def _on_file_ready(self, filehash):
self._file.filehash=filehash
self._ready=True
if self._on_ready_action:
self._on_ready_action(self._file, self.is_file_complete)
@property
def status(self):
raise NotImplementedError()
def get_normalized_status(self):
s=self.status
return {'source_type':'base',
'state':s.state,
'downloaded':s.downloaded,
'total_size':s.total_size,
'download_rate':s.download_rate,
'desired_rate':s.desired_rate,
'progress': s.progress,
'piece_size': self._file.piece_size if self._file else 0
}
@property
def file(self):
return self._file
def set_on_file_ready(self, action):
self._on_ready_action=action
@property
def is_file_ready(self):
return self._ready
def print_status(self,s,client):
raise NotImplementedError()
@property
def is_file_complete(self):
raise NotImplementedError()
def start_url(self, uri):
raise NotImplementedError()
def close(self):
if self._cache:
self._cache.close()
if self._delete_on_close and self._file:
self._file.remove()
@property
def unique_file_id(self):
raise NotImplementedError()
def update_play_time(self, playtime):
self._cache.play_position(self.unique_file_id, playtime)
@property
def last_play_time(self):
return self._cache.get_last_position(self.unique_file_id)
def add_monitor_listener(self, cb):
self._monitor.add_listener(cb)
def remove_monitor_listener(self,cb):
self._monitor.remove_listener(cb)
def stop(self):
self._monitor.stop()
self._monitor.join()