Best Python code snippet using pyatom_python
mediatypes.py
Source:mediatypes.py
1from lib.libs import pykodi2TVSHOW = 'tvshow'3MOVIE = 'movie'4EPISODE = 'episode'5SEASON = 'season'6MOVIESET = 'set'7MUSICVIDEO = 'musicvideo'8ARTIST = 'artist'9ALBUM = 'album'10SONG = 'song'11audiotypes = (ARTIST, ALBUM, SONG)12require_manualid = (MOVIESET, MUSICVIDEO)13PREFERRED_SOURCE_SHARED = {'0': None, '1': 'fanart.tv'}14PREFERRED_SOURCE_MEDIA = {'tvshows': ('thetvdb.com', (TVSHOW, SEASON, EPISODE)),15 'movies': ('themoviedb.org', (MOVIE, MOVIESET)),16 'music': ('theaudiodb.com', audiotypes),17 'musicvideos': ('theaudiodb.com', (MUSICVIDEO,))}18addon = pykodi.get_main_addon()19def get_artinfo(mediatype, arttype):20 mediatype, arttype = hack_mediaarttype(mediatype, arttype)21 return artinfo[mediatype].get(arttype, default_artinfo)22def hack_mediaarttype(mediatype, arttype):23 # Seasons were implemented oddly and need special help24 if arttype.startswith('season.'):25 return SEASON, arttype.rsplit('.', 1)[1]26 else:27 return mediatype, arttype28default_artinfo = {'autolimit': 0, 'multiselect': False, 'download': False}29artinfo = {30 TVSHOW: {31 'poster': {32 'autolimit': 1,33 'multiselect': False,34 'limit_setting': True,35 'download': False36 },37 'keyart': {38 'autolimit': 0,39 'multiselect': False,40 'limit_setting': True,41 'download': False42 },43 'fanart': {44 'autolimit': 5,45 'multiselect': True,46 'limit_setting': True,47 'download': False48 },49 'banner': {50 'autolimit': 1,51 'multiselect': False,52 'download': False53 },54 'clearlogo': {55 'autolimit': 1,56 'multiselect': False,57 'download': False58 },59 'landscape': {60 'autolimit': 1,61 'multiselect': False,62 'download': False63 },64 'clearart': {65 'autolimit': 1,66 'multiselect': False,67 'download': False68 },69 'characterart': {70 'autolimit': 1,71 'multiselect': False,72 'limit_setting': True,73 'download': False74 }75 },76 MOVIE: {77 'poster': {78 'autolimit': 1,79 'multiselect': False,80 'limit_setting': True,81 'download': False82 },83 'keyart': {84 'autolimit': 0,85 'multiselect': False,86 'limit_setting': True,87 'download': False88 },89 'fanart': {90 'autolimit': 5,91 'multiselect': True,92 'limit_setting': True,93 'download': False94 },95 'banner': {96 'autolimit': 1,97 'multiselect': False,98 'download': False99 },100 'clearlogo': {101 'autolimit': 1,102 'multiselect': False,103 'download': False104 },105 'landscape': {106 'autolimit': 1,107 'multiselect': False,108 'download': False109 },110 'clearart': {111 'autolimit': 1,112 'multiselect': False,113 'download': False114 },115 'discart': {116 'autolimit': 1,117 'multiselect': False,118 'download': False119 },120 'characterart': {121 'autolimit': 1,122 'multiselect': False,123 'limit_setting': True,124 'download': False125 },126 'animatedposter': {127 'autolimit': 0,128 'multiselect': False,129 'download': True130 },131 'animatedkeyart': {132 'autolimit': 0,133 'multiselect': False,134 'download': True135 },136 'animatedfanart': {137 'autolimit': 0,138 'multiselect': True,139 'limit_setting': True,140 'download': True141 }142 },143 MOVIESET: {144 'poster': {145 'autolimit': 1,146 'multiselect': False,147 'limit_setting': True,148 'download': False149 },150 'keyart': {151 'autolimit': 0,152 'multiselect': False,153 'limit_setting': True,154 'download': False155 },156 'fanart': {157 'autolimit': 5,158 'multiselect': True,159 'limit_setting': True,160 'download': False161 },162 'banner': {163 'autolimit': 1,164 'multiselect': False,165 'download': False166 },167 'clearlogo': {168 'autolimit': 1,169 'multiselect': False,170 'download': False171 },172 'landscape': {173 'autolimit': 1,174 'multiselect': False,175 'download': False176 },177 'clearart': {178 'autolimit': 1,179 'multiselect': False,180 'download': False181 },182 'discart': {183 'autolimit': 1,184 'multiselect': False,185 'download': False186 }187 },188 SEASON: {189 'poster': {190 'autolimit': 1,191 'multiselect': False,192 'download': False193 },194 'fanart': {195 'autolimit': 1,196 'multiselect': False,197 'download': False198 },199 'banner': {200 'autolimit': 1,201 'multiselect': False,202 'download': False203 },204 'landscape': {205 'autolimit': 1,206 'multiselect': False,207 'download': False208 }209 },210 EPISODE: {211 'fanart': {212 'autolimit': 1,213 'multiselect': False,214 'download': False215 }216 },217 MUSICVIDEO: {218 # album219 'poster': { # poster is what Kodi scrapers set and matches other areas of the video library,220 # but it should really be 'cover'221 'autolimit': 1,222 'multiselect': False,223 'download': False224 },225 'discart': {226 'autolimit': 1,227 'multiselect': False,228 'download': False229 },230 'fanart': { # artist or maybe album231 'autolimit': 3,232 'multiselect': True,233 'limit_setting': True,234 'download': False235 },236 # artist237 'artistthumb': {238 'autolimit': 1,239 'multiselect': False,240 'download': False241 },242 'banner': {243 'autolimit': 1,244 'multiselect': False,245 'download': False246 },247 'clearlogo': {248 'autolimit': 1,249 'multiselect': False,250 'download': False251 },252 'clearart': {253 'autolimit': 1,254 'multiselect': False,255 'download': False256 },257 'landscape': {258 'autolimit': 1,259 'multiselect': False,260 'download': False261 }262 },263 ARTIST: {264 'thumb': {265 'autolimit': 1,266 'multiselect': False,267 'download': False268 },269 'fanart': {270 'autolimit': 3,271 'multiselect': True,272 'limit_setting': True,273 'download': False274 },275 'banner': {276 'autolimit': 1,277 'multiselect': False,278 'download': False279 },280 'clearlogo': {281 'autolimit': 1,282 'multiselect': False,283 'download': False284 },285 'clearart': {286 'autolimit': 1,287 'multiselect': False,288 'download': False289 },290 'landscape': {291 'autolimit': 1,292 'multiselect': False,293 'download': False294 }295 },296 ALBUM: {297 'thumb': { # I'd much prefer 'cover', but for now it's thumb just like music video 'poster'298 'autolimit': 1,299 'multiselect': False,300 'download': False301 },302 # I can imagine 'fanart' images that can be accurately attributed to an album rather than the artist,303 # perhaps made from liner notes or press images, but nothing currently available from web services304 'discart': {305 'autolimit': 1,306 'multiselect': False,307 'download': False308 },309 'back': {310 'autolimit': 1,311 'multiselect': False,312 'download': False313 },314 'spine': {315 'autolimit': 1,316 'multiselect': False,317 'download': False318 }319 },320 SONG: {321 'thumb': { # single cover322 'autolimit': 1,323 'multiselect': False,324 'download': False325 }326 }327}328central_directories = {MOVIESET: False}329togenerate = dict((mediatype, False) for mediatype in artinfo)330preferred = dict((mediatype, None) for mediatype in artinfo)331onlyfs = dict((mediatype, False) for mediatype in artinfo)332othertypes = dict((mediatype, []) for mediatype in artinfo)333download_arttypes = dict((mediatype, []) for mediatype in artinfo)334arttype_settingskeys = [m[0] + '.' + art[0] + ('_limit' if art[1].get('limit_setting') else '')335 for m in artinfo.items() for art in m[1].items()]336def disabled(mediatype):337 return not any(iter_every_arttype(mediatype)) and not generatethumb(mediatype) and \338 not downloadanyartwork(mediatype)339def iter_every_arttype(mediatype):340 for arttype, info in artinfo[mediatype].items():341 if not info['autolimit']:342 continue343 yield arttype344 if info['autolimit'] > 1:345 for num in range(1, info['autolimit']):346 yield arttype + str(num)347 for arttype in othertypes[mediatype]:348 yield arttype349def downloadartwork(mediatype, arttype):350 mediatype, arttype = hack_mediaarttype(mediatype, arttype)351 arttype, _ = _split_arttype(arttype)352 if arttype in download_arttypes.get(mediatype, ()):353 return True354 info = get_artinfo(mediatype, arttype)355 return info['download']356def downloadanyartwork(mediatype):357 if download_arttypes.get(mediatype):358 return True359 info = artinfo.get(mediatype)360 if not info:361 return False362 return any(x for x in info.values() if x['download'])363def _split_arttype(arttype):364 basetype = arttype.rstrip('0123456789')365 idx = 0 if basetype == arttype else int(arttype.replace(basetype, ''))366 return basetype, idx367def generatethumb(mediatype):368 return togenerate.get(mediatype, False)369def haspreferred_source(mediatype):370 return bool(preferred.get(mediatype))371def ispreferred_source(mediatype, provider):372 return provider == preferred.get(mediatype, '')373def only_filesystem(mediatype):374 return onlyfs.get(mediatype, False)375def update_settings():376 always_multiple_selection = addon.get_setting('always_multiple_selection')377 if not always_multiple_selection:378 _set_allmulti(False)379 for settingid in arttype_settingskeys:380 splitsetting = settingid.split('.')381 thistype = artinfo[splitsetting[0]][splitsetting[1].split('_')[0]]382 try:383 thistype['autolimit'], thistype['multiselect'] = _get_autolimit_from_setting(settingid)384 except ValueError:385 addon.set_setting(settingid, thistype['autolimit'])386 addon.set_setting(settingid, thistype['multiselect'])387 if always_multiple_selection:388 _set_allmulti(True)389 for mediatype in artinfo:390 olddownload = addon.get_setting(mediatype + '.downloadartwork')391 if olddownload != '':392 # DEPRECATED: 2018-05-19393 if olddownload:394 addon.set_setting(mediatype + '.download_arttypes', ', '.join(artinfo[mediatype]))395 if mediatype == TVSHOW:396 addon.set_setting('season.download_arttypes', ', '.join(artinfo['season']))397 addon.set_setting(mediatype + '.downloadartwork', '')398 othertypes[mediatype] = [t.strip() for399 t in addon.get_setting(mediatype + '.othertypes').split(',')]400 if len(othertypes[mediatype]) == 1 and not othertypes[mediatype][0]:401 othertypes[mediatype] = []402 download_arttypes[mediatype] = [t.strip() for403 t in addon.get_setting(mediatype + '.download_arttypes').split(',')]404 if len(download_arttypes[mediatype]) == 1 and not download_arttypes[mediatype][0]:405 download_arttypes[mediatype] = []406 for atype in artinfo[mediatype]:407 dl = atype in download_arttypes[mediatype]408 artinfo[mediatype][atype]['download'] = dl409 if dl:410 del download_arttypes[mediatype][download_arttypes[mediatype].index(atype)]411 for mediatype in (MOVIESET,):412 central_directories[mediatype] = addon.get_setting('centraldir.{0}_enabled'.format(mediatype))413 if central_directories[mediatype]:414 central_directories[mediatype] = addon.get_setting('centraldir.{0}_dir'.format(mediatype))415 for mediatype in (EPISODE, MOVIE, MUSICVIDEO):416 togenerate[mediatype] = addon.get_setting('{0}.thumb_generate'.format(mediatype))417 old_prefer_tmdb = addon.get_setting('prefer_tmdbartwork')418 if old_prefer_tmdb != '':419 # DEPRECATED: 2018-05-25420 if old_prefer_tmdb:421 addon.set_setting('preferredsource_movies', '2')422 addon.set_setting('prefer_tmdbartwork', '')423 old_only_filesystem = addon.get_setting('only_filesystem')424 if old_only_filesystem != '':425 # DEPRECATED: 2018-05-26426 if old_only_filesystem:427 for media in PREFERRED_SOURCE_MEDIA:428 addon.set_setting('onlyfilesystem_' + media, True)429 addon.set_setting('only_filesystem', '')430 for media, config in PREFERRED_SOURCE_MEDIA.items():431 result = addon.get_setting('preferredsource_' + media)432 downloadconfig = addon.get_setting('download_config_' + media)433 if downloadconfig not in ('0', '1', '2'):434 # DEPRECATED: default to '2' for now for upgraders, can go back to '0' later435 downloadconfig = '2'436 addon.set_setting('download_config_' + mediatype, downloadconfig)437 for mediatype in config[1]:438 if result in ('0', '1', '2'):439 preferred[mediatype] = PREFERRED_SOURCE_SHARED[result] if \440 result in PREFERRED_SOURCE_SHARED else PREFERRED_SOURCE_MEDIA.get(media, (None,))[0]441 else:442 preferred[mediatype] = None443 addon.set_setting('preferredsource_' + media, '0')444 onlyfs[mediatype] = addon.get_setting('onlyfs_' + media)445 if downloadconfig == '0': # None446 download_arttypes[mediatype] = []447 for atype in artinfo[mediatype].values():448 atype['download'] = False449 elif downloadconfig == '1': # all configured from web and local450 download_arttypes[mediatype] = list(othertypes[mediatype])451 for atype in artinfo[mediatype].values():452 atype['download'] = atype['autolimit'] > 0453 # Kodi doesn't cache gifs, so always download animated artwork454 for arttype, artconfig in artinfo[mediatype].items():455 if arttype.startswith('animated'):456 artconfig['download'] = True457def _get_autolimit_from_setting(settingid):458 result = addon.get_setting(settingid)459 if settingid.endswith('_limit'):460 result = int(result)461 return result, result > 1462 return (1 if result else 0), False463def _set_allmulti(always_multi):464 for typeinfo in artinfo.values():465 for arttypeinfo in typeinfo.values():466 arttypeinfo['multiselect'] = always_multi...
st_multiselect.py
Source:st_multiselect.py
...22 CHOCOLATE = "CHOCOLATE"23 COOKIES = "COOKIES"24 MINT = "MINT"25options = ("male", "female")26i1 = st.multiselect("multiselect 1", options)27st.text("value 1: %s" % i1)28i2 = st.multiselect("multiselect 2", options, format_func=lambda x: x.capitalize())29st.text("value 2: %s" % i2)30i3: List[Any] = st.multiselect("multiselect 3", [])31st.text("value 3: %s" % i3)32i4 = st.multiselect("multiselect 4", ["coffee", "tea", "water"], ["tea", "water"])33st.text("value 4: %s" % i4)34i5 = st.multiselect(35 "multiselect 5",36 list(37 map(38 lambda x: f"{x} I am a ridiculously long string to have in a multiselect, so perhaps I should just not wrap and go to the next line.",39 range(5),40 )41 ),42)43st.text("value 5: %s" % i5)44i6 = st.multiselect("multiselect 6", options, disabled=True)45st.text("value 6: %s" % i6)46i7 = st.multiselect("choose colors", list(Colors), Colors.yellow)47st.text("value 7: %s" % i7)48i8 = st.multiselect("choose shakes", list(Shake), Shake.CHOCOLATE)49st.text("value 8: %s" % i8)50if st._is_running_with_streamlit:51 def on_change():52 st.session_state.multiselect_changed = True53 st.multiselect("multiselect 9", options, key="multiselect9", on_change=on_change)54 st.text("value 9: %s" % st.session_state.multiselect9)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!