def abortRequested():
return abort
# Monitor class which will get called when the settings change
python类Monitor()的实例源码
def __init__(self):
xbmc.Monitor.__init__(self)
# Init settings
settings.init()
# This is the function that signals that the user just changed a setting.
# First default settings will be loaded, then we read the user-defined settings and
# overwrite these default settings if needed.
def update_youtube_dl_core(url,name,action_type):
#credit to ruuk for most of the download code
import tarfile
if action_type=='download':
newVersion=note_ytdl_versions()
LATEST_URL=YTDL_LATEST_URL_TEMPLATE.format(newVersion)
profile = xbmc.translatePath(profile_path) #xbmc.translatePath(addon.getAddonInfo('profile')).decode('utf-8')
archivePath = os.path.join(profile,'youtube_dl.tar.gz')
extractedPath = os.path.join(profile,'youtube-dl')
extracted_core_path=os.path.join(extractedPath,'youtube_dl')
#ytdl_core_path xbmc.translatePath( addon_path+"/resources/lib/youtube_dl/" )
try:
if os.path.exists(extractedPath):
shutil.rmtree(extractedPath, ignore_errors=True)
update_dl_status('temp files removed')
update_dl_status('Downloading {0} ...'.format(newVersion))
log(' From: {0}'.format(LATEST_URL))
log(' to: {0}'.format(archivePath))
urllib.urlretrieve(LATEST_URL,filename=archivePath)
if os.path.exists(archivePath):
update_dl_status('Extracting ...')
with tarfile.open(archivePath,mode='r:gz') as tf:
members = [m for m in tf.getmembers() if m.name.startswith('youtube-dl/youtube_dl')] #get just the files from the youtube_dl source directory
tf.extractall(path=profile,members=members)
else:
update_dl_status('Download failed')
except Exception as e:
update_dl_status('Error:' + str(e))
update_dl_status('Updating...')
if os.path.exists(extracted_core_path):
log( ' extracted dir exists:'+extracted_core_path)
if os.path.exists(ytdl_core_path):
log( ' destination dir exists:'+ytdl_core_path)
shutil.rmtree(ytdl_core_path, ignore_errors=True)
update_dl_status(' Old ytdl core removed')
xbmc.sleep(1000)
try:
shutil.move(extracted_core_path, ytdl_core_path)
update_dl_status(' New core copied')
xbmc.sleep(1000)
update_dl_status('Update complete')
xbmc.Monitor().waitForAbort(2.0)
#ourVersion=ytdl_get_version_info('local')
setSetting('ytdl_btn_check_version', "")
setSetting('ytdl_btn_download', "")
except Exception as e:
update_dl_status('Failed...')
log( 'move failed:'+str(e))
elif action_type=='checkversion':
note_ytdl_versions()
def get_stream(url, airing_id, channel_id, program_id, series_id, tms_id, title, plot):
headers = {'Accept': '*/*',
'Content-type': 'application/x-www-form-urlencoded',
'Origin': 'https://vue.playstation.com',
'Accept-Language': 'en-US,en;q=0.8',
'Referer': 'https://vue.playstation.com/watch/live',
'Accept-Encoding': 'gzip, deflate, br',
'User-Agent': UA_ANDROID_TV,
'Connection': 'Keep-Alive',
'Host': 'media-framework.totsuko.tv',
'reqPayload': ADDON.getSetting(id='EPGreqPayload'),
'X-Requested-With': 'com.snei.vue.android'
}
r = requests.get(url, headers=headers, cookies=load_cookies(), verify=VERIFY)
json_source = r.json()
stream_url = json_source['body']['video']
headers = '|User-Agent='
headers += 'Adobe Primetime/1.4 Dalvik/2.1.0 (Linux; U; Android 6.0.1 Build/MOB31H)'
headers += '&Cookie=reqPayload=' + urllib.quote('"' + ADDON.getSetting(id='EPGreqPayload') + '"')
listitem = xbmcgui.ListItem()
# Checks to see if VideoPlayer info is already saved. If not then info is loaded from stream link
if xbmc.getCondVisibility('String.IsEmpty(ListItem.Title)'):
listitem = xbmcgui.ListItem(title, plot)
listitem.setInfo(type="Video", infoLabels={'title': title, 'plot': plot})
listitem.setMimeType("application/x-mpegURL")
else:
listitem = xbmcgui.ListItem()
listitem.setMimeType("application/x-mpegURL")
if xbmc.getCondVisibility('System.HasAddon(inputstream.adaptive)'):
stream_url = json_source['body']['video_alt'] # Uses alternate Sony stream to prevent Inputstream adaptive from crashing
listitem.setProperty('inputstreamaddon', 'inputstream.adaptive')
listitem.setProperty('inputstream.adaptive.manifest_type', 'hls')
listitem.setProperty('inputstream.adaptive.stream_headers', headers)
listitem.setProperty('inputstream.adaptive.license_key', headers)
else:
stream_url += headers
listitem.setPath(stream_url)
xbmcplugin.setResolvedUrl(addon_handle, True, listitem)
# Seek to time
#Give the stream sometime to start before checking
monitor = xbmc.Monitor()
monitor.waitForAbort(10)
xbmc.log("Is playing video? " + str(xbmc.Player().isPlayingVideo()))
while xbmc.Player().isPlayingVideo() and not monitor.abortRequested():
xbmc.log("Still playing...")
monitor.waitForAbort(3)
xbmc.log("We're done, write info back to ps servers!!!")
sony = SONY()
sony.put_resume_time(airing_id, channel_id, program_id, series_id, tms_id)