本文整理汇总了Python中resources.lib.dev.log函数的典型用法代码示例。如果您正苦于以下问题:Python log函数的具体用法?Python log怎么用?Python log使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了log函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: playlist_add_episode
def playlist_add_episode(playlist, season, id, season_tag='season', type=''):
dev.log('playlist_add_episode('+season+','+id+', type='+type+')')
#Check if this playlist isnt in the xml file yet
#if xml_get_elem('season', 'episode', {'id' : id}, playlist=playlist) is None:
#Build the playlist
#doc = playlist_xml_get(playlist)
#s = doc.find("season[@number='"+season+"']")
s = xml_get_elem(season_tag, season_tag, {'number': season}, playlist=playlist, type=type)
if s is None:
playlist_add_season(playlist, season, type=type)
#doc = playlist_xml_get(playlist)
#s = doc.find("season[@number='"+season+"']")
s = xml_get_elem(season_tag, season_tag, {'number': season}, playlist=playlist, type=type)
#doc = playlist_xml_get(playlist)
global playlistdocument
attr = { 'id' : id}
elem = Element('episode', attr)
s.insert(0, elem)
root = playlistdocument.getroot()
write_xml(root, dir=dev.typeEpnr(type), output=playlist+'.xml')
dev.log('Added the episode '+id+' to '+season_tag+': '+season+' in '+dev.typeEpnr(type)+'/'+playlist+'.xml')
#else:
#dev.log('playlist_add_episode: not added episode '+id+' since the episode already exists')
示例2: playYoutubeVid
def playYoutubeVid(id, meta=None, poster=None):
'''
from resources.lib import pafy
pafy.set_api_key(vars.API_KEY)
#Resolve the youtube video url for ourselves
v = pafy.new(id)
stream_url = v.getbest().url
'''
if meta is None:
#Create an empty meta, so we can fill it with the information grabbed from youtube
meta = {}
if 'title' not in meta:
meta['title'] = v.title #Store the youtube title in the meta
if poster is None:
poster = 'Default.png'
#YDStreamExtractor.disableDASHVideo(True) #Kodi (XBMC) only plays the video for DASH streams, so you don't want these normally. Of course these are the only 1080p streams on YouTube
try:
#url = id #a youtube ID will work as well and of course you could pass the url of another site
vid = YDStreamExtractor.getVideoInfo(id,quality=1) #quality is 0=SD, 1=720p, 2=1080p and is a maximum
stream_url = vid.streamURL() #This is what Kodi (XBMC) will play
except:
dev.log('Failed to get a valid stream_url!')
return False #Failed to grab a video title
#xbmc.Player().play(v.getbest().url) #Play this video
liz = xbmcgui.ListItem(meta['title'], iconImage=poster, thumbnailImage=poster)
liz.setInfo( type="Video", infoLabels=meta )
liz.setPath(stream_url)
return xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, liz)
示例3: number_of_episodes
def number_of_episodes(playlist, season, season_tag='season', type=''):
s = xml_get_elem(season_tag, season_tag, {'number': season}, playlist=playlist, type=type)
if s == None:
dev.log('number_of_episodes('+type+'): Could not find '+season_tag+' '+season+' in playlist '+playlist)
return None
dev.log('number_of_episodes('+type+'): Found '+str(len(s))+' episodes in '+season_tag+' '+season)
return len(s)
示例4: delete_playlist
def delete_playlist(id, type=''):
#Grab the settings from this playlist
settings = m_xml.xml_get_elem('playlists/playlist', 'playlist', {'id': id}, type=type) #Grab the xml settings for this playlist
if settings is None:
dev.log('deletePlaylist: Could not find playlist '+id+' in the '+dev.typeXml(type)+' file', True)
return False
else:
i = xbmcgui.Dialog().yesno("Delete Playlist", "Are you sure you want to delete this playlist?")
if i == 0:
editPlaylist(id, type=type)
else:
if m_xml.xml_remove_playlist(id, type=type) is True:
#Remove the episodenr xml file to
file = os.path.join(vars.settingsPath+dev.typeEpnr(type), id+'.xml' )
if os.path.isfile(file):
success = os.remove(file) #Remove the episodenr xml file
xbmcgui.Dialog().ok('Removed Playlist', 'Succesfully removed playlist '+id)
i = xbmcgui.Dialog().yesno('Delete from library', 'Do you also want to delete the videos from your library?')
if i != 0:
#Check in which folder the show resides
folder = settings.find('overwritefolder').text
if folder is None or folder == '':
folder = dev.legal_filename(settings.find('title').text) #Overwrite folder is not set in settings.xml, so set the folder to the title of the show
else:
folder = dev.legal_filename(folder)
movieLibrary = vars.tv_folder #Use the directory from the addon settings
if type == 'musicvideo':
movieLibrary = vars.musicvideo_folder
elif type == 'movies':
movieLibrary = vars.movies_folder
dir = os.path.join(movieLibrary, folder) #Set the folder to the maindir/dir
success = shutil.rmtree(dir, ignore_errors=True) #Remove the directory
xbmcgui.Dialog().ok('Removed from library', 'Deleted the videos from your library (You should clean your library, otherwise they will still show in your library)')
示例5: update_playlist
def update_playlist(id, type=''):
settings = m_xml.xml_get_elem('playlists/playlist', 'playlist', {'id': id}, type=type) #Grab the xml settings for this playlist
if settings is None:
dev.log('Could not find playlist '+id+' in the '+dev.typeXml(type)+' file', True)
return False
else:
dev.log('Updating playlist %s (Id: %s)' % (settings.find('title').text.encode('utf-8'), id))
#Check in which folder the show should be added
folder = settings.find('overwritefolder').text
if folder is None or folder == '':
folder = dev.legal_filename(settings.find('title').text) #Overwrite folder is not set in settings.xml, so set the folder to the title of the show
else:
folder = dev.legal_filename(folder)
#Create the tvshow.nfo
writenfo = settings.find('writenfo').text
if writenfo != 'no':
if type == '' or type == 'tv':
generators.write_tvshow_nfo(folder, settings)
update_playlist_vids(id, folder, settings, type=type)
#Save the time this playlist got updated in the xml
import datetime
d=datetime.datetime.now()
m_xml.xml_update_playlist_attr(id, 'scansince', d.strftime("%d/%m/%Y %H:%M:%S"), type=type)
return True
示例6: write_xml
def write_xml(elem, dir='', output='', type=''):
if output == '':
output = dev.typeXml(type)
dev.log('write_xml('+type+','+output+').')
xbmcvfs.mkdir(vars.settingsPath) #Create the settings dir if it does not exist already
if dir is not '': xbmcvfs.mkdir(vars.settingsPath+dir) #Create the settings dir if it does not exist already
#Write these settings to a .xml file in the addonfolder
output_file = os.path.join(vars.settingsPath+dir, output) #Set the outputfile to settings.xml
#Creating a backup of the .xml file (in case it gets corrupted)
backupfile = os.path.join(vars.settingsPath+dir, output+'.backup')
if xbmcvfs.exists(output_file):
if xbmcvfs.copy(output_file, backupfile):
dev.log('Created a backup of the xml file at: '+backupfile)
else:
dev.log('Failed to create a backup of the xml file at: '+backupfile)
else:
dev.log(output_file+' could not be found, so not able to create a backup')
indent( elem ) #Prettify the xml so its not on one line
tree = ElementTree.ElementTree( elem ) #Convert the xml back to an element
tree.write(output_file) #Save the XML in the settings file
#For backup purposes, check if the xml got corrupted by writing just now
if xml_get(type) is False:
dev.log('corrupt .xml file')
示例7: write_strm
def write_strm(name, fold, videoid, show=None, season=None, episode=None, startpoint = None, endpoint = None, artist='', album='', song='', year='', type=''):
#dev.log('strm('+name+', '+fold+', '+videoid+')')
movieLibrary = vars.tv_folder #The path we should save in is the vars.tv_folder setting from the addon settings
if type=='musicvideo':
movieLibrary = vars.musicvideo_folder
sysname = urllib.quote_plus(videoid) #Escape strings in the videoid if needed
enc_name = dev.legal_filename(name) #Encode the filename to a legal filename
if vars.__settings__.getSetting("strm_link") == "Youtube Library":
if type == 'musicvideo':
content = 'plugin://plugin.video.youtubelibrary/?mode=playmusicvideo'
if startpoint != None:
content += '&startpoint='+startpoint
if endpoint != None:
content += '&endpoint='+endpoint
content += '&id=%s&artist=%s&song=%s&album=%s&year=%s&filename=%s' % (sysname, artist, song, album, year, enc_name) #Set the content of the strm file with a link back to this addon for playing the video
else:
content = 'plugin://plugin.video.youtubelibrary/?mode=play&id=%s&show=%s&season=%s&episode=%s&filename=%s' % (sysname, show, season, episode, enc_name) #Set the content of the strm file with a link back to this addon for playing the video
else:
content = vars.KODI_ADDONLINK+'%s' % ( sysname) #Set the content of the strm file with a link to the official Kodi Youtube Addon
xbmcvfs.mkdir(movieLibrary) #Create the maindirectory if it does not exists yet
folder = os.path.join(movieLibrary, fold) #Set the folder to the maindir/dir
xbmcvfs.mkdir(folder) #Create this subfolder if it does not exist yet
stream = os.path.join(folder, enc_name + '.strm') #Set the file to maindir/name/name.strm
file = xbmcvfs.File(stream, 'w') #Open / create this file for writing
file.write(str(content.encode('UTF-8'))) #Write the content in the file
file.close() #Close the file
dev.log('write_strm: Written strm file: '+fold+'/'+enc_name+'.strm')
return enc_name
示例8: refresh_artwork
def refresh_artwork(id, type=''):
response = ytube.yt_get_playlist_info(id)
res = response['items'][0]['snippet']
thumbnail = dev.best_thumbnail(res)
#Grab the channel information
response = ytube.yt_get_channel_info(res['channelId'])
snippet = response['items'][0]['snippet']
brand = response['items'][0]['brandingSettings']
#Check if we can do a better thumbnail
better_thumbnail = dev.best_thumbnail(snippet)
if(better_thumbnail != False):
thumbnail = better_thumbnail
if thumbnail == False:
thumbnail = ''
dev.log('The thumbnail now: '+thumbnail)
bannerTv = brand['image']['bannerImageUrl']
if 'bannerTvImageUrl' in brand['image']:
bannerTv = brand['image']['bannerTvImageUrl']
m_xml.xml_update_playlist_setting(id, 'thumb', thumbnail, type=type) #Save the new setting
m_xml.xml_update_playlist_setting(id, 'banner', brand['image']['bannerImageUrl'], type=type) #Save the new setting
m_xml.xml_update_playlist_setting(id, 'fanart', bannerTv, type=type) #Save the new setting
settings = m_xml.xml_get_elem('playlists/playlist', 'playlist', {'id': id}, type=type) #Grab the xml settings for this playlist
id = vars.args['id'][0]
update_playlist(id, type=type)
示例9: hms_to_sec
def hms_to_sec(hms):
hms = hms.strip(' \t\n\r')
#dev.log('hms_to_sec('+hms+')')
m = re.search(r'(?i)((\d+)h)?((\d+)m)?((\d+)s)?', hms)
if m:
if m.group(2) is None and m.group(4) is None and m.group(6) == None:
#if hms.count(':') == 2:
m = re.search(r'(?i)((\d)+:)?((\d+))?(:(\d)+)?', hms)
#else:
#m = re.search(r'(?i)((\d)+:)?((\d+))?(:(\d)+)?', hms)
hours = m.group(2)
minutes = m.group(4)
seconds = m.group(6)
#dev.log(str(hours)+', '+str(minutes)+', '+str(seconds))
if seconds is None:
seconds = '0' #Seconds was not set in the setting, so we start with 0 seconds
seconds = int(seconds)
#dev.log('Seconds is '+str(seconds))
if minutes is not None: #If minutes are specified
#dev.log('minutes is '+minutes)
sm = int(minutes) * 60
seconds = seconds + sm
if hours is not None:
#dev.log('hours is '+hours)
sh = int(hours) * 60 * 60
seconds = seconds + sh
return seconds
else:
dev.log('Could not extract seconds from hms format: '+hms, True)
return None
示例10: playlist_xml_get
def playlist_xml_get(playlist, type=''):
dev.log('playlist_XML_get('+type+')')
if xbmcvfs.exists(os.path.join(vars.settingsPath,dev.typeEpnr(type)+"/"+playlist+".xml")) == False: #If the episodes.xml file can't be found, we should create this file
playlist_create_xml(playlist, type=type)
global playlistdocument #Set the document variable as global, so every function can reach it
playlistdocument = ElementTree.parse( vars.settingsPath+dev.typeEpnr(type)+'/'+playlist+'.xml' )
return playlistdocument
示例11: downloadYoutubeVid
def downloadYoutubeVid(name, fold, videoid, settings, type='', season=None):
#youtube-dl command to download best quality: -f bestvideo[ext!=webm]+bestaudio[ext!=webm]/best[ext!=webm]
#YDStreamExtractor.disableDASHVideo(True)
movieLibrary = vars.tv_folder #The path we should save in is the vars.tv_folder setting from the addon settings
if type=='musicvideo':
movieLibrary = vars.musicvideo_folder
if type=='movies':
movieLibrary = vars.movies_folder
folder = os.path.join(movieLibrary, fold) #Set the folder to the maindir/dir
enc_name = dev.legal_filename(name) #Encode the filename to a legal filename
xbmcvfs.mkdir(movieLibrary) #Create the maindirectory if it does not exist yet
xbmcvfs.mkdir(folder) #Create this subfolder if it does not exist yet
xbmcvfs.mkdir(folder) #Create this subfolder if it does not exist yet
if type == '' or type == 'tv':
folder = os.path.join(folder, 'Season '+season) #Set the folder to the maindir/dir
xbmcvfs.mkdir(folder) #Create this subfolder if it does not exist yet
full_file_path = os.path.join(folder, enc_name) #Set the file to maindir/name/name
dev.log('Downloading '+videoid, 1)
#vid = YDStreamExtractor.getVideoInfo(videoid,quality=1)
path = os.path.join(movieLibrary, fold) #Set the folder to the maindir/dir
#url = "https://www.youtube.com/watch?v=YKSU82afy1w" #ducktales intro to test
url = "https://www.youtube.com/watch?v="+videoid
vid = YDStreamExtractor.getVideoInfo(url,quality=1)
if vid == None:
dev.log('Failed to retrieve video from url: '+url)
return False
if settings.find('download_videos').text == '720p':
dev.log('%%%%%%% QUALITY: 720p quality selected')
format = 'bestvideo[height<=?720]+bestaudio/best[height<=?720]'
elif settings.find('download_videos').text == '1080p':
dev.log('%%%%%%% QUALITY: 1080p quality selected')
format = 'bestvideo[height<=?1080]+bestaudio/best[height<=?1080]'
else:
dev.log('%%%%%%% QUALITY: best quality selected')
format = 'bestvideo+bestaudio/best'
ydl_opts = {
'format': format,
'logger': MyLogger(),
'progress_hooks': [my_hook],
'outtmpl' : full_file_path+'.%(ext)s',
#'-o' : enc_name+'.%(ext)s',
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
return ydl.download(['https://www.youtube.com/watch?v='+videoid])
"""
示例12: find_year
def find_year(text):
regex = "(\(?()c(opyright)?\)?)?\s*(\d{4})"
m = re.search(regex, text, re.IGNORECASE)
if m:
if len(m.group(4)) == 4:
#Found a year!
dev.log(u'Found a year!: '+m.group(4)+ ' Whole match: '+m.group(0))
text = text.replace(m.group(0), '') #Remove the copyright / year notice from the title
return m.group(4), text
return False, text
示例13: xml_get
def xml_get(type=''):
file=dev.typeXml(type)
dev.log('XML_get('+type+','+file+')')
global document #Set the document variable as global, so every function can reach it
try:
document = ElementTree.parse( vars.settingsPath+file )
except Exception:
xbmcgui.Dialog().ok("ERROR: "+file+" got corrupted", "ERROR!: "+file+" got corrupted. Please report this error to the addon developer on youtubelibrary.nl or the kodi forums. Luckily a backup has been created automatically before.")
dev.log('ERROR: '+file+' got corrupted.', 1)
raise ValueError(output_file+' got corrupted! Best to quit here')
return False
return document
示例14: update_playlist
def update_playlist(type=''):
id = vars.args['id'][0]
xbmcgui.Dialog().notification(vars.__addonname__, 'Updating '+dev.typeName(type)+' Playlist '+id, vars.__icon__, 3000)
service.update_playlist(id, type=type)
xbmcgui.Dialog().notification(vars.__addonname__, 'Done updating '+dev.typeName(type)+' Playlist '+id, vars.__icon__, 3000)
#Should we also update the video library?
if vars.update_videolibrary == "true":
update_dir = vars.tv_folder_path
if type == 'musicvideo':
update_dir = vars.musicvideo_folder_path
dev.log('Updating video library is enabled. Updating librarys directory %s' % update_dir, True)
xbmc.executebuiltin('xbmc.updatelibrary(Video,'+update_dir+')')
示例15: playlist_add_season
def playlist_add_season(playlist, season, season_tag='season', type=''):
dev.log('playlist_add_season('+season+')')
#Check if this playlist isnt in the xml file yet
#if xml_get_elem('season', 'episode', {'id' : id}, playlist=playlist) is None:
#Build the playlist
doc = playlist_xml_get(playlist, type=type)
attr = { 'number' : season}
elem = Element(season_tag, attr)
root = doc.getroot()
root.insert(0, elem)
write_xml(root, dir=dev.typeEpnr(type), output=playlist+'.xml')
dev.log('Added '+season_tag+': '+season+' in '+dev.typeEpnr(type)+'/'+playlist+'.xml')