def match(f): """Manual match for a file. This is usefull for testing the a finds the correct end time.""" # assert f in H.names global HT HT = get_hashtable() x = get_offset_end(f, HT) click.echo(x)
def match(f): # pragma: no cover """Manual match for a file. This is useful for testing we finds the correct start and end time.""" global HT HT = get_hashtable() x = get_offset_end(f, HT) click.echo(x)
def add_theme_to_hashtable(threads, directory): """ Create a hashtable from the themes. Args: theads (int): How many threads to use. directory (None, str): If you don't pass a directory will select the default one Returns: None """ from bw_plex.audfprint.audfprint import multiproc_add global HT HT = get_hashtable() a = analyzer() all_files = [] for root, _, files in os.walk(directory or THEMES): for f in files: fp = os.path.join(root, f) # We need to check this since when themes are downloaded # They sometimes get a 0b files. if os.path.exists(fp) and os.path.getsize(fp): all_files.append(fp) def report(s): # this shitty reporter they want sucks balls.. pass #print(s) LOG.debug('Creating hashtable, this might take a while..') multiproc_add(a, HT, iter(all_files), report, threads) if HT and HT.dirty: HT.save(FP_HASHES)
def manually_correct_theme(name, url, type, rk, just_theme, remove_old_theme): # pragma: no cover """Set the correct fingerprint of the show in the hashes.db and process the eps of that show in the db against the new theme fingerprint. Args: name (str): name of the show url (str): the youtube/tvtunes url or filepath to the correct theme. type (str): What source to use for themes. rk (str): ratingkey of that show. Pass auto if your lazy. just_theme (bool): just add the theme song not reprocess stuff. remove_old_theme (bool): Removes all the old themes of this show Returns: None """ global HT HT = get_hashtable() # Assist for the lazy bastards.. if rk == 'auto': items = PMS.search(name) items = [i for i in items if i and i.TYPE == 'show'] items = choose('Select correct show', items, lambda x: '%s %s' % (x.title, x.TYPE)) if items: rk = items[0].ratingKey if remove_old_theme: themes = HT.get_theme(items[0]) for th in themes: LOG.debug('Removing %s from the hashtable', th) HT.remove(th) # Download the themes depending on the manual option or config file. download_theme(items[0], HT, theme_source=type, url=url) to_pp = [] if just_theme: return if rk: with session_scope() as se: # Find all episodes of this show. item = se.query(Processed).filter_by(grandparentRatingKey=rk) for i in item: to_pp.append(PMS.fetchItem(i.ratingKey)) # Prob should have used edit, but we do this so we can use process_to_db. se.delete(i) for media in to_pp: process_to_db(media)
def manually_correct_theme(name, url, type, rk, just_theme): """Set the correct fingerprint of the show in the hashes.db and process the eps of that show in the db against the new theme fingerprint. Args: name (str): name of the show url (str): the youtube url to the correct theme. rk (str): ratingkey of that show. Pass auto if your lazy. just_theme (bool): just add the theme song. Returns: None """ global HT HT = get_hashtable() # Assist for the lazy bastards.. if rk == 'auto': items = PMS.search(name) items = [i for i in items if i and i.TYPE == 'show'] items = choose('Select correct show', items, lambda x: '%s %s' % (x.title, x.TYPE)) if items: rk = items[0].ratingKey # I dont think think themes be removed anymore as one show can now have several themes # also it dont remove the files in THEMES, this is intended!. themes = HT.get_theme(items[0]) for th in themes: LOG.debug('Removing %s from the hashtable', th) HT.remove(th) # Download the themes depending on the manual option or config file. theme_path = download_theme(items[0], HT, theme_source=type, url=url) to_pp = [] # THis should be removed, if you just want to download the theme. use find theme. if just_theme: return if rk: with session_scope() as se: # Find all episodes of this show. item = se.query(Preprocessed).filter_by(grandparentRatingKey=rk) for i in item: to_pp.append(PMS.fetchItem(i.ratingKey)) # Prob should have edit, but we do this so we can use process_to_db. se.delete(i) for media in to_pp: process_to_db(media)
def watch(): # # pragma: no cover """Start watching the server for stuff to do.""" global HT HT = get_hashtable() click.echo('Watching for media on %s' % PMS.friendlyName) ffs = PMS.startAlertListener(check) try: while True: time.sleep(0.2) except KeyboardInterrupt: click.echo('Aborting') ffs.stop() POOL.terminate()
def manually_correct_theme(name, url, type, rk, just_theme): """Set the correct fingerprint of the show in the hashes.db and process the eps of that show in the db against the new theme fingerprint. Args: name (str): name of the show url (str): the youtube url to the correct theme. rk (str): ratingkey of that show. Pass auto if your lazy. just_theme (bool): just add the theme song. Returns: None """ global HT HT = get_hashtable() # Assist for the lazy bastards.. if rk == 'auto': item = PMS.search(name) item = choose('Select correct show', item, lambda x: '%s %s' % (x.title, x.TYPE)) if item: rk = item[0].ratingKey theme_path = search_for_theme_youtube(name, rk=rk, url=url, save_path=THEMES) for fp in HT.names: if os.path.basename(fp).lower() == name.lower() and os.path.exists(fp): LOG.debug('Removing %s from the hashtable', fp) HT.remove(fp) analyzer().ingest(HT, theme_path) # HT.save(FP_HASHES) to_pp = [] if just_theme: return if rk: with session_scope() as se: item = se.query(Preprocessed).filter_by(grandparentRatingKey=rk) for i in item: to_pp.append(PMS.fetchItem(i.ratingKey)) # Prob should have edit, but we do this so we can use process_to_db. se.delete(i) for media in to_pp: process_to_db(media)
def process(name, sample, threads, skip_done): """Manual process some/all eps. You will asked for what you want to process Args: name (None): Pass a name of a show you want to process sample (int): process x eps for all shows. threads (int): How many thread to use skip_done(bool): Should we skip stuff that is processed. Return: None """ global HT global SHOWS all_eps = [] if name: load_themes() shows = find_all_shows() shows = [s for s in shows if s.title.lower().startswith(name.lower())] shows = choose('Select what show to process', shows, 'title') for show in shows: eps = show.episodes() eps = choose('Select episodes', eps, lambda x: '%s %s' % (x._prettyfilename(), x.title)) all_eps += eps if sample: def lol(i): x = i.episodes()[:sample] return all_eps.extend(x) find_all_shows(lol) if skip_done: # Now there must be a better way.. with session_scope() as se: items = se.query(Preprocessed).all() for item in items: for ep in all_eps: if ep.ratingKey == item.ratingKey: click.secho('Removing as %s already is processed' % item.prettyname, fg='red') all_eps.remove(ep) HT = get_hashtable() def prot(item): try: process_to_db(item) except Exception as e: logging.error(e, exc_info=True) if all_eps: p = Pool(threads) # process_to_db craps out because off a race condition in get_theme(media) # if the user is selecting n eps > 1 for the same theme. # Lets just download the the themes first so the shit is actually processed. gr = set([i.grandparentRatingKey for i in all_eps]) - SHOWS.keys() LOG.debug('Downloading theme for %s shows this might take a while..', len(gr)) if len(gr): sh = p.map(PMS.fetchItem, gr) try: p.map(search_for_theme_youtube, [(s.title, s. ratingKey, THEMES) for s in sh]) except KeyboardInterrupt: pass try: load_themes() p.map(prot, all_eps) except KeyboardInterrupt: p.terminate()
def process(name, sample, threads, skip_done): """Manual process some/all eps. You will asked for what you want to process Args: name (None): Pass a name of a show you want to process sample (int): process x eps for all shows. threads (int): How many thread to use skip_done(bool): Should we skip stuff that is processed. Return: None """ global HT all_items = [] if name: medias = find_all_movies_shows() medias = [ s for s in medias if s.title.lower().startswith(name.lower()) ] medias = choose('Select what item to process', medias, 'title') for media in medias: if media.TYPE == 'show': eps = media.episodes() eps = choose( 'Select episodes', eps, lambda x: '%s %s' % (x._prettyfilename(), x.title)) all_items += eps else: all_items.append(media) if sample: def lol(i): if i.TYPE == 'show': x = i.episodes()[:sample] return all_items.extend(x) else: return all_items.append(i) find_all_movies_shows(lol) if skip_done: # Now there must be a better way.. with session_scope() as se: items = se.query(Processed).all() for item in items: for ep in all_items: if ep.ratingKey == item.ratingKey: click.secho( "Removing %s at it's already is processed" % item.prettyname, fg='red') all_items.remove(ep) HT = get_hashtable() def prot(item): try: process_to_db(item) except Exception as e: logging.error(e, exc_info=True) if all_items: p = Pool(threads) # Download all the themes first, skip the ones that we already have.. gr = set([ i.grandparentRatingKey for i in all_items if i.TYPE == 'episode' ]) - set(HT.get_themes().keys()) LOG.debug('Downloading theme for %s shows this might take a while..', len(gr)) if len(gr): sh = p.map(PMS.fetchItem, gr) try: p.map(HT.has_theme, sh) except KeyboardInterrupt: pass try: p.map(prot, all_items) except KeyboardInterrupt: p.terminate()
def HT(): return misc.get_hashtable()