def action(self, request): global utf8ToLatin global Manager if utf8ToLatin is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.Utf8 import utf8ToLatin if Manager is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.Manager import Manager finalOutput = WebHelper().getHtmlCore("Home") currentVersion = Update().getInstalledRevision() manager = Manager("WebIf:MainActions") movieCount = str(manager.getMoviesCount()) tvShowCount = str(manager.getSeriesCount()) episodeCount = str(manager.getEpisodesCount()) updateType = Update().getCurrentUpdateType() latestRevision = Update().getLatestRevision() finalOutput = finalOutput.replace("<!-- MOVIE_COUNT -->", movieCount) finalOutput = finalOutput.replace("<!-- TVSHOW_COUNT -->", tvShowCount) finalOutput = finalOutput.replace("<!-- EPISODE_COUNT -->", episodeCount) revisionText = """ <br> Your update type => %s.<br> The latest release for your update type is %s.<br> """ % (updateType, latestRevision) finalOutput = finalOutput.replace("<!-- CURRENT_VERSION -->", "Your installed revision => " + currentVersion) finalOutput = finalOutput.replace("<!-- LATEST_VERSION -->", revisionText) return utf8ToLatin(finalOutput)
def __init__(self, session): global Manager if Manager is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.Manager import Manager self.manager = Manager("NewestEpisodes") DMC_Library.__init__(self, session, "tv shows - newest")
def setSeen(id, seen): global manager if manager is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.Manager import Manager manager = Manager("DMC_SEEN") userId = config.plugins.pvmc.seenuserid.value if seen: # manager.MarkAsSeen(id, None) manager.MarkAsSeen(id, userId) else: manager.MarkAsUnseen(id, userId)
def __init__(self, session): printl ("->", self) global Manager if Manager is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.Manager import Manager printl ("Manager Imported") self.manager = Manager("Movies") DMC_Library.__init__(self, session, "movies")
def action(self, request): global utf8ToLatin global Manager if utf8ToLatin is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.Utf8 import utf8ToLatin if Manager is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.Manager import Manager finalOutput = WebHelper().getHtmlCore("Home") # update checker broken so set fixed values - steve4744 #currentVersion = Update().getInstalledRevision() currentVersion = "r1280" manager = Manager("WebIf:MainActions") movieCount = str(manager.getMoviesCount()) tvShowCount = str(manager.getSeriesCount()) episodeCount = str(manager.getEpisodesCount()) # update checker broken so set fixed values - steve4744 #updateType = Update().getCurrentUpdateType() #latestRevision = Update().getLatestRevision() updateType = "Release" latestRevision = "r1280" finalOutput = finalOutput.replace("<!-- MOVIE_COUNT -->", movieCount) finalOutput = finalOutput.replace("<!-- TVSHOW_COUNT -->", tvShowCount) finalOutput = finalOutput.replace("<!-- EPISODE_COUNT -->", episodeCount) revisionText = """ <br> Your update type => %s.<br> The latest release for your update type is %s.<br> """ % (updateType, latestRevision) finalOutput = finalOutput.replace( "<!-- CURRENT_VERSION -->", "Your installed revision => " + currentVersion) finalOutput = finalOutput.replace("<!-- LATEST_VERSION -->", revisionText) return utf8ToLatin(finalOutput)
def __init__(self, session, args): global Manager global utf8ToLatin if Manager is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.Manager import Manager if utf8ToLatin is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.Utf8 import utf8ToLatin self.session = session self.service = config.plugins.pvmc.plugins.subdown.provider.value self.language_1 = config.plugins.pvmc.plugins.subdown.language1.value self.language_2 = config.plugins.pvmc.plugins.subdown.language2.value self.language_3 = config.plugins.pvmc.plugins.subdown.language3.value year = str(args["Year"]) title = args["Title"] # + " (" + str(year) + ")" if args.has_key("Season"): season = str(args["Season"]) episode = str(args["Episode"]) #tvshowEntry = Manager("SubtitleDownloader").getElement_ByUsingPrimaryKey(Manager.TVSHOWS, \ # dict({'thetvdbid': args["TheTvDbId"]})) tvshowEntry = Manager("SubtitleDownloader").getMedia(args["Id"]) tvshow = tvshowEntry.Title else: season = "" episode = "" tvshow = "" self.file_original_path = args["Path"] set_temp = False rar = False self.tmp_sub_dir = "/tmp/subdir" try: shutil.rmtree(str(self.tmp_sub_dir)) except Exception, ex: printl("Exception: " + str(ex), __name__, "E")
class DMC_NewestEpisodes(DMC_Library): def __init__(self, session): global Manager if Manager is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.Manager import Manager self.manager = Manager("NewestEpisodes") DMC_Library.__init__(self, session, "tv shows - newest") ### # Return Value is expected to be: # (libraryArray, onEnterPrimaryKeys, onLeavePrimaryKeys, onLeaveSelectEntry def loadLibrary(self, primaryKeyValuePair, seenPng=None, unseenPng=None): printl("->", self) global Manager global utf8ToLatin if utf8ToLatin is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.Utf8 import utf8ToLatin start_time = time.time() userId = config.plugins.pvmc.seenuserid.value # Diplay all TVShows if primaryKeyValuePair is None: parsedLibrary = [] today = date.today() tmpGenres = [] shows = {} daysBack = config.plugins.pvmc.plugins.latestepisodes.daysback.value #episodes = self.manager.get.All(Manager.TVSHOWSEPISODES) episodes = self.manager.getAllEpisodes() for episode in episodes: try: fileCreationValidTime = False epDate = date(episode.Year, episode.Month, episode.Day) if self.checkFileCreationDate: try: creation = episode.FileCreation cDate = date.fromtimestamp(creation) if (today - cDate).days < daysBack: fileCreationValidTime = True except Exception, ex: printl("Exception(" + str(type(ex)) + "): " + str(ex), self, "W") creation = 0 if (today - epDate).days < daysBack or fileCreationValidTime: if not shows.has_key(episode.ParentId): tvshow = self.manager.getMedia(episode.ParentId) shows[episode.ParentId] = tvshow genres = utf8ToLatin(tvshow.Genres).split("|") for genre in genres: if genre not in tmpGenres: tmpGenres.append(genre) else: tvshow = shows[episode.ParentId] d = {} d["ArtBackdropId"] = utf8ToLatin(tvshow.TheTvDbId) d["ArtPosterId"] = d["ArtBackdropId"] d["Id"] = episode.Id d["ImdbId"] = utf8ToLatin(tvshow.ImdbId) d["TheTvDbId"] = utf8ToLatin(episode.TheTvDbId) d["Tag"] = utf8ToLatin(tvshow.Tag) d["Title"] = " %s %dx%02d: %s" % ( utf8ToLatin(tvshow.Title), episode.Season, episode.Episode, utf8ToLatin(episode.Title), ) d["ScreenTitle"] = d["Title"] d["ScreenTitle"] = utf8ToLatin(d["ScreenTitle"]) d["Year"] = episode.Year d["Month"] = episode.Month d["Day"] = episode.Day d["Date"] = episode.getDate() d["Creation"] = episode.FileCreation d["Path"] = utf8ToLatin(episode.Path + "/" + episode.Filename + "." + episode.Extension) d["Season"] = episode.Season d["Episode"] = episode.Episode d["Plot"] = utf8ToLatin(episode.Plot) d["Runtime"] = episode.Runtime d["Popularity"] = episode.Popularity d["Genres"] = utf8ToLatin(episode.Genres).split("|") d["Resolution"] = utf8ToLatin(episode.Resolution) d["Sound"] = utf8ToLatin(episode.Sound) if self.manager.isMediaSeen(d["Id"], userId): image = seenPng d["Seen"] = "Seen" else: image = unseenPng d["Seen"] = "Unseen" d["ViewMode"] = "play" parsedLibrary.append( (d["Title"], d, episode.Season * 1000 + episode.Episode, "50", image)) except Exception, ex: printl("Exception while loading library: " + str(ex), self, "E") printl("\tEntry: " + str(episode), self, "E")
class DMC_MovieLibrary(DMC_Library): def __init__(self, session): printl ("->", self) global Manager if Manager is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.Manager import Manager printl ("Manager Imported") self.manager = Manager("Movies") DMC_Library.__init__(self, session, "movies") ### # Return Value is expected to be: # (libraryArray, onEnterPrimaryKeys, onLeavePrimaryKeys, onLeaveSelectEntry def loadLibrary(self, params, seenPng=None, unseenPng=None): global Manager global utf8ToLatin if utf8ToLatin is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.Utf8 import utf8ToLatin userId = config.plugins.pvmc.seenuserid.value # Diplay all Movies if params is None: parsedLibrary = [] library = self.manager.getMoviesValues() tmpAbc = [] tmpGenres = [] for movie in library: # not needed anymore in my point of view #if len(str(movie.Title)) == 0: # or len(movie.ImdbId) == 0: # printl("Movie with empty Title in database!", self, "W") # continue d = {} d["ArtBackdropId"] = utf8ToLatin(movie.ImdbId) d["ArtPosterId"] = d["ArtBackdropId"] d["Id"] = movie.Id d["ImdbId"] = utf8ToLatin(movie.ImdbId) d["Title"] = " " + utf8ToLatin(movie.Title) if d["Title"][2].upper() not in tmpAbc: tmpAbc.append(d["Title"][2].upper()) d["Tag"] = utf8ToLatin(movie.Tag) d["Year"] = movie.Year d["Month"] = movie.Month d["Day"] = movie.Day d["Date"] = movie.getDate() d["Filename"] = utf8ToLatin(movie.Filename).lower() d["Path"] = utf8ToLatin(str(movie.Path) + "/" + str(movie.Filename) + "." + str(movie.Extension)) d["Creation"] = movie.FileCreation d["Plot"] = utf8ToLatin(movie.Plot) d["Runtime"] = movie.Runtime d["Popularity"] = movie.Popularity d["Genres"] = utf8ToLatin(movie.Genres).split("|") for genre in d["Genres"]: if genre not in tmpGenres: tmpGenres.append(genre) d["Resolution"] = utf8ToLatin(movie.Resolution) d["Sound"] = utf8ToLatin(movie.Sound) if self.manager.isMediaSeen(d["Id"], userId): image = seenPng d["Seen"] = "Seen" else: image = unseenPng d["Seen"] = "Unseen" d["ViewMode"] = "play" d["ScreenTitle"] = utf8ToLatin(movie.Title) parsedLibrary.append((d["Title"], d, d["Title"].lower(), "50", image)) sort = [("Title", None, False), ("Popularity", "Popularity", True), ("Aired", "Date", True), ] if self.checkFileCreationDate: sort.append(("File Creation", "Creation", True)) sort.append(("Filename", "Filename", False)) filter = [("All", (None, False), ("", )), ] filter.append(("Seen", ("Seen", False, 1), ("Seen", "Unseen", ))) if len(tmpGenres) > 0: tmpGenres.sort() filter.append(("Genre", ("Genres", True), tmpGenres)) if len(tmpAbc) > 0: tmpAbc.sort() filter.append(("Abc", ("Title", False, 1), tmpAbc)) return (parsedLibrary, ("ViewMode", "Id", ), None, None, sort, filter) elif params["ViewMode"] == "Tree": pass elif params["ViewMode"]=="ShowGroup": pass return None def buildInfoPlaybackArgs(self, entry): args = {} args["id"] = entry["Id"] args["title"] = entry["Title"] args["year"] = entry["Year"] args["imdbid"] = entry["ImdbId"] args["type"] = "movie" return args
def action(self, request): global Manager global utf8ToLatin global MediaInfo if Manager is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.Manager import Manager if utf8ToLatin is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.Utf8 import utf8ToLatin if MediaInfo is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.MediaInfo import MediaInfo printl("request: " + str(request), self) printl("request.args: " + str(request.args), self) printl("request.args[mode]: " + str(request.args["mode"]), self) ########################## # OPTIONS SECTION # Argument: request.args["mode"][0] == "options.saveconfig" # request.args["what"][0] == "settings_global" | "settings_sync" ########################## if request.args["mode"][0] == "options.saveconfig": printl("mode (options.saveconfig)", self, "I") what = request.args["what"][0] #settings_global if what == "settings_global": name = request.args["name"][0] value = "unchecked" if request.args.has_key("value"): value = request.args["value"][0] valueType = request.args["type"][0] printl( "name=\"%s\" value=\"%s\" type=\"%s\"" % (name, value, valueType), self, "D") entries = WebData().getData("options.global") for entry in entries: if entry[0] == name: if valueType == "text" or valueType == "select": printl("Setting \"%s\" to \"%s\"" % (name, value), self, "I") entry[1].value = value elif valueType == "checkbox": if value == "checked" or value == "on": value = True else: value = False printl("Setting \"%s\" to \"%s\"" % (name, value), self, "I") entry[1].value = value entry[1].save() # settins_sync elif what == "settings_sync": printl("argument => what = settings_sync", self, "I") if request.args["section"][0] == "paths": printl("argument => section = path", self, "I") id = request.args["Id"][0] directory = request.args["directory"][0] typeFolder = request.args["type"][0] enabled = request.args.has_key("enabled") useFolder = request.args.has_key("usefolder") path = { "directory": directory, "enabled": enabled, "usefolder": useFolder, "type": typeFolder } action = "standard" from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.PathsConfig import PathsConfig if directory == "": action = "delete" PathsConfig().getInstance().setPath(id, path, action) PathsConfig().getInstance().save() elif request.args["section"][0] == "filetypes": printl("argument => section = filetypes", self, "I") value = request.args["value"][0] from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.PathsConfig import PathsConfig PathsConfig().getInstance().setFileTypes(value.split("|")) PathsConfig().getInstance().save() return WebHelper().redirectMeTo("/options") ########################## # DUMP DATABASE - view via webif http://url:8888/dumps # Argument: request.args["mode"][0] == "dumpDb" ########################## elif request.args["mode"][0] == "dumpDb": printl("mode (dumpDb)", self, "I") Manager("WebIf:SubActions:WebFunctions").getDbDump() return WebHelper().redirectMeTo("/dumps") ########################## # BACKUP SECTION # Argument: request.args["mode"][0] == "backupValerie" ########################## elif request.args["mode"][0] == "backupValerie": printl("mode (backupValerie)", self, "I") #import zipfile, os #zipf = zipfile.ZipFile('/hdd/valerie-backup.zip', mode='w', compression=zipfile.ZIP_STORED ) #path = utf8ToLatin(config.plugins.pvmc.tmpfolderpath.value) #WebHelper().recursive_zip(zipf, path) #zipf.close() backupFile = '/mnt/net/store/valerie-backup.tar' sourcePath = utf8ToLatin(config.plugins.pvmc.tmpfolderpath.value) os.system("tar -cvf " + backupFile + " " + sourcePath + " --exclude 'tmp/*' --exclude 'tmp'") return WebHelper().redirectMeTo("/elog/") ########################## # RESTORE SECTION - do not use for now fills up the flash => freeze # Argument: request.args["mode"][0] == "restoreValerie" # Information: http://webpython.codepoint.net/cgi_file_upload ########################## elif request.args["mode"][0] == "restoreValerie": printl("mode (restoreValerie)", self, "I") outputStream = open(filename, '/hdd/test.zip') outputStream.write(request.args['myFile']) outputStream.close()
def action(self, request): global Manager global utf8ToLatin global stringToUtf8 global MediaInfo if Manager is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.Manager import Manager if stringToUtf8 is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.Utf8 import stringToUtf8 if utf8ToLatin is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.Utf8 import utf8ToLatin if MediaInfo is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.MediaInfo import MediaInfo printl("request: " + str(request), self) printl("request.args: " + str(request.args), self) printl("request.args[mode]: " + str(request.args["mode"]), self) ########################## # ADD SECTION # Argument: request.args["mode"][0] == "addMediaToDb" # Subargument: request.args["type"][0] == "isMovie" | "isTvShow" | "isEpisode" # request.args["ParentId"][0] == Integer ########################## if request.args["mode"][0] == "addMediaToDb": printl("mode (addMediaToDb)", self, "I") manager = Manager("WebIf:SubActions:MediaActions") type = request.args["type"][0] if (type == "isEpisode"): parentId = request.args["ParentId"][0] key_value_dict = {} for key in request.args.keys(): key_value_dict[key] = request.args[key][0] # add movies if type == "isMovie": printl("INSERT MOVIE : " + str(key_value_dict), self, "I") result = manager.insertMediaWithDict(Manager.MOVIES, key_value_dict) if result["status"] > 0: return WebHelper().redirectMeTo( "/movies?mode=showDoneForm&showSave=true") else: return WebHelper().redirectMeTo( "/mediaForm?mode=showErrorForm&type=isMovie&" + urlencode({'msg': result["message"]})) # add tvshows elif type == "isTvShow": printl("INSERT TVSHOW : " + str(key_value_dict), self, "I") result = manager.insertMediaWithDict(Manager.TVSHOWS, key_value_dict) if result["status"] > 0: return WebHelper().redirectMeTo( "/tvshows?mode=showDoneForm&showSave=true") else: return WebHelper().redirectMeTo( "/mediaForm?mode=showErrorForm&type=isTvShow&" + urlencode({'msg': result["message"]})) # add tvshowepisodes elif type == "isEpisode": printl("INSERT EPISODE: " + str(key_value_dict), self, "I") result = manager.insertMediaWithDict(Manager.TVSHOWSEPISODES, key_value_dict) if result["status"] > 0: return WebHelper().redirectMeTo( "/episodes?mode=showDoneForm&ParentId=" + parentId + "&showSave=true") else: return WebHelper().redirectMeTo( "/mediaForm?mode=showErrorForm&type=isEpisode&ParentId=" + parentId + "&" + urlencode({'msg': result["message"]})) ########################## # EDIT SECTION # Argument: request.args["mode"][0] == "alterMediaInDb" # Subargument: request.args["type"][0] == "isMovie" | "isTvShow" | "isEpisode" # request.args["Id"][0] == Integer # request.args["ParentId"][0] == Integer ########################## elif request.args["mode"][0] == "alterMediaInDb": printl("mode (alterMediaInDb)", self, "I") manager = Manager("WebIf:SubActions:MediaActions") type = stringToUtf8(request.args["type"][0]) Id = request.args["Id"][0] if (type == "isEpisode"): parentId = request.args["ParentId"][0] key_value_dict = {} for key in request.args.keys(): # key_value_dict[key] = stringToUtf8(request.args[key][0]) key_value_dict[key] = request.args[key][0] printl("Content: " + key + " => " + request.args[key][0], self, "I") if not "Seen" in request.args: WebData().getData("MediaInfo_markUnseen", Id) else: if (request.args["Seen"][0] == "on"): WebData().getData("MediaInfo_markSeen", Id) # edit movies if type == "isMovie": result = manager.updateMediaWithDict(Manager.MOVIES, key_value_dict) printl("alter Movie in Db", self, "I") if result is True: printl("TRUE", self, "I") return WebHelper().redirectMeTo( "/movies?mode=showDoneForm&Id=" + Id + "&showSave=true") else: printl("FALSE", self, "I") return WebHelper().redirectMeTo( "/mediaForm?mode=showErrorForm&type=isMovie&Id=" + Id) # edit tvshows elif type == "isTvShow": result = manager.updateMediaWithDict(Manager.TVSHOWS, key_value_dict) if result: return WebHelper().redirectMeTo( "/tvshows?mode=showDoneForm&Id=" + Id + "&showSave=true") else: return WebHelper().redirectMeTo( "/mediaForm?mode=showErrorForm&type=isTvShow&Id=" + Id) # edit tvsshowepisodes elif type == "isEpisode": result = manager.updateMediaWithDict(Manager.TVSHOWSEPISODES, key_value_dict) if result: return WebHelper().redirectMeTo( "/episodes?mode=showDoneForm&Id=" + Id + "&ParentId=" + parentId + "&showSave=true") else: return WebHelper().redirectMeTo( "/mediaForm?mode=showErrorForm&type=isEpisode&ParentId=" + parentId + "&Id=" + Id) ########################## # DELETE SECTION # Argument: request.args["mode"][0] == "deleteMediaFromDb" # Subargument: request.args["Id"][0] == Integer # request.args["ParentId"][0] == Integer # request.args["type"][0] == "isMovie" | "isTvShow" | "isEpisode" ########################## elif request.args["mode"][0] == "deleteMediaFromDb": printl("mode (deleteMediaFromDb)", self, "I") manager = Manager("WebIf:SubActions:MediaActions") id = request.args["Id"][0] type = request.args["type"][0] if (type == "isEpisode"): parentId = request.args["ParentId"][0] result = manager.deleteMedia(id) #delete movie if type == "isMovie": if result: return WebHelper().redirectMeTo( "/movies?mode=showDoneForm&showSave=true") else: return WebHelper().redirectMeTo( "/mediaForm?mode=showErrorForm&type=isMovie") # delete tvshowepisodes elif type == "isEpisode": if result: return WebHelper().redirectMeTo( "/episodes?mode=showDoneForm&ParentId=" + parentId + "&showSave=true") else: return WebHelper().redirectMeTo( "/mediaForm?mode=showErrorForm&tpye=isEpisode&ParentId=" + parentId) # delete tvshow elif type == "isTvShow": if result: return WebHelper().redirectMeTo( "/tvshows?mode=showDoneForm&showSave=true") else: return WebHelper().redirectMeTo( "/mediaForm?mode=showErrorForm&type=isTvShow") # delete failed elif type == "isFailed": if result: return WebHelper().redirectMeTo("/failed?showSave=true") else: return WebHelper().redirectMeTo( "/mediaForm?mode=showErrorForm&type=isTvShow") ########################## # CHANGE ARTS SECTION # Argument: request.args["mode"][0] == "changeMediaArts" # Subargument: request.args["Id"][0] == Integer # request.args["type"][0] == "isMovie" | "isTvShow" | "isEpisode" # request.args["media_type"][0] == "poster" | "backdrop" # request.args["media_source"][0] == String ########################## elif request.args["mode"][0] == "changeMediaArts": printl("mode (changeMediaArts)", self, "I") manager = Manager("WebIf:SubActions:MediaActions") type = request.args["type"][0] media_source = request.args["media_source"][0] media_type = request.args["media_type"][0] Id = request.args["Id"][0] printl("media_source => " + media_source + ")", self, "I") if (media_source[0:7] != "user://"): if (media_source[0:7] == "http://" or media_source[0:8] == "https://" or media_source[0:1] == "/"): media_source = "user://" + media_source printl( "media_source without user:// found => correcting to new value = " + media_source, self, "I") else: printl( "media_source seems to have bad format at all - trying it anyway without warranty ;-)", self, "W") else: printl("media_source with user:// found => no changes needed", self, "I") #change movie art if type == "isMovie": t = Manager.MOVIES #change tvshow art elif type == "isTvShow": t = Manager.TVSHOWS #change episode art elif type == "isEpisode": t = Manager.TVSHOWSEPISODES else: return utf8ToLatin("error") if media_type == "poster": result = manager.changeMediaArts(t, Id, True, None, media_source) if result == True: return utf8ToLatin("success") else: return utf8ToLatin("error") elif media_type == "backdrop": result = manager.changeMediaArts(t, Id, True, media_source, None) if result == True: return utf8ToLatin("success") else: return utf8ToLatin("error") else: printl("no media type found", self) return utf8ToLatin("error") return utf8ToLatin("error") ########################## # SAVE TO DB # Argument: request.args["mode"][0] == "saveChangesToDb" ########################## elif request.args["mode"][0] == "saveChangesToDb": printl("mode (saveChangesToDb)", self, "I") manager = Manager("WebIf:SubActions:MediaActions") manager.finish() if request.args["return_to"][0] == "movies": return WebHelper().redirectMeTo("/movies") elif request.args["return_to"][0] == "tvshows": return WebHelper().redirectMeTo("/tvshows") elif request.args["return_to"][0] == "episodes": return WebHelper().redirectMeTo("/episodes") elif request.args["return_to"][0] == "failed": return WebHelper().redirectMeTo("/failed") ########################## # MOVE TO FAILED SECTION # Argument: request.args["mode"][0] == "moveToFailedSection" # Subargument: request.args["Id"][0] == Integer ########################## elif request.args["mode"][0] == "moveToFailedSection": manager = Manager("WebIf:SubActions:MediaActions") type = request.args["type"][0] Id = request.args["Id"][0] result = manager.moveToFailedSection(Id, type) if (type == "isEpisode"): parentId = request.args["ParentId"][0] #delete movie if type == "isMovie": if result: return WebHelper().redirectMeTo( "/movies?mode=showDoneForm&showSave=true") else: return WebHelper().redirectMeTo( "/mediaForm?mode=showErrorForm&type=isMovie") # delete tvshowepisodes elif type == "isEpisode": if result: return WebHelper().redirectMeTo( "/episodes?mode=showDoneForm&ParentId=" + parentId + "&showSave=true") else: return WebHelper().redirectMeTo( "/mediaForm?mode=showErrorForm&tpye=isEpisode&ParentId=" + parentId) # delete tvshow elif type == "isTvShow": if result: return WebHelper().redirectMeTo( "/tvshows?mode=showDoneForm&showSave=true") else: return WebHelper().redirectMeTo( "/mediaForm?mode=showErrorForm&type=isTvShow")
class DMC_TvShowLibrary(DMC_Library): def __init__(self, session): global Manager if Manager is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.Manager import Manager self.manager = Manager("TVShows") DMC_Library.__init__(self, session, "tv shows") ### # Return Value is expected to be: # (libraryArray, onEnterPrimaryKeys, onLeavePrimaryKeys, onLeaveSelectEntry def loadLibrary(self, params, seenPng=None, unseenPng=None): global Manager global utf8ToLatin if utf8ToLatin is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.Utf8 import utf8ToLatin printl("DEBUG 3", self) printl("", self) printl("params=" + str(params), self) userId = config.plugins.pvmc.seenuserid.value # Diplay all TVShows if params is None: printl("Series", self) parsedLibrary = [] library = self.manager.getSeriesValues() tmpAbc = [] tmpGenres = [] for tvshow in library: d = {} d["ArtBackdropId"] = utf8ToLatin(tvshow.TheTvDbId) d["ArtPosterId"] = d["ArtBackdropId"] d["Id"] = tvshow.Id d["ImdbId"] = utf8ToLatin(tvshow.ImdbId) d["TheTvDbId"] = utf8ToLatin(tvshow.TheTvDbId) d["Title"] = " " + utf8ToLatin(tvshow.Title) if d["Title"][2].upper() not in tmpAbc: tmpAbc.append(d["Title"][2].upper()) d["Tag"] = utf8ToLatin(tvshow.Tag) d["Year"] = tvshow.Year d["Month"] = tvshow.Month d["Day"] = tvshow.Day d["Plot"] = utf8ToLatin(tvshow.Plot) d["Runtime"] = tvshow.Runtime d["Popularity"] = tvshow.Popularity d["Genres"] = utf8ToLatin(tvshow.Genres).split("|") for genre in d["Genres"]: if genre not in tmpGenres: tmpGenres.append(genre) if config.plugins.pvmc.showseenforshow.value is True: #if self.manager.is_Seen({"TheTvDbId": d["TheTvDbId"]}): if self.manager.isMediaSeen(d["Id"], userId): image = seenPng else: image = unseenPng else: image = None d["ScreenTitle"] = d["Title"] d["ScreenTitle"] = utf8ToLatin(d["ScreenTitle"]) d["ViewMode"] = "ShowSeasons" parsedLibrary.append( (d["Title"], d, d["Title"].lower(), "50", image)) sort = ( ("Title", None, False), ("Popularity", "Popularity", True), ) filter = [ ("All", (None, False), ("", )), ] if len(tmpGenres) > 0: tmpGenres.sort() filter.append(("Genre", ("Genres", True), tmpGenres)) if len(tmpAbc) > 0: tmpAbc.sort() filter.append(("Abc", ("Title", False, 1), tmpAbc)) return ( parsedLibrary, #listViewList ( "ViewMode", "Id", ), #onEnterPrimaryKeys None, #onLeavePrimaryKeyValuePair None, #onLeaveSelectKeyValuePair sort, #onSortKeyValuePair filter, #onFilterKeyValuePair ) # Display the Seasons Menu elif params["ViewMode"] == "ShowSeasons": printl("Seasons", self) parsedLibrary = [] tvshow = self.manager.getMedia(params["Id"]) d = {} d["ArtBackdropId"] = utf8ToLatin(tvshow.TheTvDbId) d["Id"] = tvshow.Id d["ImdbId"] = utf8ToLatin(tvshow.ImdbId) d["TheTvDbId"] = utf8ToLatin(tvshow.TheTvDbId) d["Tag"] = utf8ToLatin(tvshow.Tag) d["Year"] = tvshow.Year d["Month"] = tvshow.Month d["Day"] = tvshow.Day d["Plot"] = utf8ToLatin(tvshow.Plot) d["Runtime"] = tvshow.Runtime d["Popularity"] = tvshow.Popularity d["Genres"] = utf8ToLatin(tvshow.Genres).split("|") library = self.manager.getEpisodes(params["Id"]) seasons = [] for entry in library: season = entry.Season if season not in seasons: seasons.append(season) s = d.copy() if entry.Season is None: s["Title"] = " Special" s["Season"] = "" # for retrive data only with season=None else: s["Title"] = " Season %2d" % (season, ) s["Season"] = season s["ScreenTitle"] = tvshow.Title + " - " + s["Title"].strip( ) s["ScreenTitle"] = utf8ToLatin(s["ScreenTitle"]) s["ArtPosterId"] = d["ArtBackdropId"] + "_s" + str(season) if config.plugins.pvmc.showseenforseason.value is True: if self.manager.isMediaSeen(d["Id"], s["Season"], userId): image = seenPng else: image = unseenPng else: image = None s["ViewMode"] = "ShowEpisodes" parsedLibrary.append((s["Title"], s, season, "50", image)) sort = (("Title", None, False), ) filter = [ ("All", (None, False), ("", )), ] return (parsedLibrary, ( "ViewMode", "Id", "Season", ), None, params, sort, filter) # (libraryArray, onEnterPrimaryKeys, onLeavePrimaryKeys, onLeaveSelectEntry # Display the Episodes Menu elif params["ViewMode"] == "ShowEpisodes": printl("EpisodesOfSeason", self) parsedLibrary = [] tvshow = self.manager.getMedia(params["Id"]) library = self.manager.getEpisodes(params["Id"], params["Season"]) for episode in library: try: d = {} d["ArtBackdropId"] = utf8ToLatin(tvshow.TheTvDbId) d["ArtPosterId"] = d["ArtBackdropId"] d["Id"] = episode.Id d["TVShowId"] = tvshow.Id d["ImdbId"] = utf8ToLatin(tvshow.ImdbId) d["TheTvDbId"] = utf8ToLatin(episode.TheTvDbId) d["Tag"] = utf8ToLatin(tvshow.Tag) #d["Title"] = " %dx%02d: %s" % (episode.Season, episode.Episode, utf8ToLatin(episode.Title), ) if episode.Season is None and episode.Disc is None and episode.Episode is not None: # # Only Episode d["Title"] = " %s: %s" % ( episode.Episode, utf8ToLatin(episode.Title), ) elif episode.Season is None and episode.Disc is not None and episode.Episode is None: # Only Disc d["Title"] = " Disc %s: %s" % ( episode.Disc, utf8ToLatin(episode.Title), ) elif episode.Season is not None and episode.Disc is None and episode.Episode is not None and episode.EpisodeLast is not None: # # Without Disc, With Episode And EpisodeLast d["Title"] = " %02d-%02d: %s" % ( episode.Episode, episode.EpisodeLast, utf8ToLatin(episode.Title), ) elif episode.Season is not None and episode.Disc is None and episode.Episode is not None: # # Without Disc, With Episode d["Title"] = " %02d: %s" % ( episode.Episode, utf8ToLatin(episode.Title), ) elif episode.Season is not None and episode.Disc is not None and episode.Episode is not None and episode.EpisodeLast is not None: # # With Disc, With Episode And EpisodeLast d["Title"] = " D%sE%s-E%s: %s" % ( episode.Disc, episode.Episode, episode.EpisodeLast, utf8ToLatin(episode.Title)) elif episode.Season is not None and episode.Disc is not None and episode.Episode is not None and episode.EpisodeLast is None: # # With Disc, Without EpisodeLast d["Title"] = " D%sE%s: %s" % ( episode.Disc, episode.Episode, utf8ToLatin(episode.Title), ) elif episode.Season is not None and episode.Disc is not None and episode.Episode is None: # # With Disc, Without Episode d["Title"] = " Disc %s: %s" % ( episode.Disc, utf8ToLatin(episode.Title), ) else: d["Title"] = " %s" % (utf8ToLatin(episode.Title), ) if episode.Season is None: d["ScreenTitle"] = tvshow.Title + " - " + "Special" else: d["ScreenTitle"] = tvshow.Title + " - " + "Season %2d" % ( episode.Season, ) d["ScreenTitle"] = utf8ToLatin(d["ScreenTitle"]) d["Year"] = episode.Year d["Month"] = episode.Month d["Day"] = episode.Day d["Path"] = utf8ToLatin(episode.Path + "/" + episode.Filename + "." + episode.Extension) d["Creation"] = episode.FileCreation d["Season"] = episode.Season d["Episode"] = episode.Episode d["Plot"] = utf8ToLatin(episode.Plot) d["Runtime"] = episode.Runtime d["Popularity"] = episode.Popularity d["Genres"] = utf8ToLatin(episode.Genres).split("|") d["Resolution"] = utf8ToLatin(episode.Resolution) d["Sound"] = utf8ToLatin(episode.Sound) if self.manager.isMediaSeen(d["Id"], userId): image = seenPng d["Seen"] = "Seen" else: image = unseenPng d["Seen"] = "Unseen" d["ViewMode"] = "play" _season = episode.Season if _season is None: _season = 0 _disc = episode.Disc if _disc is None: _disc = 0 _episode = episode.Episode if _episode is None: _episode = 0 printl("DISC: " + repr(_disc), self) _season = int(_season) _disc = int(_disc) _episode = int(_episode) parsedLibrary.append( (d["Title"], d, _season * 100000 + _disc * 1000 + _episode, "50", image)) except Exception, ex: printl("Exception: " + str(ex), self, "E") printl("episode: " + str(episode), self, "E") sort = [ ("Title", None, False), ("Popularity", "Popularity", True), ] if self.checkFileCreationDate: sort.append(("File Creation", "Creation", True)) filter = [ ("All", (None, False), ("", )), ] filter.append(("Seen", ("Seen", False, 1), ( "Seen", "Unseen", ))) return (parsedLibrary, ("ViewMode", "Id", "TVShowId", "Season", "Episode", ), \ dict({'ViewMode': "ShowSeasons", 'Id': params["Id"],}), \ params, sort, filter) # (libraryArray, onEnterPrimaryKeys, onLeavePrimaryKeys, onLeaveSelectEntry return None
class DMC_NewestEpisodes(DMC_Library): def __init__(self, session): global Manager if Manager is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.Manager import Manager self.manager = Manager("NewestEpisodes") DMC_Library.__init__(self, session, "tv shows - newest") ### # Return Value is expected to be: # (libraryArray, onEnterPrimaryKeys, onLeavePrimaryKeys, onLeaveSelectEntry def loadLibrary(self, primaryKeyValuePair, seenPng=None, unseenPng=None): printl("->", self) global Manager global utf8ToLatin if utf8ToLatin is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.Utf8 import utf8ToLatin start_time = time.time() userId = config.plugins.pvmc.seenuserid.value # Diplay all TVShows if primaryKeyValuePair is None: parsedLibrary = [] today = date.today() tmpGenres = [] shows = {} daysBack = config.plugins.pvmc.plugins.latestepisodes.daysback.value #episodes = self.manager.get.All(Manager.TVSHOWSEPISODES) episodes = self.manager.getAllEpisodes() for episode in episodes: try: fileCreationValidTime = False epDate = date(episode.Year, episode.Month, episode.Day) if self.checkFileCreationDate: try: creation = episode.FileCreation cDate = date.fromtimestamp(creation) if (today-cDate).days < daysBack: fileCreationValidTime = True except Exception, ex: printl("Exception(" + str(type(ex)) + "): " + str(ex), self, "W") creation = 0 if (today-epDate).days < daysBack or fileCreationValidTime: if not shows.has_key(episode.ParentId): tvshow = self.manager.getMedia(episode.ParentId) shows[episode.ParentId]= tvshow genres = utf8ToLatin(tvshow.Genres).split("|") for genre in genres: if genre not in tmpGenres: tmpGenres.append(genre) else: tvshow = shows[episode.ParentId] d = {} d["ArtBackdropId"] = utf8ToLatin(tvshow.TheTvDbId) d["ArtPosterId"] = d["ArtBackdropId"] d["Id"] = episode.Id d["ImdbId"] = utf8ToLatin(tvshow.ImdbId) d["TheTvDbId"] = utf8ToLatin(episode.TheTvDbId) d["Tag"] = utf8ToLatin(tvshow.Tag) d["Title"] = " %s %dx%02d: %s" % (utf8ToLatin(tvshow.Title),episode.Season, episode.Episode, utf8ToLatin(episode.Title), ) d["ScreenTitle"] = d["Title"] d["ScreenTitle"] = utf8ToLatin(d["ScreenTitle"]) d["Year"] = episode.Year d["Month"] = episode.Month d["Day"] = episode.Day d["Date"] = episode.getDate() d["Creation"] = episode.FileCreation d["Path"] = utf8ToLatin(episode.Path + "/" + episode.Filename + "." + episode.Extension) d["Season"] = episode.Season d["Episode"] = episode.Episode d["Plot"] = utf8ToLatin(episode.Plot) d["Runtime"] = episode.Runtime d["Popularity"] = episode.Popularity d["Genres"] = utf8ToLatin(episode.Genres).split("|") d["Resolution"] = utf8ToLatin(episode.Resolution) d["Sound"] = utf8ToLatin(episode.Sound) if self.manager.isMediaSeen(d["Id"], userId): image = seenPng d["Seen"] = "Seen" else: image = unseenPng d["Seen"] = "Unseen" d["ViewMode"] = "play" parsedLibrary.append((d["Title"], d, episode.Season * 1000 + episode.Episode, "50", image)) except Exception, ex: printl("Exception while loading library: " + str(ex), self, "E") printl("\tEntry: " + str(episode), self, "E")
def action(self, request): global Manager global utf8ToLatin global stringToUtf8 global MediaInfo if Manager is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.Manager import Manager if stringToUtf8 is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.Utf8 import stringToUtf8 if utf8ToLatin is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.Utf8 import utf8ToLatin if MediaInfo is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.MediaInfo import MediaInfo printl("request: " + str(request), self) printl("request.args: " + str(request.args), self) printl("request.args[mode]: " + str(request.args["mode"]), self) ########################## # ADD SECTION # Argument: request.args["mode"][0] == "addMediaToDb" # Subargument: request.args["type"][0] == "isMovie" | "isTvShow" | "isEpisode" # request.args["ParentId"][0] == Integer ########################## if request.args["mode"][0] == "addMediaToDb": printl("mode (addMediaToDb)", self, "I") manager = Manager("WebIf:SubActions:MediaActions") type = request.args["type"][0] if (type == "isEpisode"): parentId = request.args["ParentId"][0] key_value_dict = {} for key in request.args.keys(): key_value_dict[key] = request.args[key][0] # add movies if type == "isMovie": printl ("INSERT MOVIE : " + str(key_value_dict), self, "I") result = manager.insertMediaWithDict(Manager.MOVIES, key_value_dict) if result["status"] > 0: return WebHelper().redirectMeTo("/movies?mode=showDoneForm&showSave=true") else: return WebHelper().redirectMeTo("/mediaForm?mode=showErrorForm&type=isMovie&"+urlencode({'msg':result["message"]})) # add tvshows elif type == "isTvShow": printl ("INSERT TVSHOW : " + str(key_value_dict), self, "I") result = manager.insertMediaWithDict(Manager.TVSHOWS, key_value_dict) if result["status"] > 0: return WebHelper().redirectMeTo("/tvshows?mode=showDoneForm&showSave=true") else: return WebHelper().redirectMeTo("/mediaForm?mode=showErrorForm&type=isTvShow&"+urlencode({'msg':result["message"]})) # add tvshowepisodes elif type == "isEpisode": printl ("INSERT EPISODE: " + str(key_value_dict), self, "I") result = manager.insertMediaWithDict(Manager.TVSHOWSEPISODES, key_value_dict) if result["status"] > 0: return WebHelper().redirectMeTo("/episodes?mode=showDoneForm&ParentId=" + parentId + "&showSave=true") else: return WebHelper().redirectMeTo("/mediaForm?mode=showErrorForm&type=isEpisode&ParentId=" + parentId + "&"+urlencode({'msg':result["message"]})) ########################## # EDIT SECTION # Argument: request.args["mode"][0] == "alterMediaInDb" # Subargument: request.args["type"][0] == "isMovie" | "isTvShow" | "isEpisode" # request.args["Id"][0] == Integer # request.args["ParentId"][0] == Integer ########################## elif request.args["mode"][0] == "alterMediaInDb": printl("mode (alterMediaInDb)", self, "I") manager = Manager("WebIf:SubActions:MediaActions") type = stringToUtf8(request.args["type"][0]) Id = request.args["Id"][0] if (type == "isEpisode"): parentId = request.args["ParentId"][0] key_value_dict = {} for key in request.args.keys(): # key_value_dict[key] = stringToUtf8(request.args[key][0]) key_value_dict[key] = request.args[key][0] printl("Content: " + key + " => " + request.args[key][0], self, "I") if not "Seen" in request.args: WebData().getData("MediaInfo_markUnseen", Id) else: if (request.args["Seen"][0] == "on"): WebData().getData("MediaInfo_markSeen", Id) # edit movies if type == "isMovie": result = manager.updateMediaWithDict(Manager.MOVIES, key_value_dict) printl("alter Movie in Db", self, "I") if result is True: printl("TRUE", self, "I") return WebHelper().redirectMeTo("/movies?mode=showDoneForm&Id=" + Id + "&showSave=true") else: printl("FALSE", self, "I") return WebHelper().redirectMeTo("/mediaForm?mode=showErrorForm&type=isMovie&Id=" + Id) # edit tvshows elif type == "isTvShow": result = manager.updateMediaWithDict(Manager.TVSHOWS, key_value_dict) if result: return WebHelper().redirectMeTo("/tvshows?mode=showDoneForm&Id=" + Id + "&showSave=true") else: return WebHelper().redirectMeTo("/mediaForm?mode=showErrorForm&type=isTvShow&Id=" + Id) # edit tvsshowepisodes elif type == "isEpisode": result = manager.updateMediaWithDict(Manager.TVSHOWSEPISODES, key_value_dict) if result: return WebHelper().redirectMeTo("/episodes?mode=showDoneForm&Id=" + Id + "&ParentId=" + parentId + "&showSave=true") else: return WebHelper().redirectMeTo("/mediaForm?mode=showErrorForm&type=isEpisode&ParentId="+ parentId + "&Id=" + Id) ########################## # DELETE SECTION # Argument: request.args["mode"][0] == "deleteMediaFromDb" # Subargument: request.args["Id"][0] == Integer # request.args["ParentId"][0] == Integer # request.args["type"][0] == "isMovie" | "isTvShow" | "isEpisode" ########################## elif request.args["mode"][0] == "deleteMediaFromDb": printl("mode (deleteMediaFromDb)", self, "I") manager = Manager("WebIf:SubActions:MediaActions") id = request.args["Id"][0] type = request.args["type"][0] if (type == "isEpisode"): parentId = request.args["ParentId"][0] result = manager.deleteMedia(id) #delete movie if type == "isMovie": if result: return WebHelper().redirectMeTo("/movies?mode=showDoneForm&showSave=true") else: return WebHelper().redirectMeTo("/mediaForm?mode=showErrorForm&type=isMovie") # delete tvshowepisodes elif type == "isEpisode": if result: return WebHelper().redirectMeTo("/episodes?mode=showDoneForm&ParentId=" + parentId + "&showSave=true") else: return WebHelper().redirectMeTo("/mediaForm?mode=showErrorForm&tpye=isEpisode&ParentId=" + parentId) # delete tvshow elif type == "isTvShow": if result: return WebHelper().redirectMeTo("/tvshows?mode=showDoneForm&showSave=true") else: return WebHelper().redirectMeTo("/mediaForm?mode=showErrorForm&type=isTvShow") # delete failed elif type == "isFailed": if result: return WebHelper().redirectMeTo("/failed?showSave=true") else: return WebHelper().redirectMeTo("/mediaForm?mode=showErrorForm&type=isTvShow") ########################## # CHANGE ARTS SECTION # Argument: request.args["mode"][0] == "changeMediaArts" # Subargument: request.args["Id"][0] == Integer # request.args["type"][0] == "isMovie" | "isTvShow" | "isEpisode" # request.args["media_type"][0] == "poster" | "backdrop" # request.args["media_source"][0] == String ########################## elif request.args["mode"][0] == "changeMediaArts": printl("mode (changeMediaArts)", self, "I") manager = Manager("WebIf:SubActions:MediaActions") type = request.args["type"][0] media_source = request.args["media_source"][0] media_type = request.args["media_type"][0] Id = request.args["Id"][0] printl("media_source => " + media_source + ")", self, "I") if (media_source[0:7] != "user://"): if(media_source[0:7] == "http://" or media_source[0:8] == "https://" or media_source[0:1] == "/"): media_source = "user://" + media_source printl("media_source without user:// found => correcting to new value = " + media_source, self, "I") else: printl("media_source seems to have bad format at all - trying it anyway without warranty ;-)", self, "W") else: printl("media_source with user:// found => no changes needed", self, "I") #change movie art if type == "isMovie": t = Manager.MOVIES #change tvshow art elif type == "isTvShow": t = Manager.TVSHOWS #change episode art elif type == "isEpisode": t = Manager.TVSHOWSEPISODES else: return utf8ToLatin("error") if media_type == "poster": result = manager.changeMediaArts(t, Id, True, None, media_source) if result == True: return utf8ToLatin("success") else: return utf8ToLatin("error") elif media_type == "backdrop": result = manager.changeMediaArts(t, Id, True, media_source, None) if result == True: return utf8ToLatin("success") else: return utf8ToLatin("error") else: printl("no media type found", self) return utf8ToLatin("error") return utf8ToLatin("error") ########################## # SAVE TO DB # Argument: request.args["mode"][0] == "saveChangesToDb" ########################## elif request.args["mode"][0] == "saveChangesToDb": printl("mode (saveChangesToDb)", self, "I") manager = Manager("WebIf:SubActions:MediaActions") manager.finish() if request.args["return_to"][0] == "movies": return WebHelper().redirectMeTo("/movies") elif request.args["return_to"][0] == "tvshows": return WebHelper().redirectMeTo("/tvshows") elif request.args["return_to"][0] == "episodes": return WebHelper().redirectMeTo("/episodes") elif request.args["return_to"][0] == "failed": return WebHelper().redirectMeTo("/failed") ########################## # MOVE TO FAILED SECTION # Argument: request.args["mode"][0] == "moveToFailedSection" # Subargument: request.args["Id"][0] == Integer ########################## elif request.args["mode"][0] == "moveToFailedSection": manager = Manager("WebIf:SubActions:MediaActions") type = request.args["type"][0] Id = request.args["Id"][0] result = manager.moveToFailedSection(Id, type) if (type == "isEpisode"): parentId = request.args["ParentId"][0] #delete movie if type == "isMovie": if result: return WebHelper().redirectMeTo("/movies?mode=showDoneForm&showSave=true") else: return WebHelper().redirectMeTo("/mediaForm?mode=showErrorForm&type=isMovie") # delete tvshowepisodes elif type == "isEpisode": if result: return WebHelper().redirectMeTo("/episodes?mode=showDoneForm&ParentId=" + parentId + "&showSave=true") else: return WebHelper().redirectMeTo("/mediaForm?mode=showErrorForm&tpye=isEpisode&ParentId=" + parentId) # delete tvshow elif type == "isTvShow": if result: return WebHelper().redirectMeTo("/tvshows?mode=showDoneForm&showSave=true") else: return WebHelper().redirectMeTo("/mediaForm?mode=showErrorForm&type=isTvShow")
def action(self, request): global MediaInfo if MediaInfo is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.MediaInfo import MediaInfo global utf8ToLatin if utf8ToLatin is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.Utf8 import utf8ToLatin global Manager if Manager is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.Manager import Manager finalOutput = WebHelper().getHtmlCore("MediaInfo", True) Id = None ParentId = None imdbId = u"" theTvDbId = u"" currentMode = request.args["mode"][0] if "type" in request.args: type = request.args["type"][0] else: type = u"" ####################### # DONE MODE ####################### if currentMode == "showDoneForm": return finalOutput ####################### # GET MEDIA DETAILS FOR WEBIF ####################### elif currentMode == "getMediaDetails": Id = request.args["Id"][0] data = self._getMediaDetails(type, int(Id)) response = data.Path + "/" + data.Filename + "." + data.Extension return str(response) ####################### # ERROR MODE ###################### elif currentMode == "showErrorForm": return finalOutput ####################### # EDIT MODE ####################### elif currentMode == 'showEditForm': nextMode = "alterMediaInDb" finalOutput = finalOutput.replace("<!-- CUSTOM_TITLE -->", " - Edit Media") Id = request.args["Id"][0] m = self._getMediaDetails(type, int(Id)) ####################### # ADDBYIMDB MODE ####################### elif currentMode == 'showAddByImdbForm': fileData = None if "Id" in request.args: if request.args["Id"][0] == "": nextMode = "addMediaToDb" else: printl("ID => " + request.args["Id"][0], self, "D") nextMode = "alterMediaInDb" fileData = self._getMediaDetails( type, int(request.args["Id"][0])) else: nextMode = "addMediaToDb" finalOutput = finalOutput.replace("<!-- CUSTOM_TITLE -->", " - Add Media") m = MediaInfo() m.ImdbId = "" m.SearchString = "" if type == "isEpisode": type = "isSerie" # we need to do this because Manger.syncelemnts uses this name not the name till now isTvShow if fileData is not None: path = fileData.Path filename = fileData.Filename extension = fileData.Extension else: path = u"test" filename = u"test" extension = u"test" if type == "isMovie": m.ImdbId = request.args["ImdbId"][0] printl("showAddByImdbForm: " + str(request.args["ImdbId"][0]) + " " + str(type)) syncData = Manager("WebIf:SubActions:MediaForm").syncElement( path, filename, extension, m.ImdbId, False) m = syncData[0] if type == "isSerie": m.ImdbId = request.args["ImdbId"][0] printl("showAddByImdbForm: " + str(request.args["ImdbId"][0]) + " " + str(type)) syncData = Manager("WebIf:SubActions:MediaForm").syncElement( path, filename, extension, m.ImdbId, True) m = syncData[0] ####################### # ADDBYTITLE MODE ####################### elif currentMode == 'showAlternativesForm': nextMode = "showAddByImdbForm" finalOutput = finalOutput.replace("<!-- CUSTOM_TITLE -->", " - Add Media") mediainfo.SearchString = request.args["Title"][0] results = Manager("WebIf:SubActions:MediaForm").searchAlternatives( mediainfo) ####################### # MOVETOFAILED ####################### elif currentMode == 'moveToFailed': nextMode = "showAddByImdbForm" #hier sollte mehr stehen lol if "Id" in request.args: Id = request.args["Id"][0] else: Id = u"" if "ParentId" in request.args: ParentId = request.args["ParentId"][0] else: ParentId = u"" image = u"" backdrop = u"" mediaFolderPath = config.plugins.pvmc.mediafolderpath.value mediaForm = WebHelper().getHtmlForm("mediaForm") ####################### # ADD MODE ####################### if currentMode == "showManualAddForm": nextMode = "addMediaToDb" mediaForm = mediaForm % (type, nextMode, u"", ParentId, type, u"", u"", u"", u"", u"", u"", u"", u"", u"", u"", u"", u"", u"", u"", u"", u"", u"", 0) else: if type == "isMovie": if os.path.isfile(mediaFolderPath + m.ImdbId + "_poster_195x267.png"): image = """<img id="duck_img" src="%s" width="78" height="107" alt="n/a"></img>""" % ( "/media/" + str(m.ImdbId) + "_poster_195x267.png") else: image = """<img src=\"http://val.duckbox.info/convertImg2/poster/%s_195x267.png\" width="78" height="107" alt="n/a"></img>""" % ( str(m.ImdbId)) if os.path.isfile(mediaFolderPath + str(m.ImdbId) + "_backdrop_320x180.png"): backdrop = """<img id="duck_backdrop_img" src="%s" width="160" height="90" alt="n/a"></img>""" % ( "/media/" + str(m.ImdbId) + "_backdrop_320x180.png") else: backdrop = """<img src=\"http://val.duckbox.info/convertImg2/backdrop/%s_320x180.png\" width="160" height="90" alt="n/a">""" % ( str(m.ImdbId)) elif type == "isTvShow" or type == "isEpisode": if os.path.isfile(mediaFolderPath + str(m.TheTvDbId) + "_poster_195x267.png"): image = """<img id="duck_img" src="%s" width="78" height="107" alt="n/a"></img>""" % ( "/media/" + str(m.TheTvDbId) + "_poster_195x267.png") else: image = """<img src=\"http://val.duckbox.info/convertImg2/poster/%s_195x267.png\" width="78" height="107" alt="n/a"></img>""" % ( str(m.TheTvDbId)) if os.path.isfile(mediaFolderPath + str(m.TheTvDbId) + "_backdrop_320x180.png"): backdrop = """<img id="duck_backdrop_img" src="%s" width="160" height="90" alt="n/a"></img>""" % ( "/media/" + str(m.TheTvDbId) + "_backdrop_320x180.png") else: backdrop = """<img src=\"http://val.duckbox.info/convertImg2/backdrop/%s_320x180.png\" width="160" height="90" alt="n/a">""" % ( str(m.TheTvDbId)) seenCheck = "" if WebData().getData("MediaInfo_isSeen", m.Id): seenCheck = 'checked' printl("nextMode = " + nextMode, self, "W") if m.ParentId == None: m.ParentId = u"" mediaForm = mediaForm % ( type, nextMode, Id, m.ParentId, type, Id, m.ImdbId, m.TheTvDbId, m.Title, m.Tag, m.Season, m.Disc, m.Episode, m.EpisodeLast, m.Plot, m.Runtime, m.Year, m.Genres, self._getPopularity( m.Popularity), m.Path, m.Filename, m.Extension, seenCheck) finalOutput = finalOutput.replace("<!-- CUSTOM_IMAGE -->", image) finalOutput = finalOutput.replace("<!-- CUSTOM_BACKDROP -->", backdrop) finalOutput = finalOutput.replace("<!-- CUSTOM_FORM -->", mediaForm) return utf8ToLatin(finalOutput)
def getData(self, type, param=None): global Manager if Manager is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.Manager import Manager global ManagerInstance if ManagerInstance is None: ManagerInstance = Manager("WebIf:WebData") dataRows = [] printl("TYPE: " + type) if type == "movies": dataRows = ManagerInstance.getMoviesValues() elif type == "tvshows": dataRows = ManagerInstance.getSeriesValues() elif type == "episodes": if param != None: dataRows = ManagerInstance.getEpisodesWithTheTvDbId(param) else: dataRows = ManagerInstance.getEpisodes() elif type == "EpisodesOfSerie": dataRows = ManagerInstance.getEpisodes(param) elif type == "failed": dataRows = ManagerInstance.getFailedValues() elif type == "MediaInfo_isMovie": dataRows = ManagerInstance.getMedia(param) elif type == "MediaInfo_isTvShow": dataRows = ManagerInstance.getMedia(param) elif type == "MediaInfo_isEpisode": dataRows = ManagerInstance.getMedia(param) elif type == "MediaInfo_isFailed": dataRows = ManagerInstance.getMedia(param) elif type == "MediaInfo_isSeen": userId = config.plugins.pvmc.seenuserid.value dataRows = ManagerInstance.isMediaSeen(param, userId) elif type == "MediaInfo_markSeen": userId = config.plugins.pvmc.seenuserid.value dataRows = ManagerInstance.MarkAsSeen(param, userId) elif type == "MediaInfo_markUnseen": userId = config.plugins.pvmc.seenuserid.value dataRows = ManagerInstance.MarkAsUnseen(param, userId) elif type == "options.global": from Plugins.Extensions.ProjectValerie.__plugin__ import getPlugins, Plugin dataRows = [] plugins = getPlugins(where=Plugin.SETTINGS) for plugin in plugins: pluginSettingsList = plugin.fnc() for pluginSetting in pluginSettingsList: if len(plugin.name) > 0: text = "[%s] %s" % (plugin.name, pluginSetting[0], ) else: text = "%s" % (pluginSetting[0], ) dataRows.append((text, pluginSetting[1])) elif type == "options.sync": from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.PathsConfig import PathsConfig dataRows = PathsConfig().getInstance() return dataRows
class DMC_TvShowLibrary(DMC_Library): def __init__(self, session): global Manager if Manager is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.Manager import Manager self.manager = Manager("TVShows") DMC_Library.__init__(self, session, "tv shows") ### # Return Value is expected to be: # (libraryArray, onEnterPrimaryKeys, onLeavePrimaryKeys, onLeaveSelectEntry def loadLibrary(self, params, seenPng=None, unseenPng=None): global Manager global utf8ToLatin if utf8ToLatin is None: from Plugins.Extensions.ProjectValerie.DMC_Plugins.DMC_SyncExtras.Utf8 import utf8ToLatin printl("DEBUG 3", self) printl("", self) printl("params=" + str(params), self) userId = config.plugins.pvmc.seenuserid.value # Diplay all TVShows if params is None: printl("Series", self) parsedLibrary = [] library = self.manager.getSeriesValues() tmpAbc = [] tmpGenres = [] for tvshow in library: d = {} d["ArtBackdropId"] = utf8ToLatin(tvshow.TheTvDbId) d["ArtPosterId"] = d["ArtBackdropId"] d["Id"] = tvshow.Id d["ImdbId"] = utf8ToLatin(tvshow.ImdbId) d["TheTvDbId"] = utf8ToLatin(tvshow.TheTvDbId) d["Title"] = " " + utf8ToLatin(tvshow.Title) if d["Title"][2].upper() not in tmpAbc: tmpAbc.append(d["Title"][2].upper()) d["Tag"] = utf8ToLatin(tvshow.Tag) d["Year"] = tvshow.Year d["Month"] = tvshow.Month d["Day"] = tvshow.Day d["Plot"] = utf8ToLatin(tvshow.Plot) d["Runtime"] = tvshow.Runtime d["Popularity"] = tvshow.Popularity d["Genres"] = utf8ToLatin(tvshow.Genres).split("|") for genre in d["Genres"]: if genre not in tmpGenres: tmpGenres.append(genre) if config.plugins.pvmc.showseenforshow.value is True: #if self.manager.is_Seen({"TheTvDbId": d["TheTvDbId"]}): if self.manager.isMediaSeen(d["Id"], userId): image = seenPng else: image = unseenPng else: image = None d["ScreenTitle"] = d["Title"] d["ScreenTitle"] = utf8ToLatin(d["ScreenTitle"]) d["ViewMode"] = "ShowSeasons" parsedLibrary.append((d["Title"], d, d["Title"].lower(), "50", image)) sort = (("Title", None, False), ("Popularity", "Popularity", True), ) filter = [("All", (None, False), ("", )), ] if len(tmpGenres) > 0: tmpGenres.sort() filter.append(("Genre", ("Genres", True), tmpGenres)) if len(tmpAbc) > 0: tmpAbc.sort() filter.append(("Abc", ("Title", False, 1), tmpAbc)) return ( parsedLibrary, #listViewList ("ViewMode", "Id", ), #onEnterPrimaryKeys None, #onLeavePrimaryKeyValuePair None, #onLeaveSelectKeyValuePair sort, #onSortKeyValuePair filter, #onFilterKeyValuePair ) # Display the Seasons Menu elif params["ViewMode"]=="ShowSeasons": printl("Seasons", self) parsedLibrary = [] tvshow = self.manager.getMedia(params["Id"]) d = {} d["ArtBackdropId"] = utf8ToLatin(tvshow.TheTvDbId) d["Id"] = tvshow.Id d["ImdbId"] = utf8ToLatin(tvshow.ImdbId) d["TheTvDbId"] = utf8ToLatin(tvshow.TheTvDbId) d["Tag"] = utf8ToLatin(tvshow.Tag) d["Year"] = tvshow.Year d["Month"] = tvshow.Month d["Day"] = tvshow.Day d["Plot"] = utf8ToLatin(tvshow.Plot) d["Runtime"] = tvshow.Runtime d["Popularity"] = tvshow.Popularity d["Genres"] = utf8ToLatin(tvshow.Genres).split("|") library = self.manager.getEpisodes(params["Id"]) seasons = [] for entry in library: season = entry.Season if season not in seasons: seasons.append(season) s = d.copy() if entry.Season is None: s["Title"] = " Special" s["Season"] = "" # for retrive data only with season=None else: s["Title"] = " Season %2d" % (season, ) s["Season"] = season s["ScreenTitle"] = tvshow.Title + " - " + s["Title"].strip() s["ScreenTitle"] = utf8ToLatin(s["ScreenTitle"]) s["ArtPosterId"] = d["ArtBackdropId"] + "_s" + str(season) if config.plugins.pvmc.showseenforseason.value is True: if self.manager.isMediaSeen(d["Id"], s["Season"], userId): image = seenPng else: image = unseenPng else: image = None s["ViewMode"] = "ShowEpisodes" parsedLibrary.append((s["Title"], s, season, "50", image)) sort = (("Title", None, False), ) filter = [("All", (None, False), ("", )), ] return (parsedLibrary, ("ViewMode", "Id", "Season", ), None, params, sort, filter) # (libraryArray, onEnterPrimaryKeys, onLeavePrimaryKeys, onLeaveSelectEntry # Display the Episodes Menu elif params["ViewMode"]=="ShowEpisodes": printl("EpisodesOfSeason", self) parsedLibrary = [] tvshow = self.manager.getMedia(params["Id"]) library = self.manager.getEpisodes(params["Id"], params["Season"]) for episode in library: try: d = {} d["ArtBackdropId"] = utf8ToLatin(tvshow.TheTvDbId) d["ArtPosterId"] = d["ArtBackdropId"] d["Id"] = episode.Id d["TVShowId"] = tvshow.Id d["ImdbId"] = utf8ToLatin(tvshow.ImdbId) d["TheTvDbId"] = utf8ToLatin(episode.TheTvDbId) d["Tag"] = utf8ToLatin(tvshow.Tag) #d["Title"] = " %dx%02d: %s" % (episode.Season, episode.Episode, utf8ToLatin(episode.Title), ) if episode.Season is None and episode.Disc is None and episode.Episode is not None: # # Only Episode d["Title"] = " %s: %s" % (episode.Episode, utf8ToLatin(episode.Title), ) elif episode.Season is None and episode.Disc is not None and episode.Episode is None: # Only Disc d["Title"] = " Disc %s: %s" % (episode.Disc, utf8ToLatin(episode.Title), ) elif episode.Season is not None and episode.Disc is None and episode.Episode is not None and episode.EpisodeLast is not None: # # Without Disc, With Episode And EpisodeLast d["Title"] = " %02d-%02d: %s" % (episode.Episode, episode.EpisodeLast, utf8ToLatin(episode.Title), ) elif episode.Season is not None and episode.Disc is None and episode.Episode is not None: # # Without Disc, With Episode d["Title"] = " %02d: %s" % (episode.Episode, utf8ToLatin(episode.Title), ) elif episode.Season is not None and episode.Disc is not None and episode.Episode is not None and episode.EpisodeLast is not None: # # With Disc, With Episode And EpisodeLast d["Title"] = " D%sE%s-E%s: %s" % (episode.Disc, episode.Episode, episode.EpisodeLast, utf8ToLatin(episode.Title) ) elif episode.Season is not None and episode.Disc is not None and episode.Episode is not None and episode.EpisodeLast is None: # # With Disc, Without EpisodeLast d["Title"] = " D%sE%s: %s" % (episode.Disc, episode.Episode, utf8ToLatin(episode.Title), ) elif episode.Season is not None and episode.Disc is not None and episode.Episode is None: # # With Disc, Without Episode d["Title"] = " Disc %s: %s" % (episode.Disc, utf8ToLatin(episode.Title), ) else: d["Title"] = " %s" % (utf8ToLatin(episode.Title), ) if episode.Season is None: d["ScreenTitle"] = tvshow.Title + " - " + "Special" else: d["ScreenTitle"] = tvshow.Title + " - " + "Season %2d" % (episode.Season, ) d["ScreenTitle"] = utf8ToLatin(d["ScreenTitle"]) d["Year"] = episode.Year d["Month"] = episode.Month d["Day"] = episode.Day d["Path"] = utf8ToLatin(episode.Path + "/" + episode.Filename + "." + episode.Extension) d["Creation"] = episode.FileCreation d["Season"] = episode.Season d["Episode"] = episode.Episode d["Plot"] = utf8ToLatin(episode.Plot) d["Runtime"] = episode.Runtime d["Popularity"] = episode.Popularity d["Genres"] = utf8ToLatin(episode.Genres).split("|") d["Resolution"] = utf8ToLatin(episode.Resolution) d["Sound"] = utf8ToLatin(episode.Sound) if self.manager.isMediaSeen(d["Id"], userId): image = seenPng d["Seen"] = "Seen" else: image = unseenPng d["Seen"] = "Unseen" d["ViewMode"] = "play" _season = episode.Season if _season is None: _season=0 _disc = episode.Disc if _disc is None: _disc=0 _episode = episode.Episode if _episode is None: _episode=0 printl("DISC: " + repr(_disc), self) _season = int(_season) _disc = int(_disc) _episode = int(_episode) parsedLibrary.append((d["Title"], d, _season * 100000 + _disc * 1000 + _episode, "50", image)) except Exception, ex: printl("Exception: " + str(ex), self, "E") printl("episode: " + str(episode), self, "E") sort = [("Title", None, False), ("Popularity", "Popularity", True), ] if self.checkFileCreationDate: sort.append(("File Creation", "Creation", True)) filter = [("All", (None, False), ("", )), ] filter.append(("Seen", ("Seen", False, 1), ("Seen", "Unseen", ))) return (parsedLibrary, ("ViewMode", "Id", "TVShowId", "Season", "Episode", ), \ dict({'ViewMode': "ShowSeasons", 'Id': params["Id"],}), \ params, sort, filter) # (libraryArray, onEnterPrimaryKeys, onLeavePrimaryKeys, onLeaveSelectEntry return None