def markSeen(cmd, args): episode = db.store.find(series_list.Episode, series_list.Episode.id == args["id"]).one() if episode is not None: episode.status = series_list.EP_SEEN db.store.commit() viewmgr.episode_updated(episode) # auto archive all the files that the collection function finds to be # placed under the current episode season number small convenience for # the user instead of manually archiving them if len(episode.season) > 3: series = db.store.find( series_list.Series, series_list.Series.id == episode.series_id).one() if series is not None and series.folder != '' and appcfg.options[ appcfg.CFG_SERIES_PATH] != '': sfiles = db_conv_xml._collectEpisodeFiles( series_list.get_series_path(series)) if episode.season in sfiles: for epobj in sfiles[episode.season]: errstr = _archiveFile(epobj.filepath) if errstr is not None: cmd.html = errstr return cmd.redirect = _getBaseURL("series?cmd_get_series=%i" % episode.series_id) cmd.html = ''
def markSeen(cmd, args): episode = db.store.find(series_list.Episode, series_list.Episode.id == args["id"]).one() if episode is not None: episode.status = series_list.EP_SEEN db.store.commit() viewmgr.episode_updated(episode) # auto archive all the files that the collection function finds to be # placed under the current episode season number small convenience for # the user instead of manually archiving them if len(episode.season) > 3: series = db.store.find(series_list.Series, series_list.Series.id == episode.series_id).one() if series is not None and series.folder != '' and appcfg.options[appcfg.CFG_SERIES_PATH] != '': sfiles = db_conv_xml._collectEpisodeFiles(series_list.get_series_path(series)) if episode.season in sfiles: for epobj in sfiles[episode.season]: errstr = _archiveFile(epobj.filepath) if errstr is not None: cmd.html = errstr return cmd.redirect = _getBaseURL("series?cmd_get_series=%i" % episode.series_id) cmd.html = ''
def get_series_xml(): """ This function returns an XML structure that contains all the series that are currently in airs, with all properties needed for XSLT -> HTML """ dom = libxml2.newDoc("1.0") root = libxml2.newNode("airs") dom.addChild(root) options = _createOptionsNode() root.addChild(options) items = libxml2.newNode("series") root.addChild(items) todaystr = series_list.date_to_str(datetime.datetime.now()) wdelta = series_list.idx_to_weekdelta(appcfg.options[appcfg.CFG_EPISODE_DELTA]) bottomstr = series_list.date_to_str(datetime.date.today() - datetime.timedelta(weeks = wdelta)) c = db.store.execute("select count(*) from episode where aired != '' and aired <= '%s'" "and aired > '%s' and new != 0" % (todaystr, bottomstr) ) items.setProp("airedcount", str(c.get_one()[0])) result = db.store.find(series_list.Series).order_by(series_list.Series.name) series = [serie for serie in result] for item in series: serie = libxml2.newNode("item") serie.setProp("name", item.name) serie.setProp("id", str(item.id)) serie.setProp("cancelled", str(item.postponed)) serie.setProp("folder", item.folder) seriespath = series_list.get_series_path(item) serie.setProp("mediacount", str(_getMediaCount(seriespath))) # report total number of episodes and the # episodes already seen c = db.store.execute("select count(*) from episode where series_id = %i and aired != '' and aired < '%s'" % \ (item.id, todaystr) ) totalcount = str(c.get_one()[0]) c = db.store.execute("select count(*) from episode where series_id = %i and status = %i" % \ (item.id, series_list.EP_SEEN)) seencount = str(c.get_one()[0]) #c = db.store.execute("select count(*) from episode where series_id = %i and status = 4" % item.id) #seencount = str(c.get_one()[0]) serie.setProp("seencount", seencount) serie.setProp("count", totalcount) items.addChild(serie) return dom
def _collectEpisodesByID(series, episode_list): """ Function that collects per episode ID all files that match this episode. This function uses _collectEpisodeFiles to auto match the season strings, and further processes all unknown episodes to do fuzzy matching on title and file name parts """ ep_to_file = dict() sfiles = _collectEpisodeFiles(series_list.get_series_path(series)) bad_series_words = set([s.lower() for s in series.name.split()]) ablookup = list() if "_" in sfiles: # pre process and make lookup mediaext_set = set(_media_extensions) for abitem in sfiles["_"]: orgfile_set = set([ s.lower() for s in m0.findall(abitem.filename) ]) orgfile_set = orgfile_set - mediaext_set - bad_words - bad_series_words ablookup.append( (EpisodeFileFuzzyMatch(abitem), orgfile_set) ) for episode in episode_list: seasonstr = episode.season.upper() if len(seasonstr) > 2: if seasonstr in sfiles: ep_to_file[episode.id] = [efile for efile in sfiles[seasonstr]] if appcfg.options[appcfg.CFG_FUZZY_MATCH]: # now check episode title with any sets title_set = set([ s.lower() for s in m0.findall(episode.title) ]) if len(title_set) > 0: for fuzzy_info, file_set in ablookup: if len(file_set) > 0: score = 1 - len(title_set - file_set) / float(len(title_set)) if score >= DIFF_THRESHOLD: if (fuzzy_info.candidate_id == -1) or score > fuzzy_info.diff_score: fuzzy_info.candidate_id = episode.id fuzzy_info.diff_score = score # now let's feed the episode info from the ablookup into the lookup list of # episodes. This will also group all permanently abandoned files in the # category -1. abandoned = list() for fuzzy_info, dummy in ablookup: epid = fuzzy_info.candidate_id epfile = fuzzy_info.epfile if epid != -1: if epid in ep_to_file: ep_to_file[epid].append(epfile) else: ep_to_file[epid] = [ epfile ] else: abandoned.append(epfile) ep_to_file[-1] = abandoned return ep_to_file