def ffmpeg_process(name, trim, dev, da, dv, pix_th, au_db): """Simple manual test for ffmpeg_process with knobs to turn.""" click.echo( find_offset_ffmpeg(name, trim=trim, dev=dev, duration_audio=da, duration_video=dv, pix_th=pix_th, au_db=au_db))
def task(item, sessionkey): """Main func for processing a episode. Args: item(str): a episode's ratingkey sessionkey(str): streams sessionkey Returns: None """ global HT media = PMS.fetchItem(int(item)) # LOG.debug('Found %s', media._prettyfilename()) if media.TYPE not in ('episode', 'show'): return theme = get_theme(media) LOG.debug('task theme %s', theme) LOG.debug('Download the first 10 minutes of %s as .wav', media._prettyfilename()) vid = convert_and_trim(check_file_access(media), fs=11025, trim=600) # Check if this shows theme exist in the hash table. # We should prop just check if x in HT.names try: HT.name_to_id(theme) except ValueError: LOG.debug('No fingerprint for theme %s does exists in the %s', os.path.basename(theme), FP_HASHES) analyzer().ingest(HT, theme) #HT = HT.save_then_reload(FP_HASHES) start, end = get_offset_end(vid, HT) ffmpeg_end = find_offset_ffmpeg(check_file_access(media)) if end != -1 or ffmpeg_end != 1: # End is -1 if not found. Or a positiv int. process_to_db(media, theme=theme, vid=vid, start=start, end=end, ffmpeg_end=ffmpeg_end) try: os.remove(vid) LOG.debug('Deleted %s', vid) except IOError: LOG.excetion('Failed to delete %s', vid) nxt = find_next(media) if nxt: process_to_db(nxt) try: IN_PROG.remove(item) except ValueError: LOG.debug('Failed to remove %s from IN_PROG', item)
def process_to_db(media, theme=None, vid=None, start=None, end=None, ffmpeg_end=None, recap=None): """Process a plex media item to the db Args: media (Episode obj): theme: path to the theme. vid: path to the stripped wav of the media item. start (None, int): of theme. end (None, int): of theme. ffmpeg_end (None, int): What does ffmpeg think is the start of the ep. Returns: None """ global HT ff = -1 name = media._prettyfilename() LOG.debug('Started to process %s', name) if theme is None: theme = get_theme(media) theme = convert_and_trim(theme, fs=11025, theme=True) if vid is None: vid = convert_and_trim(check_file_access(media), fs=11025, trim=600) # too cover manual process_to_db. if theme not in HT.names: analyzer().ingest(HT, theme) # Lets skip the start time for now. This need to be added later to support shows # that have show, theme song show. if end is None: start, end = get_offset_end(vid, HT) if ffmpeg_end is None: ffmpeg_end = find_offset_ffmpeg(check_file_access(media)) if recap is None: recap = has_recap(media, CONFIG.get('words'), audio=vid) if end is not None: with session_scope() as se: try: se.query(Preprocessed).filter_by(ratingKey=media.ratingKey).one() except NoResultFound: p = Preprocessed(show_name=media.grandparentTitle, ep_title=media.title, theme_end=end, theme_start=start, theme_start_str=to_time(start), theme_end_str=to_time(end), ffmpeg_end=ffmpeg_end, ffmpeg_end_str=to_time(ff), duration=media.duration, ratingKey=media.ratingKey, grandparentRatingKey=media.grandparentRatingKey, prettyname=media._prettyfilename(), updatedAt=media.updatedAt, has_recap=recap) se.add(p) LOG.debug('Added %s to media.db', name)
def process_to_db(media, theme=None, vid=None, start=None, end=None, ffmpeg_end=None, recap=None, credits_start=None, credits_end=None): """Process a plex media item to the db Args: media (Episode obj): theme: path to the theme. vid: path to the stripped wav of the media item. start (None, int): of theme. end (None, int): of theme. ffmpeg_end (None, int): What does ffmpeg think is the start of the ep. recap(None, bool): If this how has a recap or not credits_start(None, int): The offset (in sec) the credits text starts credits_end(None, int): The offset (in sec) the credits text ends Returns: None """ global HT # Disable for now. # if media.TYPE == 'movie': # return # This will download the theme and add it to # the hashtable if its missing if media.TYPE == 'episode' and theme is None: if HT.has_theme(media, add_if_missing=False) is False: LOG.debug('downloading theme from process_to_db') theme = download_theme(media, HT) name = media._prettyfilename() LOG.debug('Started to process %s', name) if vid is None and media.TYPE == 'episode': vid = convert_and_trim(check_file_access(media), fs=11025, trim=CONFIG['tv'].get('check_for_theme_sec', 600)) # Find the start and the end of the theme in the episode file. if end is None and media.TYPE == 'episode': start, end = get_offset_end(vid, HT) # Guess when the intro ended using blackframes and audio silence. if ffmpeg_end is None: if media.TYPE == 'episode': trim = CONFIG['tv'].get('check_intro_ffmpeg_sec') else: trim = CONFIG['movie'].get('check_intro_ffmpeg_sec') ffmpeg_end = find_offset_ffmpeg(check_file_access(media), trim=trim) # Check for recap. if recap is None: recap = has_recap(media, CONFIG['tv'].get('words', []), audio=vid) if (media.TYPE == 'episode' and CONFIG['tv'].get('check_credits') is True and credits_start is None and credits_end is None): dur = media.duration / 1000 - CONFIG['tv'].get('check_credits_sec', 120) credits_start, credits_end = find_credits(check_file_access(media), offset=dur, check=-1) elif (media.TYPE == 'movie' and CONFIG['movie'].get('check_credits') is True and credits_start is None and credits_end is None): dur = media.duration / 1000 - CONFIG['movie'].get( 'check_credits_sec', 600) credits_start, credits_end = find_credits(check_file_access(media), offset=dur, check=-1) else: # We dont want to find the credits. credits_start = -1 credits_end = -1 # We assume this is kinda right, # double check this # TODO location = list(i.file for i in media.iterParts() if i)[0] with session_scope() as se: try: se.query(Processed).filter_by(ratingKey=media.ratingKey).one() except NoResultFound: if media.TYPE == 'episode': p = Processed(show_name=media.grandparentTitle, title=media.title, type=media.TYPE, theme_end=end, theme_start=start, theme_start_str=to_time(start), theme_end_str=to_time(end), ffmpeg_end=ffmpeg_end, ffmpeg_end_str=to_time(ffmpeg_end), credits_start=credits_start, credits_start_str=to_time(credits_start), credits_end=credits_end, credits_end_str=to_time(credits_end), duration=media.duration, ratingKey=media.ratingKey, grandparentRatingKey=media.grandparentRatingKey, prettyname=media._prettyfilename(), updatedAt=media.updatedAt, has_recap=recap, location=location) elif media.TYPE == 'movie': p = Processed(title=media.title, type=media.TYPE, ffmpeg_end=ffmpeg_end, ffmpeg_end_str=to_time(ffmpeg_end), credits_start=credits_start, credits_start_str=to_time(credits_start), credits_end=credits_end, credits_end_str=to_time(credits_end), duration=media.duration, ratingKey=media.ratingKey, prettyname=media._prettyfilename(), updatedAt=media.updatedAt, location=location) se.add(p) LOG.debug('Added %s to media.db', name) if media.TYPE == 'movie' and CONFIG['movie']['create_edl']: edl.write_edl( location, edl.db_to_edl(p, type=CONFIG['movie']['edl_action_type'])) elif media.TYPE == 'episode' and CONFIG['tv']['create_edl']: edl.write_edl( location, edl.db_to_edl(p, type=CONFIG['tv']['edl_action_type']))
def process_to_db(media, theme=None, vid=None, start=None, end=None, ffmpeg_end=None, recap=None): """Process a plex media item to the db Args: media (Episode obj): theme: path to the theme. vid: path to the stripped wav of the media item. start (None, int): of theme. end (None, int): of theme. ffmpeg_end (None, int): What does ffmpeg think is the start of the ep. Returns: None """ global HT # This will download the theme and add it to # the hashtable if its missing if theme is None: if HT.has_theme(media, add_if_missing=False) is False: LOG.debug('downloading theme from process_to_db') theme = download_theme(media, HT) ff = -1 name = media._prettyfilename() LOG.debug('Started to process %s', name) if vid is None: vid = convert_and_trim(check_file_access(media), fs=11025, trim=600) # Find the start and the end of the theme in the video file. if end is None: start, end = get_offset_end(vid, HT) # Guess when the intro ended using blackframes and audio silence. if ffmpeg_end is None: ffmpeg_end = find_offset_ffmpeg(check_file_access(media)) # Check for recap. if recap is None: recap = has_recap(media, CONFIG.get('words', []), audio=vid) with session_scope() as se: try: se.query(Preprocessed).filter_by(ratingKey=media.ratingKey).one() except NoResultFound: p = Preprocessed(show_name=media.grandparentTitle, ep_title=media.title, theme_end=end, theme_start=start, theme_start_str=to_time(start), theme_end_str=to_time(end), ffmpeg_end=ffmpeg_end, ffmpeg_end_str=to_time(ffmpeg_end), duration=media.duration, ratingKey=media.ratingKey, grandparentRatingKey=media.grandparentRatingKey, prettyname=media._prettyfilename(), updatedAt=media.updatedAt, has_recap=recap) se.add(p) LOG.debug('Added %s to media.db', name)