def sync_request(self, request_type='', data=False):
sync_url = obplayer.Config.setting('sync_url')
if not sync_url:
obplayer.Log.log("sync url is blank, skipping sync request", 'sync')
return ''
curl = pycurl.Curl()
postfields = {}
postfields['id'] = obplayer.Config.setting('sync_device_id')
postfields['pw'] = obplayer.Config.setting('sync_device_password')
postfields['hbuffer'] = obplayer.Config.setting('sync_buffer')
if data:
postfields['data'] = data
enc_postfields = urllib.urlencode(postfields)
curl.setopt(pycurl.NOSIGNAL, 1)
curl.setopt(pycurl.USERAGENT, 'OpenBroadcaster Player')
curl.setopt(pycurl.URL, sync_url + '?action=' + request_type)
curl.setopt(pycurl.HEADER, False)
curl.setopt(pycurl.POST, True)
curl.setopt(pycurl.POSTFIELDS, enc_postfields)
# some options so that it'll abort the transfer if the speed is too low (i.e., network problem)
# low speed abort set to 0.01Kbytes/s for 60 seconds).
curl.setopt(pycurl.LOW_SPEED_LIMIT, 10)
curl.setopt(pycurl.LOW_SPEED_TIME, 60)
curl.setopt(pycurl.NOPROGRESS, 0)
curl.setopt(pycurl.PROGRESSFUNCTION, self.curl_progress)
class CurlResponse:
def __init__(self):
self.buffer = u''
def __call__(self, data):
self.buffer += data.decode('utf-8')
curl_response = CurlResponse()
curl.setopt(pycurl.WRITEFUNCTION, curl_response)
try:
curl.perform()
#except pycurl.error as error:
# (errno, errstr) = error
# obplayer.Log.log('network error: ' + errstr, 'error')
except:
obplayer.Log.log("exception in sync " + request_type + " thread", 'error')
obplayer.Log.log(traceback.format_exc(), 'error')
curl.close()
return curl_response.buffer
#
# Fetch media from web application. Saves under media directory.
# media_id : id of the media we want
# filename : filename to save under.
#
评论列表
文章目录