def begin(movieid=None, episodeid=None, dbtype=None, selection=False, args=None): e = experience.ExperiencePlayer().create() seqPath = None if not e.hasFeatures() or selection or movieid or episodeid or dbtype: if dbtype: if not e.addDBFeature(dbtype, args[0][5:]): return showNoFeaturesDialog() elif not e.addSelectedFeature(selection=selection, movieid=movieid, episodeid=episodeid): return showNoFeaturesDialog() elif len(e.features) < 2 and kodiutil.getSetting('ignore.playlist.single', True) and e.selectionAvailable(): if not e.addSelectedFeature(selection=True): return showNoFeaturesDialog() # We shouldn't get here if not kodiutil.getSetting('hide.queue.dialog', False) or (kodiutil.getSetting('hide.queue.dialog.single', False) and len(e.features) > 1): if not args or 'nodialog' not in args: e.features, seqPath = featureComfirmationDialog(e.features) if not e.features: return if seqPath: kodiutil.DEBUG_LOG('Loading selected sequence: {0}'.format(repr(seqPath))) else: seqPath = cvutil.getSequencePath(for_3D=e.has3D) kodiutil.DEBUG_LOG('Loading sequence for {0}: {1}'.format(e.has3D and '3D' or '2D', repr(seqPath))) if xbmc.getCondVisibility('Window.IsVisible(MovieInformation)'): xbmc.executebuiltin('Dialog.Close(MovieInformation)') e.start(seqPath)
def checkForContentDB(self): if kodiutil.getSetting('content.path'): kodiutil.setGlobalProperty('DEMO_MODE', '') return kodiutil.getSetting('content.initialized', False) else: kodiutil.setGlobalProperty('DEMO_MODE', '1') return True
def begin(movieid=None, episodeid=None, selection=False, args=None): e = experience.ExperiencePlayer().create() seqPath = None if not e.hasFeatures() or selection or movieid or episodeid: if not e.addSelectedFeature(selection=selection, movieid=movieid, episodeid=episodeid): return showNoFeaturesDialog() elif len(e.features) < 2 and kodiutil.getSetting('ignore.playlist.single', True) and e.selectionAvailable(): if not e.addSelectedFeature(selection=True): return showNoFeaturesDialog() # We shouldn't get here if not kodiutil.getSetting('hide.queue.dialog', False) or (kodiutil.getSetting('hide.queue.dialog.single', False) and len(e.features) > 1): if not args or 'nodialog' not in args: e.features, seqPath = featureComfirmationDialog(e.features) if not e.features: return if seqPath: kodiutil.DEBUG_LOG('Loading selected sequence: {0}'.format(repr(seqPath))) else: seqPath = cvutil.getSequencePath(for_3D=e.has3D) kodiutil.DEBUG_LOG('Loading sequence for {0}: {1}'.format(e.has3D and '3D' or '2D', repr(seqPath))) e.start(seqPath)
def begin(movieid=None, episodeid=None, dbtype=None, selection=False, args=None): e = experience.ExperiencePlayer().create() seqPath = None feature = None if 'intercept' in args and len(args) >= 3: if args[1] == 'movie': feature = e.featureFromId(movieid=args[2]) elif args[1] == 'episode': feature = e.featureFromId(episodeid=args[2]) if feature is not None: if len(e.features) > 0: e.features[0] = feature else: e.features.append(feature) if not e.hasFeatures() or selection or movieid or episodeid or dbtype: if dbtype: if not e.addDBFeature(dbtype, args[0][5:]): return showNoFeaturesDialog() elif not e.addSelectedFeature( selection=selection, movieid=movieid, episodeid=episodeid): return showNoFeaturesDialog() elif len(e.features) < 2 and kodiutil.getSetting( 'ignore.playlist.single', True) and e.selectionAvailable(): if not e.addSelectedFeature(selection=True): return showNoFeaturesDialog() # We shouldn't get here if not kodiutil.getSetting('hide.queue.dialog', False) or ( kodiutil.getSetting('hide.queue.dialog.single', False) and len(e.features) > 1): if not args or 'nodialog' not in args: e.features, seqPath = featureComfirmationDialog(e.features, args) if not e.features: return if seqPath: kodiutil.DEBUG_LOG('Loading selected sequence: {0}'.format( repr(seqPath))) else: if feature is None: feature = e.features[0] seqData = cvutil.getMatchedSequence(feature) seqPath = seqData['path'] kodiutil.DEBUG_LOG('Loading sequence for {0}: {1}'.format( feature.is3D and '3D' or '2D', repr(seqPath))) if xbmc.getCondVisibility('Window.IsVisible(MovieInformation)'): xbmc.executebuiltin('Dialog.Close(MovieInformation)') e.start(seqPath)
def _save(self, full_path, temp=False): items = [li.dataSource for li in self.sequenceControl if li.dataSource] if not cinemavision.sequence.sequenceHasFeature(items): yes = xbmcgui.Dialog().yesno( T(32603, 'No Feature'), T( 32604, 'Sequence does not have a feature module, which is required to play items selected in Kodi.' ), T(32605, 'Continue?')) if not yes: return xmlString = cinemavision.sequence.getSaveString(items) kodiutil.DEBUG_LOG('Saving to: {0}'.format(full_path)) success = True if cinemavision.util.vfs.exists(full_path): cinemavision.util.vfs.delete(full_path) with cinemavision.util.vfs.File(full_path, 'w') as f: success = f.write(xmlString) if not success: xbmcgui.Dialog().ok( T(32573, 'Failed'), T(32606, 'Failed to write sequence file!'), T(32607, 'Kodi may be unable to write to this location.')) return if not temp: self.modified = False self.saveDefault() sequence2D = kodiutil.getSetting('sequence.2D') sequence3D = kodiutil.getSetting('sequence.3D') if not sequence2D or (self.name != sequence2D and self.name != sequence3D): yes = xbmcgui.Dialog().yesno( T(32555, 'Set Default'), T( 32556, 'Would you like to set this as the default for playback?' )) if yes: as3D = xbmcgui.Dialog().yesno('2D/3D', T(32557, 'For 2D or 3D?'), nolabel='2D', yeslabel='3D') if as3D: kodiutil.setSetting('sequence.3D', self.name) else: kodiutil.setSetting('sequence.2D', self.name)
def getSequencePath(for_3D=False, with_name=False): if for_3D: name = kodiutil.getSetting('sequence.3D') else: name = kodiutil.getSetting('sequence.2D') if name: path = getSavePath(name) else: path = defaultSavePath() if with_name: return (path, getSequenceName(path)) return path
def selectSequence(): import xbmcgui default2D = 2 default3D = 3 contentPath = kodiutil.getSetting('content.path') if not contentPath: xbmcgui.Dialog().ok(T(32500, 'Not Found'), ' ', T(32501, 'No sequences found.')) return None sequencesPath = cinemavision.util.pathJoin(contentPath, 'Sequences') options = cinemavision.util.vfs.listdir(sequencesPath) options = [(n, n[:-6]) for n in options if n.endswith('.cvseq')] options.append((default2D, u'[ {0} ]'.format(T(32599, 'Default 2D')))) options.append((default3D, u'[ {0} ]'.format(T(32600, 'Default 3D')))) if not options: xbmcgui.Dialog().ok(T(32500, 'Not Found'), ' ', T(32501, 'No sequences found.')) return None idx = xbmcgui.Dialog().select(T(32502, 'Choose Sequence'), [o[1] for o in options]) if idx < 0: return None result = options[idx][0] if result == default2D: path = defaultSavePath() elif result == default3D: path = defaultSavePath(for_3D=True) else: path = cinemavision.util.pathJoin(sequencesPath, options[idx][0]) return {'path': path, 'name': options[idx][1]}
def createSettingsRSDirs(): base = os.path.join(kodiutil.PROFILE_PATH, 'settings', 'ratings') if not os.path.exists(base): os.makedirs(base) defaultPath = os.path.join(kodiutil.PROFILE_PATH, 'settings', 'ratings_default') if os.path.exists(defaultPath): import shutil shutil.rmtree(defaultPath) defaultSystem = kodiutil.getSetting('rating.system.default', 'MPAA') for system in cinemavision.ratings.RATINGS_SYSTEMS.values(): systemPaths = [os.path.join(base, system.name)] if system.name == defaultSystem: systemPaths.append(defaultPath) for path in systemPaths: if not os.path.exists(path): os.makedirs(path) for rating in system.ratings: with open(os.path.join(path, str(rating).replace(':', '.', 1)), 'w'): pass kodiutil.setSetting('settings.ratings.initialized', 'true') kodiutil.setSetting('settings.ratings.initialized2', 'true')
def setTheme(theme_path=None): global THEME default = os.path.join(kodiutil.ADDON_PATH, 'resources', 'themes', 'default') + '/' if theme_path is not None: kodiutil.setSetting('theme.path', theme_path) else: theme_path = kodiutil.getSetting('theme.path', default) cfg = cinemavision.util.pathJoin(theme_path, 'theme.json') try: with cinemavision.util.vfs.File(cfg, 'r') as f: THEME = json.loads(f.read().decode('utf-8')) THEME['theme.path'] = theme_path except: kodiutil.ERROR('Could not read {0}'.format(cfg)) THEME = { 'theme.name': '[I]Default[/I]', 'theme.color.icon': 'FF9C2A2D', 'theme.color.setting': 'FF9C2A2D', 'theme.color.move': 'FF9C2A2D', 'theme.color.button.selected': 'FF9C2A2D', 'theme.path': default } kodiutil.setGlobalProperty('theme.color.icon', THEME['theme.color.icon']) kodiutil.setGlobalProperty('theme.color.setting', THEME['theme.color.setting']) kodiutil.setGlobalProperty('theme.color.move', THEME['theme.color.move']) kodiutil.setGlobalProperty('theme.color.button.selected', THEME['theme.color.button.selected']) kodiutil.setGlobalProperty('theme.path', THEME['theme.path'])
def loadDefault(self): self.setName(kodiutil.getSetting('save.name', '')) if not self.name: savePath = self.defaultSavePath() else: savePath = self.savePath() if not xbmcvfs.exists(savePath): self.setName('') self.saveDefault(force=True) new = xbmcgui.Dialog().yesno( T(32558, 'Missing'), T(32559, 'Previous save not found.'), '', T(32560, 'Load the default or start a new sequence?'), T(32322, 'Default'), T(32541, 'New')) if new: self.setName('') self.setFocusId(self.ADD_ITEM_LIST_ID) return else: savePath = self.defaultSavePath() kodiutil.DEBUG_LOG('Loading previous save: {0}'.format(savePath)) self._load(savePath) kodiutil.DEBUG_LOG('Previous save loaded')
def getSavePath(name): contentPath = kodiutil.getSetting('content.path') if not name or not contentPath: return return cinemavision.util.pathJoin(contentPath, 'Sequences', name + '.cvseq')
def loadDefault(self): self.setName(kodiutil.getSetting('save.name', '')) if not self.name: savePath = self.defaultSavePath() else: savePath = self.savePath() if not xbmcvfs.exists(savePath): self.setName('') self.saveDefault(force=True) new = xbmcgui.Dialog().yesno( T(32558, 'Missing'), T(32559, 'Previous save not found.'), '', T(32560, 'Load the default or start a new sequence?'), T(32322, 'Default'), T(32541, 'New') ) if new: self.setName('') self.setFocusId(self.ADD_ITEM_LIST_ID) return else: savePath = self.defaultSavePath() kodiutil.DEBUG_LOG('Loading previous save: {0}'.format(savePath)) self._load(savePath) kodiutil.DEBUG_LOG('Previous save loaded')
def save(self, as_new=False, export=False): if export: path = xbmcgui.Dialog().browse(3, T(32552, 'Select Save Directory'), 'files', None, False, False) if not path: return else: contentPath = kodiutil.getSetting('content.path') if not contentPath: xbmcgui.Dialog().ok(T(32503, 'No Content Path'), ' ', T(32553, 'Please set the content path in addon settings.')) return path = cinemavision.util.pathJoin(contentPath, 'Sequences') name = self.name if not name or as_new or export: name = xbmcgui.Dialog().input(T(32554, 'Enter name for file'), name) if not name: return if not export: self.setName(name) fullPath = self.savePath(path, name) self._save(fullPath, temp=export)
def save(self, as_new=False, export=False): if export: path = xbmcgui.Dialog().browse(3, T(32552, 'Select Save Directory'), 'files', None, False, False) if not path: return else: contentPath = kodiutil.getSetting('content.path') if not contentPath: xbmcgui.Dialog().ok( T(32503, 'No Content Path'), ' ', T(32553, 'Please set the content path in addon settings.')) return path = cinemavision.util.pathJoin(contentPath, 'Sequences') name = self.name if not name or as_new or export: name = xbmcgui.Dialog().input(T(32554, 'Enter name for file'), name) if not name: return if not export: self.setName(name) fullPath = self.savePath(path, name) self._save(fullPath, temp=export)
def setScrapers(): import cvutil import cinemavision selected = [ s.strip().lower() for s in kodiutil.getSetting('trailer.scrapers', '').split(',') ] contentScrapers = cinemavision.util.contentScrapers() temp = [list(x) for x in cinemavision.sequence.Trailer._scrapers] options = [] for s in temp: for ctype, c in contentScrapers: if ctype == 'trailers' and c == s[0]: s[2] = s[2] in selected options.append(s) options.sort(key=lambda i: i[0].lower() in selected and selected.index(i[ 0].lower()) + 1 or 99) result = cvutil.multiSelect(options, default=True) if result is False or result is None: return kodiutil.setSetting('trailer.scrapers', result)
def addSelectedFeature(self, movieid=None, episodeid=None, selection=False): if selection or movieid or episodeid: return self.addFromID(movieid, episodeid, selection) if xbmc.getCondVisibility('ListItem.IsCollection'): kodiutil.DEBUG_LOG('Selection is a collection') return self.addCollectionMovies() title = kodiutil.infoLabel('ListItem.Title') if not title: return False feature = cinemavision.sequenceprocessor.Feature( kodiutil.infoLabel('ListItem.FileNameAndPath')) feature.title = title ratingString = cvutil.ratingParser().getActualRatingFromMPAA( kodiutil.infoLabel('ListItem.Mpaa'), debug=True) if ratingString: feature.rating = ratingString feature.ID = kodiutil.intOrZero(xbmc.getInfoLabel('ListItem.DBID')) feature.dbType = xbmc.getInfoLabel('ListItem.DBTYPE') feature.genres = kodiutil.infoLabel('ListItem.Genre').split(' / ') feature.thumb = kodiutil.infoLabel('ListItem.Thumb') feature.year = kodiutil.infoLabel('ListItem.Year') try: feature.runtime = kodiutil.intOrZero( xbmc.getInfoLabel('ListItem.Duration')) * 60 except TypeError: pass feature.is3D = xbmc.getCondVisibility('ListItem.IsStereoscopic') if not feature.is3D: tags3DRegEx = kodiutil.getSetting('3D.tag.regex', cvutil.DEFAULT_3D_RE) feature.is3D = bool(re.search(tags3DRegEx, feature.path)) codec = xbmc.getInfoLabel('ListItem.AudioCodec') channels = kodiutil.intOrZero( xbmc.getInfoLabel('ListItem.AudioChannels')) if codec: feature.audioFormat = AUDIO_FORMATS.get(codec) feature.codec = codec feature.channels = channels DEBUG_LOG('CODEC ({0}): {1} ({2} channels)'.format( kodiutil.strRepr(feature.title), codec, channels or '?')) else: DEBUG_LOG('CODEC ({0}): NOT DETECTED'.format( kodiutil.strRepr(feature.title))) self.features.append(feature) return True
def _save(self, full_path, temp=False): items = [li.dataSource for li in self.sequenceControl if li.dataSource] if not cinemavision.sequence.sequenceHasFeature(items): yes = xbmcgui.Dialog().yesno( T(32603, 'No Feature'), T(32604, 'Sequence does not have a feature module, which is required to play items selected in Kodi.'), T(32605, 'Continue?') ) if not yes: return xmlString = cinemavision.sequence.getSaveString(items) kodiutil.DEBUG_LOG('Saving to: {0}'.format(full_path)) success = True if cinemavision.util.vfs.exists(full_path): cinemavision.util.vfs.delete(full_path) with cinemavision.util.vfs.File(full_path, 'w') as f: success = f.write(xmlString) if not success: xbmcgui.Dialog().ok( T(32573, 'Failed'), T(32606, 'Failed to write sequence file!'), T(32607, 'Kodi may be unable to write to this location.') ) return if not temp: self.modified = False self.saveDefault() sequence2D = kodiutil.getSetting('sequence.2D') sequence3D = kodiutil.getSetting('sequence.3D') if not sequence2D or (self.name != sequence2D and self.name != sequence3D): yes = xbmcgui.Dialog().yesno(T(32555, 'Set Default'), T(32556, 'Would you like to set this as the default for playback?')) if yes: as3D = xbmcgui.Dialog().yesno('2D/3D', T(32557, 'For 2D or 3D?'), nolabel='2D', yeslabel='3D') if as3D: kodiutil.setSetting('sequence.3D', self.name) else: kodiutil.setSetting('sequence.2D', self.name)
def showVideo(self, video): if kodiutil.getSetting('allow.video.skip', True): if video.type == 'FEATURE': self.playVideos(None, features=[video]) self.setSkinFeatureVars() else: self.playVideos([video]) else: self.play(*self.getPathAndListItemFromVideo(video))
def getSequencesContentPath(): import xbmcgui contentPath = kodiutil.getSetting('content.path') if not contentPath: xbmcgui.Dialog().ok(T(32500, 'Not Found'), ' ', T(32501, 'No sequences found.')) return None return contentPath
def loadContent(from_settings=False, bg=False): import xbmcgui if from_settings and not kodiutil.getSetting('content.path'): xbmcgui.Dialog().ok(T(32503, 'No Content Path'), ' ', T(32504, 'Content path not set or not applied')) return contentPath = getContentPath(from_load=True) kodiutil.DEBUG_LOG('Loading content...') with kodiutil.Progress(T(32505, 'Loading Content'), bg=bg) as p: cinemavision.content.UserContent(contentPath, callback=p.msg, trailer_sources=kodiutil.getSetting( 'trailer.scrapers', '').split(',')) createSettingsRSDirs()
def savePath(self, path=None, name=None): name = name or self.name if not path: contentPath = kodiutil.getSetting('content.path') if not contentPath: return path = cinemavision.util.pathJoin(contentPath, 'Sequences') if not name or not path: return None if name.endswith('.cvseq'): name = name[:-6] return cinemavision.util.pathJoin(path, name) + '.cvseq'
def setRatingDefaults(self): ratingSystem = kodiutil.getSetting('rating.system.default', 'MPAA') if not ratingSystem: try: countryCode = self.LANGUAGE.split('-')[1].strip() if countryCode: cinemavision.ratings.setCountry(countryCode) except IndexError: pass except: kodiutil.ERROR() else: cinemavision.ratings.setDefaultRatingSystem(ratingSystem)
def featureFromJSON(self, r): tags3DRegEx = kodiutil.getSetting('3D.tag.regex', cvutil.DEFAULT_3D_RE) feature = cinemavision.sequenceprocessor.Feature(r['file']) feature.title = r.get('title') or r.get('label', '') ratingString = cvutil.ratingParser().getActualRatingFromMPAA( r.get('mpaa', ''), debug=True) if ratingString: feature.rating = ratingString feature.ID = kodiutil.intOrZero( r.get('movieid', r.get('episodeid', r.get('id', 0)))) feature.dbType = r.get('type', '') feature.genres = r.get('genre', []) feature.tags = r.get('tag', []) feature.studios = r.get('studio', []) feature.directors = r.get('director', []) feature.cast = r.get('cast', []) feature.thumb = r.get('thumbnail', '') feature.runtime = r.get('runtime', 0) feature.year = r.get('year', 0) try: stereomode = r['streamdetails']['video'][0]['stereomode'] except: stereomode = '' if stereomode not in ('mono', ''): feature.is3D = True else: feature.is3D = bool(re.search(tags3DRegEx, r['file'])) try: codec, channels = self.getCodecAndChannelsFromStreamDetails( r['streamdetails']) DEBUG_LOG('CODEC ({0}): {1} ({2} channels)'.format( kodiutil.strRepr(feature.title), codec, channels or '?')) DEBUG_LOG('STREAMDETAILS: \n{0}'.format( self.formatStreamDetails(r.get('streamdetails')))) feature.audioFormat = AUDIO_FORMATS.get(codec) feature.codec = codec feature.channels = channels except: kodiutil.ERROR() DEBUG_LOG('CODEC ({0}): NOT DETECTED'.format( kodiutil.strRepr(feature.title))) DEBUG_LOG('STREAMDETAILS: {0}'.format(repr( r.get('streamdetails')))) return feature
def addSelectedFeature(self, movieid=None, episodeid=None, selection=False): if selection or movieid or episodeid: return self.addFromID(movieid, episodeid, selection) if xbmc.getCondVisibility('ListItem.IsCollection'): kodiutil.DEBUG_LOG('Selection is a collection') return self.addCollectionMovies() title = kodiutil.infoLabel('ListItem.Title') if not title: return False feature = cinemavision.sequenceprocessor.Feature(kodiutil.infoLabel('ListItem.FileNameAndPath')) feature.title = title ratingString = cvutil.ratingParser().getActualRatingFromMPAA(kodiutil.infoLabel('ListItem.Mpaa'), debug=True) if ratingString: feature.rating = ratingString feature.ID = kodiutil.intOrZero(xbmc.getInfoLabel('ListItem.DBID')) feature.dbType = xbmc.getInfoLabel('ListItem.DBTYPE') feature.genres = kodiutil.infoLabel('ListItem.Genre').split(' / ') feature.thumb = kodiutil.infoLabel('ListItem.Thumb') feature.year = kodiutil.infoLabel('ListItem.Year') try: feature.runtime = kodiutil.intOrZero(xbmc.getInfoLabel('ListItem.Duration')) * 60 except TypeError: pass feature.is3D = xbmc.getCondVisibility('ListItem.IsStereoscopic') if not feature.is3D: tags3DRegEx = kodiutil.getSetting('3D.tag.regex', cvutil.DEFAULT_3D_RE) feature.is3D = bool(re.search(tags3DRegEx, feature.path)) codec = xbmc.getInfoLabel('ListItem.AudioCodec') channels = kodiutil.intOrZero(xbmc.getInfoLabel('ListItem.AudioChannels')) if codec: feature.audioFormat = AUDIO_FORMATS.get(codec) feature.codec = codec feature.channels = channels DEBUG_LOG('CODEC ({0}): {1} ({2} channels)'.format(kodiutil.strRepr(feature.title), codec, channels or '?')) else: DEBUG_LOG('CODEC ({0}): NOT DETECTED'.format(kodiutil.strRepr(feature.title))) self.features.append(feature) return True
def loadContent(from_settings=False): import xbmcgui if from_settings and not kodiutil.getSetting('content.path'): xbmcgui.Dialog().ok(T(32503, 'No Content Path'), ' ', T(32504, 'Content path not set or not applied')) return contentPath = getContentPath(from_load=True) kodiutil.DEBUG_LOG('Loading content...') with kodiutil.Progress(T(32505, 'Loading Content')) as p: cinemavision.content.UserContent(contentPath, callback=p.msg, trailer_sources=kodiutil.getSetting('trailer.scrapers', '').split(',')) createSettingsRSDirs()
def loadActions(self): self.pauseAction = None self.resumeAction = None self.abortAction = None if kodiutil.getSetting('action.onPause', False): actionFile = kodiutil.getSetting('action.onPause.file') self.pauseAction = actionFile and cinemavision.actions.ActionFileProcessor(actionFile) or None if kodiutil.getSetting('action.onResume', 0) == 2: actionFile = kodiutil.getSetting('action.onResume.file') self.resumeAction = actionFile and cinemavision.actions.ActionFileProcessor(actionFile) or None elif kodiutil.getSetting('action.onResume', 0) == 1: self.resumeAction = True if kodiutil.getSetting('action.onAbort', False): actionFile = kodiutil.getSetting('action.onAbort.file') self.abortAction = actionFile and cinemavision.actions.ActionFileProcessor(actionFile) or None
def getContentPath(from_load=False): contentPath = kodiutil.getSetting('content.path') demoPath = os.path.join(kodiutil.PROFILE_PATH, 'demo') if contentPath: kodiutil.setSetting('content.initialized', True) if os.path.exists(demoPath): try: import shutil shutil.rmtree(demoPath) except: kodiutil.ERROR() return contentPath else: if not os.path.exists(demoPath): copyDemoContent() downloadDemoContent() if not from_load: loadContent() return demoPath
def getContentPath(from_load=False): contentPath = kodiutil.getSetting('content.path') demoPath = os.path.join(kodiutil.PROFILE_PATH, 'demo') if contentPath: kodiutil.setSetting('content.initialized', True) if os.path.exists(demoPath): try: import shutil shutil.rmtree(demoPath) except Exception: kodiutil.ERROR() return contentPath else: if not os.path.exists(demoPath): copyDemoContent() downloadDemoContent() if not from_load: loadContent() return demoPath
def setScrapers(): import cvutil import cinemavision selected = [s.strip().lower() for s in kodiutil.getSetting('trailer.scrapers', '').split(',')] contentScrapers = cinemavision.util.contentScrapers() temp = [list(x) for x in cinemavision.sequence.Trailer._scrapers] options = [] for s in temp: for ctype, c in contentScrapers: if ctype == 'trailers' and c == s[0]: s[2] = s[2] in selected options.append(s) options.sort(key=lambda i: i[0].lower() in selected and selected.index(i[0].lower())+1 or 99) result = cvutil.multiSelect(options, default=True) if result is False or result is None: return kodiutil.setSetting('trailer.scrapers', result)
def featureFromJSON(self, r): tags3DRegEx = kodiutil.getSetting('3D.tag.regex', cvutil.DEFAULT_3D_RE) feature = cinemavision.sequenceprocessor.Feature(r['file']) feature.title = r.get('title') or r.get('label', '') ratingString = cvutil.ratingParser().getActualRatingFromMPAA(r.get('mpaa', ''), debug=True) if ratingString: feature.rating = ratingString feature.ID = kodiutil.intOrZero(r.get('movieid', r.get('episodeid', r.get('id', 0)))) feature.dbType = r.get('type', '') feature.genres = r.get('genre', []) feature.thumb = r.get('thumbnail', '') feature.runtime = r.get('runtime', 0) feature.year = r.get('year', 0) try: stereomode = r['streamdetails']['video'][0]['stereomode'] except: stereomode = '' if stereomode not in ('mono', ''): feature.is3D = True else: feature.is3D = bool(re.search(tags3DRegEx, r['file'])) try: codec, channels = self.getCodecAndChannelsFromStreamDetails(r['streamdetails']) DEBUG_LOG('CODEC ({0}): {1} ({2} channels)'.format(kodiutil.strRepr(feature.title), codec, channels or '?')) DEBUG_LOG('STREAMDETAILS: {0}'.format(repr(r.get('streamdetails')))) feature.audioFormat = AUDIO_FORMATS.get(codec) feature.codec = codec feature.channels = channels except: DEBUG_LOG('CODEC ({0}): NOT DETECTED'.format(kodiutil.strRepr(feature.title))) DEBUG_LOG('STREAMDETAILS: {0}'.format(repr(r.get('streamdetails')))) return feature
def loadActions(self): self.pauseAction = None self.resumeAction = None self.abortAction = None if kodiutil.getSetting('action.onPause', False): actionFile = kodiutil.getSetting('action.onPause.file') self.pauseAction = actionFile and cinemavision.actions.ActionFileProcessor( actionFile) or None if kodiutil.getSetting('action.onResume', 0) == 2: actionFile = kodiutil.getSetting('action.onResume.file') self.resumeAction = actionFile and cinemavision.actions.ActionFileProcessor( actionFile) or None elif kodiutil.getSetting('action.onResume', 0) == 1: self.resumeAction = True if kodiutil.getSetting('action.onAbort', False): actionFile = kodiutil.getSetting('action.onAbort.file') self.abortAction = actionFile and cinemavision.actions.ActionFileProcessor( actionFile) or None
def testEventActions(action): import cvutil path = None if action == 'PAUSE': if kodiutil.getSetting('action.onPause', False): path = kodiutil.getSetting('action.onPause.file', '') elif action == 'RESUME': if kodiutil.getSetting('action.onResume', 0) == 2: path = kodiutil.getSetting('action.onResume.file', '') elif action == 'ABORT': if kodiutil.getSetting('action.onAbort', False): path = kodiutil.getSetting('action.onAbort.file', '') if not path: import xbmcgui xbmcgui.Dialog().ok(T(32090, 'Not Set'), T(32330, 'This action is not set or not yet applied.')) return cvutil.evalActionFile(path)
def videoPreDelay(self): delay = kodiutil.getSetting('video.preDelay', 0) if delay: kodiutil.DEBUG_LOG('Video pre-dalay: {0}ms'.format(delay)) xbmc.sleep(delay)
def lastSavePath(): name = kodiutil.getSetting('save.name', '') return getSavePath(name)
def evalActionFile(paths, test=True): import xbmcgui if not paths: xbmcgui.Dialog().ok(T(32511, 'None found'), T(32512, 'No action file(s) set')) return if not isinstance(paths, list): paths = [paths] messages = [] abortPath = kodiutil.getSetting('action.onAbort.file') if not kodiutil.getSetting('action.onAbort', False): abortPath = None # if not abortPath: # yes = xbmcgui.Dialog().yesno('No Abort', 'Abort action not set.', '') # Test = False for path in paths: processor = cinemavision.actions.ActionFileProcessor(path, test=True) messages.append(u'[B]VALIDATE ({0}):[/B]'.format(os.path.basename(path))) messages.append('') parseMessages = [] hasParseMessages = False hasErrors = False if not processor.fileExists: messages.append(u'{0} - [COLOR FFFF0000]{1}[/COLOR]'.format(os.path.basename(path), T(32513, 'MISSING!'))) messages.append('') continue if processor.parserLog: hasParseMessages = True for type_, msg in processor.parserLog: hasErrors = hasErrors or type_ == 'ERROR' parseMessages .append(u'[COLOR {0}]{1}[/COLOR]'.format(type_ == 'ERROR' and 'FFFF0000' or 'FFFFFF00', msg)) else: parseMessages.append('[COLOR FF00FF00]OK[/COLOR]') messages += parseMessages messages.append('') if test: if hasErrors: messages += [u'[B]TEST ({0}):[/B]'.format(os.path.basename(path)), ''] messages.append(u'[COLOR FFFF0000]{0}[/COLOR]'.format('SKIPPED DUE TO ERRORS')) else: with kodiutil.Progress('Testing', 'Executing actions...'): messages += ['[B]TEST ({0}):[/B]'.format(os.path.basename(path)), ''] for line in processor.test(): if line.startswith('Action ('): lsplit = line.split(': ', 1) line = '[COLOR FFAAAAFF]{0}:[/COLOR] {1}'.format(lsplit[0], lsplit[1]) elif line.startswith('ERROR:'): line = '[COLOR FFFF0000]{0}[/COLOR]'.format(line) messages.append(line) messages.append('') if not test and not hasParseMessages: xbmcgui.Dialog().ok(T(32515, 'Done'), T(32516, 'Action file(s) parsed OK')) else: showText(T(32514, 'Parser Messages'), '[CR]'.join(messages)) if test and abortPath: runAbort = kodiutil.getSetting('action.test.runAbort', 0) if runAbort and (runAbort != 2 or xbmcgui.Dialog().yesno(T(32597, 'Cleanup'), T(32598, 'Run abort action?'))): processor = cinemavision.actions.ActionFileProcessor(abortPath) processor.run()
def evalActionFile(paths, test=True): import xbmcgui if not paths: xbmcgui.Dialog().ok(T(32511, 'None found'), T(32512, 'No action file(s) set')) return if not isinstance(paths, list): paths = [paths] messages = [] abortPath = kodiutil.getSetting('action.onAbort.file') if not kodiutil.getSetting('action.onAbort', False): abortPath = None # if not abortPath: # yes = xbmcgui.Dialog().yesno('No Abort', 'Abort action not set.', '') # Test = False for path in paths: processor = cinemavision.actions.ActionFileProcessor(path, test=True) messages.append(u'[B]VALIDATE ({0}):[/B]'.format( os.path.basename(path))) messages.append('') parseMessages = [] hasParseMessages = False hasErrors = False if not processor.fileExists: messages.append(u'{0} - [COLOR FFFF0000]{1}[/COLOR]'.format( os.path.basename(path), T(32513, 'MISSING!'))) messages.append('') continue if processor.parserLog: hasParseMessages = True for type_, msg in processor.parserLog: hasErrors = hasErrors or type_ == 'ERROR' parseMessages.append(u'[COLOR {0}]{1}[/COLOR]'.format( type_ == 'ERROR' and 'FFFF0000' or 'FFFFFF00', msg)) else: parseMessages.append('[COLOR FF00FF00]OK[/COLOR]') messages += parseMessages messages.append('') if test: if hasErrors: messages += [ u'[B]TEST ({0}):[/B]'.format(os.path.basename(path)), '' ] messages.append(u'[COLOR FFFF0000]{0}[/COLOR]'.format( 'SKIPPED DUE TO ERRORS')) else: with kodiutil.Progress('Testing', 'Executing actions...'): messages += [ u'[B]TEST ({0}):[/B]'.format(os.path.basename(path)), '' ] for line in processor.test(): if line.startswith('Action ('): lsplit = line.split(': ', 1) line = u'[COLOR FFAAAAFF]{0}:[/COLOR] {1}'.format( lsplit[0], lsplit[1]) elif line.startswith('ERROR:'): line = u'[COLOR FFFF0000]{0}[/COLOR]'.format(line) messages.append(line) messages.append('') if not test and not hasParseMessages: xbmcgui.Dialog().ok(T(32515, 'Done'), T(32516, 'Action file(s) parsed OK')) else: showText(T(32514, 'Parser Messages'), '[CR]'.join(messages)) if test and abortPath: runAbort = kodiutil.getSetting('action.test.runAbort', 0) if runAbort and (runAbort != 2 or xbmcgui.Dialog().yesno( T(32597, 'Cleanup'), T(32598, 'Run abort action?'))): processor = cinemavision.actions.ActionFileProcessor(abortPath) processor.run()
def loadContent(self): if self.checkForContentDB() and not kodiutil.getSetting('database.autoUpdate', False): return cvutil.loadContent()
import os import re import json import xbmc import kodiutil import cinemavision from kodiutil import T DEFAULT_3D_RE = '(?i)3DSBS|3D.SBS|HSBS|H.SBS|H-SBS|[\. _]SBS[\. _]|FULL-SBS|FULL.SBS|FULLSBS|FSBS|HALF-SBS|' +\ '3DTAB|3D.TAB|HTAB|H.TAB|3DOU|3D.OU|3D.HOU|[\. _]HOU[\. _]|[\. _]OU[\. _]|HALF-TAB|[\. _]TAB[\. _]' cinemavision.init(kodiutil.DEBUG(), kodiutil.Progress, kodiutil.T, kodiutil.getSetting('3D.tag.regex', DEFAULT_3D_RE)) THEME = None def setTheme(theme_path=None): global THEME default = os.path.join(kodiutil.ADDON_PATH, 'resources', 'themes', 'default') + '/' if theme_path is not None: kodiutil.setSetting('theme.path', theme_path) else: theme_path = kodiutil.getSetting('theme.path', default) cfg = cinemavision.util.pathJoin(theme_path, 'theme.json') try:
def _pasteLog(logName='kodi.log'): import os import re import xbmc import xbmcgui from pastebin_python import PastebinPython logPath = os.path.join(xbmc.translatePath('special://logpath').decode('utf-8'), logName) if not os.path.exists(logPath): xbmcgui.Dialog().ok(T(32570, 'No Log'), ' ', T(32571, 'That log file does not exist!')) return False def debug_log(msg): kodiutil.DEBUG_LOG('PASTEBIN: {0}'.format(msg)) replaces = ( ('//.+?:.+?@', '//USER:PASSWORD@'), ('<user>.+?</user>', '<user>USER</user>'), ('<pass>.+?</pass>', '<pass>PASSWORD</pass>'), ) apiUserKeyFile = os.path.join(kodiutil.PROFILE_PATH, 'settings.pb.key') apiUserKey = '' if os.path.exists(apiUserKeyFile): with open(apiUserKeyFile, 'r') as f: apiUserKey = f.read() or '' pb = PastebinPython(api_dev_key=kodiutil.getPeanutButter(), api_user_key=apiUserKey) apiUser = kodiutil.getSetting('pastebin.user') if apiUser and not apiUserKey: debug_log('Username set, asking user for password') password = xbmcgui.Dialog().input( T(32572, 'Enter Pastebin password (only needed 1st time - NOT stored)'), '', xbmcgui.INPUT_ALPHANUM, xbmcgui.ALPHANUM_HIDE_INPUT ) if password: debug_log('Getting API user key') apiUserKey = pb.createAPIUserKey(apiUser, password) if apiUserKey.lower().startswith('bad'): xbmcgui.Dialog().ok(T(32573, 'Failed'), u'{0}: {1}'.format(T(32574, 'Failed to create paste as user'), apiUser), '', apiUserKey) debug_log('Failed get user API key ({0}): {1}'.format(apiUser, apiUserKey)) else: with open(apiUserKeyFile, 'w') as f: f.write(apiUserKey) else: debug_log('User aborted') xbmcgui.Dialog().ok(T(32575, 'Aborted'), ' ', T(32576, 'Paste aborted!')) return False elif apiUserKey: debug_log('Creating paste with stored API key') with kodiutil.Progress('Pastebin', T(32577, 'Creating paste...')): with open(logPath, 'r') as f: content = f.read().decode('utf-8') for pattern, repl in replaces: content = re.sub(pattern, repl, content) urlOrError = pb.createPaste(content, 'Kodi CV LOG: {0}'.format(logName), api_paste_private=1, api_paste_expire_date='1W') showQR = False if urlOrError.startswith('http'): showQR = xbmcgui.Dialog().yesno( T(32515, 'Done'), T(32578, 'Paste created at:'), '', urlOrError, T(32579, 'OK'), T(32580, 'Show QR Code') ) debug_log('Paste created: {0}'.format(urlOrError)) else: xbmcgui.Dialog().ok(T(32573, 'Failed'), T(32581, 'Failed to create paste:'), '', urlOrError) debug_log('Failed to create paste: {0}'.format(urlOrError)) if showQR: showQRCode(urlOrError) return True
def loadContent(self): if self.checkForContentDB() and not kodiutil.getSetting( 'database.autoUpdate', False): return cvutil.loadContent()
import os import re import xbmc import kodiutil import cinemavision from kodiutil import T DEFAULT_3D_RE = '(?i)3DSBS|3D.SBS|HSBS|H.SBS|H-SBS|[\. _]SBS[\. _]|FULL-SBS|FULL.SBS|FULLSBS|FSBS|HALF-SBS|' +\ '3DTAB|3D.TAB|HTAB|H.TAB|3DOU|3D.OU|3D.HOU|[\. _]HOU[\. _]|[\. _]OU[\. _]|HALF-TAB|[\. _]TAB[\. _]' cinemavision.init(kodiutil.DEBUG(), kodiutil.Progress, kodiutil.T, kodiutil.getSetting('3D.tag.regex', DEFAULT_3D_RE)) def defaultSavePath(for_3D=False): return os.path.join(kodiutil.ADDON_PATH, 'resources', 'script.cinemavision.default{0}.cvseq'.format(for_3D and '3D' or '2D')) def lastSavePath(): name = kodiutil.getSetting('save.name', '') return getSavePath(name) def getSavePath(name): contentPath = kodiutil.getSetting('content.path') if not name or not contentPath: return return cinemavision.util.pathJoin(contentPath, 'Sequences', name + '.cvseq')