def Scan(path, files, mediaList, subdirs): # Scan for video files. VideoFiles.Scan(path, files, mediaList, subdirs) # Take top two as show/season, but require at least the top one. paths = Utils.SplitPath(path) if len(paths) > 0 and len(paths[0]) > 0: done = False if done == False: (title, year) = VideoFiles.CleanName(paths[0]) for i in files: done = False is_movie = False file = os.path.basename(i) (file, ext) = os.path.splitext(file) # See if there's a pytivo metadata file to peek at meta = dict() metadata_filename = '{0}.txt'.format(i.replace('_LQ', '')) if os.path.isfile(metadata_filename): with open(metadata_filename, 'r') as f: for line in f: line = line.strip() if line and len(line): line_a = line.split(' : ') if len(line_a) > 1: key, value = line.split(' : ') meta[key] = value #print "pytivo metadata, ", meta # Skip tv shows based on pytivo metadata file and backup to filename if not present if 'isEpisode' in meta: if meta['isEpisode'] == 'false': is_movie = True elif file.strip().startswith('(Rec'): is_movie = True # If we still think it is not a movie then skip it if is_movie == False: print "File {0} is determined to be a tv show by pytivo metadata file, skipping".format(file) continue if 'title' in meta: title = meta['title'] if 'movieYear' in meta: year = meta['movieYear'] # Create the movie movie = Media.Movie(title, year) movie.source = VideoFiles.RetrieveSource(i) movie.parts.append(i) mediaList.append(movie)
def Scan(path, files, mediaList, subdirs, language=None, root=None): # Just look for video files. VideoFiles.Scan(path, files, mediaList, subdirs, root) # Add them all. for path in files: (show, year) = VideoFiles.CleanName(os.path.basename(path)) file = Utils.SplitPath(path)[-1] ext = file.split('.')[-1] name = '.'.join(file.split('.')[0:-1]) nameChunks = name.split(' - ') for i, chunk in enumerate(nameChunks): if parseEpisode(chunk): nameChunks = [ ' - '.join(nameChunks[:i]), nameChunks[i], ' - '.join(nameChunks[i + 1:]) ] break # correct for "-" in show name or title if len(nameChunks) > 4: if parseEpisode(nameChunks[1]) == None: if len(nameChunks[1]) >= 4: if parseEpisode(nameChunks[2]) <> None: extra = nameChunks.pop(1) nameChunks[0] = "%s - %s" % (nameChunks[0], extra) else: while len(nameChunks) > 4: extra = nameChunks.pop(3) nameChunks[2] = "%s - %s" % (nameChunks[2], extra) try: sep = parseEpisode(nameChunks[1]) if sep <> None: if len(sep) == 1: anime_ep = Media.Episode(cleanTitle(nameChunks[0]), sep[0][0], sep[0][1], nameChunks[2]) anime_ep.source = findGroup(nameChunks[2]) anime_ep.parts.append(path) mediaList.append(anime_ep) else: for ep in sep: beginEp = sep[0][1] endEp = sep[-1][1] anime_ep = Media.Episode(cleanTitle(nameChunks[0]), ep[0], ep[1], nameChunks[2]) anime_ep.source = findGroup(nameChunks[2]) anime_ep.display_offset = (ep[1] - beginEp) * 100 / ( endEp - beginEp + 1) anime_ep.parts.append(path) mediaList.append(anime_ep) except: with open('/tmp/adb-unmatchables.log', 'a') as log: log.write("%s\n" % file)
def Scan(path, files, mediaList, subdirs, language=None, root=None): # Just look for video files. VideoFiles.Scan(path, files, mediaList, subdirs, root) # Add them all. for i in files: name, year = VideoFiles.CleanName(os.path.basename(i)) movie = Media.Movie(name, year) movie.parts.append(i) mediaList.append(movie)
def handle(self, match, file): show = 'Bellator' name, year = VideoFiles.CleanName(os.path.basename(file)) m = re.match(self.PATTERN, name, re.IGNORECASE) if not m: return None episode = int(m.group('episode')) title = 'Bellator %d' % episode if year is None and os.path.exists(file): year = getYearFromFile(file) return Media.Episode(show, year, episode, title, year)
def Scan(path, files, mediaList, subdirs, language=None, root=None): # Scan for video files. VideoFiles.Scan(path, files, mediaList, subdirs, root) # Take top two as show/season, but require at least the top one. paths = Utils.SplitPath(path) shouldStack = True if len(paths) == 1 and len(paths[0]) == 0: # Run the select regexps we allow at the top level. for i in files: try: file = os.path.basename(i) for rx in episode_regexps[0:-1]: match = re.search(rx, file, re.IGNORECASE) if match: # Extract data. show = match.group('show') if match.groupdict( ).has_key('show') else '' season = match.group('season') if season.lower() == 'sp': season = 0 episode = int(match.group('ep')) endEpisode = episode if match.groupdict().has_key( 'secondEp') and match.group('secondEp'): endEpisode = int(match.group('secondEp')) # Clean title. name, year = VideoFiles.CleanName(show) if len(name) > 0: for ep in range(episode, endEpisode + 1): tv_show = Media.Episode( name, season, ep, '', year) tv_show.display_offset = ( ep - episode) * 100 / (endEpisode - episode + 1) tv_show.parts.append(i) mediaList.append(tv_show) except Exception, e: pass
def Scan(path, files, mediaList, subdirs, language=None, root=None): filesToRemove = [] # Scan for video files. VideoFiles.Scan(path, files, mediaList, subdirs, root) # Take top two as show/season, but require at least the top one. paths = Utils.SplitPath(path) if len(paths) == 1 and len(paths[0]) == 0: # Run the select regexps we allow at the top level. for i in files: file = os.path.basename(i) match = re.search(regexp, file, re.IGNORECASE) if match: # Extract data. show = match.group('show') year = int(match.group('year')) month = int(match.group('month')) day = int(match.group('day')) # Clean title. name, _ = VideoFiles.CleanName(show) if len(name) > 0: # Use the year as the season. tv_show = Media.Episode(name, year, None, None, None) tv_show.released_at = '%d-%02d-%02d' % (year, month, day) tv_show.parts.append(i) mediaList.append(tv_show) filesToRemove.append(i) # Uniquify and remove. for i in list(set(filesToRemove)): files.remove(i) SeriesScanner.Scan(path, files, mediaList, subdirs, language, root)
def handle(self, match, file): show = self.show_name name, year = VideoFiles.CleanName(os.path.basename(file)) m = re.match(self.PATTERN % self.show_name, name, re.IGNORECASE) if not m: return None episode = int(m.group('episode')) * 10 title = '' if 'early' in name.lower(): episode += 1 title = 'Early Prelims' elif 'prelim' in name.lower(): episode += 2 title = 'Prelims' else: episode += 3 title = 'Main Event' if year is None and os.path.exists(file): year = getYearFromFile(file) return Media.Episode(show, year, episode, title, year)
def handle(self, match, file): show = 'UFC' name, year = VideoFiles.CleanName(os.path.basename(file)) m = re.match(self.PATTERN, name, re.IGNORECASE) if not m: return None title = m.group('title') lower = title.lower() episode = int(m.group('episode')) * 10 if "weigh" in lower: episode += 1 elif "prelim" in lower: episode += 2 else: if title == "": title = "Fight" episode += 3 if year is None and os.path.exists(file): year = getYearFromFile(file) return Media.Episode(show, year, episode, title, year)
def handle(self, match, file): show = 'WSOP' basename = os.path.basename(file) m = re.match(self.PATTERN, basename, re.IGNORECASE) if not m: return None year = int(m.group('year')) title = VideoFiles.CleanName(m.group('title'))[0] titleLower = title.lower() if 'preview' in titleLower: episode = 0 elif "one drop" in titleLower: m = re.match('.*part ?(?P<day>\d+)', title, re.IGNORECASE) if not m: return None day = int(m.group('day')) episode = day * 10 elif "main event" in titleLower: m = re.match('.*day ?(?P<day>\d+)(?P<part>[a-z]?)', title, re.IGNORECASE) if not m: return None day = int(m.group('day')) part = m.group('part') if "final table" in titleLower: episode = 200 + day * 10 else: episode = 100 + day * 10 if part != "": episode += ord(part[0]) - ord('a') + 1 else: m = re.match(".*part.(?P<part>\d+)", title,re.IGNORECASE) if m: part = m.group('part') episode += int(part) else: return None return Media.Episode(show, year, episode, title, year)
def Scan(path, files, mediaList, subdirs, language=None, root=None, **kwargs): # Scan for video files. VideoFiles.Scan(path, files, mediaList, subdirs, root) # Check for DVD rips. paths = Utils.SplitPath(path) video_ts = Utils.ContainsFile(files, 'video_ts.ifo') if video_ts is None: video_ts = Utils.ContainsFile(files, 'video_ts.bup') if len(paths) >= 1 and len(paths[0]) > 0 and video_ts is not None: print "Found a DVD" name = year = None # Now find the name. if paths[-1].lower() == 'video_ts' and len(paths) >= 2: # Easiest case. (name, year) = VideoFiles.CleanName(paths[-2]) else: # Work up until we find a viable candidate. backwardsPaths = paths backwardsPaths.reverse() for p in backwardsPaths: if re.match(nice_match, p): (name, year) = VideoFiles.CleanName(p) break if name is None: # Use the topmost path. (name, year) = VideoFiles.CleanName(paths[0]) movie = Media.Movie(name, year) # Add the video_ts file first. movie.parts.append(video_ts) biggestFile = None biggestSize = 0 for i in files: if os.path.splitext(i)[1].lower( ) == '.vob' and os.path.getsize(i) > biggestSize: biggestSize = os.path.getsize(i) biggestFile = i # Add the biggest part so that we can get thumbnail/art/analysis from it. if biggestFile is not None: movie.parts.append(biggestFile) if len(movie.parts) > 0: movie.guid = checkNfoFile(movie.parts[0], 1) mediaList.append(movie) # Check for Bluray rips. elif len(paths) >= 3 and paths[-1].lower() == 'stream' and paths[-2].lower( ) == 'bdmv': (name, year) = VideoFiles.CleanName(paths[-3]) movie = Media.Movie(name, year) for i in files: movie.parts.append(i) mediaList.append(movie) else: # Make movies! for i in files: file = os.path.basename(i) (name, year) = VideoFiles.CleanName(os.path.splitext(file)[0]) # If it matches a TV show, don't scan it as a movie. tv = False for rx in SeriesScanner.episode_regexps[0:-1]: if re.match(rx, file): print "The file", file, "looked like a TV show so we're skipping it (", rx, ")" tv = True if tv == False: # OK, it's a movie movie = Media.Movie(name, year) movie.source = VideoFiles.RetrieveSource(file) movie.parts.append(i) mediaList.append(movie) # Stack the results. Stack.Scan(path, files, mediaList, subdirs) # Clean the folder name and try a match on the folder. if len(path) > 0: folderName = os.path.basename(path).replace(' ', ' ').replace(' ', '.') (cleanName, year) = VideoFiles.CleanName(folderName) if len(mediaList) == 1 and re.match(nice_match, cleanName): res = re.findall(nice_match, cleanName) mediaList[0].name = res[0][0] mediaList[0].year = res[0][1] elif len(mediaList) == 1 and (len(cleanName) > 1 or year is not None): mediaList[0].name = cleanName mediaList[0].year = year # Check for a folder with multiple 'CD' subfolders and massage foundCDsubdirs = {} for s in subdirs: m = re.match('cd[ ]*([0-9]+)', os.path.basename(s).lower()) if m: foundCDsubdirs[int(m.groups(1)[0])] = s # More than one cd subdir, let's stack and whack subdirs. if len(foundCDsubdirs) > 1: name, year = VideoFiles.CleanName(os.path.basename(path)) movie = Media.Movie(name, year) movie.guid = checkNfoFile( os.path.dirname(foundCDsubdirs.values()[0]), 1) keys = foundCDsubdirs.keys() keys.sort() for key in keys: d = foundCDsubdirs[key] subFiles = [] for f in os.listdir(d): subFiles.append(os.path.join(d, f)) VideoFiles.Scan(d, subFiles, mediaList, [], None) subdirs.remove(d) movie.parts += subFiles if len(movie.parts) > 0: mediaList.append(movie) # See if we can find a GUID. for mediaItem in mediaList: if mediaItem.guid is None: mediaItem.guid = checkNfoFile(mediaItem.parts[0], len(mediaList)) if len(mediaList) == 1: if mediaList[0].source is None: mediaList[0].source = VideoFiles.RetrieveSource(path) # If the subdirectories indicate that we're inside a DVD, when whack things other than audio and video. whack = [] if 'video_ts' in [Utils.SplitPath(s)[-1].lower() for s in subdirs]: for dir in subdirs: d = os.path.basename(dir).lower() if d not in ['video_ts', 'audio_ts']: whack.append(dir) # Finally, if any of the subdirectories match a TV show, don't enter! for dir in subdirs: for rx in standalone_tv_regexs: res = re.findall(rx, dir) if len(res): whack.append(dir) for w in whack: subdirs.remove(w)
def Scan(dir, files, mediaList, subdirs): # Go through the files and see if any of them need to be stacked. stack_dict = {} stackDiffs = '123456789abcdefghijklmn' # These are the characters we are looking for being different across stackable filenames stackSuffixes = ['cd', 'dvd', 'part', 'pt', 'disk', 'disc', 'scene'] # Sort the mediaList by filename, so we can do our compares properly mediaList[:] = sorted(mediaList, key=compareFilenames) # Search for parts. count = 0 for mediaItem in mediaList[:-1]: m1 = mediaList[count] m2 = mediaList[count + 1] f1 = os.path.basename(m1.parts[0]) f2 = os.path.basename(m2.parts[0]) opcodes = difflib.SequenceMatcher(None, f1, f2).get_opcodes() if len(opcodes) == 3: # We only have one transform (tag, i1, i2, j1, j2) = opcodes[1] if tag == 'replace': # The transform is a replace if (i2 - i1 == 1) and ( j2 - j1 == 1): # The transform is only one character if 1 in [c in f1[i1:i2].lower() for c in stackDiffs ]: # That one character is 1-4 or a-d root = f1[:i1] xOfy = False if f1[i1 + 1:].lower().strip().startswith( 'of' ): #check to see if this an x of y style stack, if so flag it xOfy = True #prefix = f1[:i1] + f1[i2:] #(root, ext) = os.path.splitext(prefix) # Fix cases where it is something like part 01 ... part 02 -- remove that 0, so the suffix check works later if root[-1:] == '0': root = root[:-1] # This is a special case for folders with multiple Volumes of a series (not a stacked movie) [e.g, Kill Bill Vol 1 / 2] if not root.lower().strip().endswith( 'vol') and not root.lower().strip().endswith( 'volume'): # Strip any suffixes like CD, DVD. foundSuffix = False for suffix in stackSuffixes: if root.lower().strip().endswith(suffix): root = root[0:-len(suffix)].strip() foundSuffix = True break if foundSuffix or xOfy: # Replace the name, which probably had the suffix. (name, year) = VideoFiles.CleanName(root) mediaItem.name = name if stack_dict.has_key(root): stack_dict[root].append(m2) else: stack_dict[root] = [m1] stack_dict[root].append(m2) count += 1 # Now combine stacked parts for stack in stack_dict.keys(): for media in stack_dict[stack][1:]: stack_dict[stack][0].parts.append(media.parts[0]) mediaList.remove(media)
def Scan(dir, files, mediaList, subdirs): # Go through the files and see if any of them need to be stacked. stack_dict = {} stackDiffs = r'[\da-n]' # These are the characters we are looking for being different across stackable filenames stackSuffixes = r'(?:cd|dvd|part|pt|disk|disc|scene)\.?(?:\d+)?$' scenePrefixes = r'(?:^scene.\d+|scene.\d+$)' # Sort the mediaList by filename, so we can do our compares properly mediaList[:] = sorted(mediaList, key=compareFilenames) # check for monotonically increasing numeric or alphabetic filenames count = 0 monotonicSeries = False for mediaItem in mediaList[:-1]: # if it didn't start as a monotonic series, it's not going to become one if count > 0 and monotonicSeries == False: break # if items were already stacked by other method, skip this attempt if hasattr(mediaItem, 'stacked') and mediaItem.stacked == True: continue m1 = mediaList[count] m2 = mediaList[count + 1] f1 = os.path.basename(os.path.splitext(m1.parts[0])[0]).strip().lower() f2 = os.path.basename(os.path.splitext(m2.parts[0])[0]).strip().lower() initialA = re.search(r'(^\d+)', f1) initialB = re.search(r'(^\d+)', f2) terminalA = re.search(r'(\d+)$', f1) terminalB = re.search(r'(\d+)$', f2) # if the filenames both start, or both end with a digit, # and the digit of the second filename is 1 larger than the one of the first filename, it's a series if (((initialA and initialB) and (int(initialA.group(0)) == int(initialB.group(0)) - 1)) or ((terminalA and terminalB) and (int(terminalA.group(0)) == int(terminalB.group(0)) - 1))): monotonicSeries = True # if the filenames both start, or both end with a letter, # and the letter seems to the correct one for this iteration if we started from "a", # and the letter of the second filename is 1 larger than the one of the first filename, it's a series if (monotonicSeries == False): initialA = re.search(r'(^[a-y])', f1) initialB = re.search(r'(^[a-y])', f2) terminalA = re.search(r'([a-y])$', f1) terminalB = re.search(r'([a-y])$', f2) if (((initialA and initialB) and (ord(initialA.group(0)) == ord('a') + count and ord(initialA.group(0)) == ord(initialB.group(0)) - 1)) or ((terminalA and terminalB) and (ord(terminalA.group(0)) == ord('a') + count and ord( terminalA.group(0)) == ord(terminalB.group(0)) - 1))): monotonicSeries = True if monotonicSeries: m1.name = dir root = '_monotonic' m1.stacked = True if stack_dict.has_key(root): stack_dict[root].append(m2) # only mark the second item as stacked on last iteration, otherwise it'll break out of the loop in the start if count == len(mediaList) - 1: m2.stacked = True else: stack_dict[root] = [m1] stack_dict[root].append(m2) count += 1 # group scene-based movie splits into a stack for mediaItem in mediaList: # if items were already stacked by other method, skip this attempt if hasattr(mediaItem, 'stacked') and mediaItem.stacked == True: continue f1 = os.path.basename(os.path.splitext(mediaItem.parts[0])[0]).lower() if re.match(scenePrefixes, f1): (name, year) = VideoFiles.CleanName(re.sub(scenePrefixes, '', f1)) root = '_scene' mediaItem.name = name if stack_dict.has_key(root): stack_dict[root].append(mediaItem) mediaItem.stacked = True else: stack_dict[root] = [mediaItem] mediaItem.stacked = True # Search for prefix-based part names. count = 0 for mediaItem in mediaList[:-1]: m1 = mediaList[count] m2 = mediaList[count + 1] # if items were already stacked by other method, skip this attempt if hasattr(m1, 'stacked') and m1.stacked == True: continue f1 = os.path.basename(m1.parts[0]) f2 = os.path.basename(m2.parts[0]) opcodes = difflib.SequenceMatcher(None, f1, f2).get_opcodes() if len(opcodes) == 3: # We only have one transform (tag, i1, i2, j1, j2) = opcodes[1] if tag == 'replace': # The transform is a replace if (i2 - i1 <= 2) and ( j2 - j1 <= 2): # The transform is only one character if re.search(stackDiffs, f1[i1:i2].lower() ): # That one character is 1-4 or a-n root = f1[:i1].strip(' _-') xOfy = False if f1[i1 + 1:].lower().strip().startswith( 'of' ): #check to see if this an x of y style stack, if so flag it xOfy = True #prefix = f1[:i1] + f1[i2:] #(root, ext) = os.path.splitext(prefix) # This is a special case for folders with multiple Volumes of a series (not a stacked movie) [e.g, Kill Bill Vol 1 / 2] if not root.lower().strip().endswith( 'vol') and not root.lower().strip().endswith( 'volume'): # Strip any suffixes like CD, DVD. foundSuffix = False suffixMatch = re.search(stackSuffixes, root.lower().strip()) if suffixMatch: root = root[0:-len(suffixMatch.group(0) )].strip(' _-') foundSuffix = True if foundSuffix or xOfy: # Replace the name, which probably had the suffix. (name, year) = VideoFiles.CleanName(root) # pdb.set_trace() mediaItem.name = name m1.stacked = True if stack_dict.has_key(root): stack_dict[root].append(m2) # only mark the second item as stacked on last iteration, otherwise it'll break out of the loop in the start if count == len(mediaList) - 1: m2.stacked = True else: stack_dict[root] = [m1] stack_dict[root].append(m2) count += 1 # combine stacks if possible count = 0 stacks = stack_dict.keys() for stack in stacks[:-1]: s1 = stacks[count] s2 = stacks[count + 1] opcodes = difflib.SequenceMatcher(None, s1, s2).get_opcodes() if len(opcodes) == 2: # We only have one transform (tag, i1, i2, j1, j2) = opcodes[1] if tag == 'replace': # The transform is a replace if (i2 - i1 == 1) and ( j2 - j1 == 1): # The transform is only one character if re.search(stackDiffs, s1): # That one character is 1-4 or a-n root = s1.lower().strip() suffixMatch = re.search(stackSuffixes, root) if suffixMatch: root = root[0:-len(suffixMatch.group(0))].strip( ' -') (name, year) = VideoFiles.CleanName(root) # merge existing two stacks into new root for oldstack in [s1, s2]: for media in stack_dict[oldstack]: media.name = name if stack_dict.has_key(root): for media in stack_dict[oldstack]: stack_dict[root].append(media) else: stack_dict[root] = stack_dict[oldstack] del stack_dict[oldstack] count += 1 # Now combine stacked parts for stack in stack_dict.keys(): for media in stack_dict[stack][1:]: stack_dict[stack][0].parts.append(media.parts[0]) mediaList.remove(media)
def Scan(path, files, mediaList, subdirs, language=None, root=None): Log('+++++++++++++++++++++ Scan') Log('path:%s' % path.encode('euc-kr')) Log('files:%s' % files) for file in files: Log(file.encode('euc-kr')) Log('mediaList:%s' % mediaList) Log('subdirs:%s' % subdirs) for subdir in subdirs: Log(subdir.encode('euc-kr')) ### Root scan for OS information that i need to complete the Log function ### """ if path == "": Log("================================================================================") try: os_uname="" for string in os.uname(): os_uname += string Log("os.uname(): '%s'" % os_uname) #(sysname, nodename, release, version, machine) # Log("Sys.platform: '%s'" % sys.platform) # Log("os.name: '%s'" % os.name) # 'posix', 'nt', 'os2', 'ce', 'java', 'riscos'.) Log("os.getcwd: '%s'" % os.getcwd()) # Current dir: /volume1/homes/plex Log("root folder: '%s'" % root if root is not None else "") except: pass """ # Scan for video files. VideoFiles.Scan(path, files, mediaList, subdirs, root) # Take top two as show/season, but require at least the top one. paths = Utils.SplitPath(path) if len(paths) != 0: Log('>> SCAN PATH : %s' % paths[0].encode('euc-kr')) shouldStack = True if len(paths) == 1 and len(paths[0]) == 0: # Run the select regexps we allow at the top level. for i in files: Log('\nFILE1 : %s' % i.encode('euc-kr')) try: file = os.path.basename(i) for rx in episode_regexps[0:-1]: match = re.search(rx, file, re.IGNORECASE) if match: # Extract data. show = match.group('show') if match.groupdict( ).has_key('show') else '' season = match.group('season') if season.lower() == 'sp': season = 0 episode = int(match.group('ep')) endEpisode = episode if match.groupdict().has_key( 'secondEp') and match.group('secondEp'): endEpisode = int(match.group('secondEp')) # Clean title. name, year = VideoFiles.CleanName(show) if len(name) > 0: for ep in range(episode, endEpisode + 1): tv_show = Media.Episode( name, season, ep, '', year) tv_show.display_offset = ( ep - episode) * 100 / (endEpisode - episode + 1) tv_show.parts.append(i) mediaList.append(tv_show) except Exception, e: pass
def Scan(path, files, mediaList, subdirs, language=None, root=None): print('Path: "%s" files: %s mediaList: %s subdirs: %s root: %s' % (path, files, mediaList, subdirs, root)) # Scan for video files. VideoFiles.Scan(path, files, mediaList, subdirs, root) # Take top two as show/season, but require at least the top one. paths = Utils.SplitPath(path) shouldStack = True if len(paths) == 1 and len(paths[0]) == 0: # Run the select regexps we allow at the top level. for i in files: file = os.path.basename(i) found = False for rx in date_regexps_top_level: match = re.search(rx, file) if match: show = match.group('show') for rx1, name in show_map.iteritems(): if re.match(rx1, show): show = name break year = int(match.group('year')) month = int(match.group('month')) day = int(match.group('day')) # Use the year as the season. tv_show = Media.Episode(show, year, None, None, None) tv_show.released_at = '%d-%02d-%02d' % (year, month, day) tv_show.parts.append(i) mediaList.append(tv_show) found = True break if found: continue try: for rx in episode_regexps[0:-1]: match = re.search(rx, file, re.IGNORECASE) if match: # Extract data. show = match.group('show') if match.groupdict( ).has_key('show') else '' season = match.group('season') if season.lower() == 'sp': season = 0 # Smart Scanner Changes Start #################################################### elif season.lower() == 'part': season = 1 # Smart Scanner Changes END #################################################### episode = int(match.group('ep')) endEpisode = episode if match.groupdict().has_key( 'secondEp') and match.group('secondEp'): endEpisode = int(match.group('secondEp')) # Clean title. name, year = VideoFiles.CleanName(show) if len(name) > 0: for ep in range(episode, endEpisode + 1): tv_show = Media.Episode( name, season, ep, '', year) tv_show.display_offset = ( ep - episode) * 100 / (endEpisode - episode + 1) tv_show.parts.append(i) mediaList.append(tv_show) found = True if found: break if found: continue except Exception, e: pass
def getAnime(pathAnime): (animeName, animeYear) = VideoFiles.CleanName(pathAnime) logging.debug("Anime Name: %s" % animeName) logging.debug("Anime Year: %s" % animeYear) return (animeName, animeYear)
def Scan(path, files, mediaList, subdirs, language=None, root=None): VideoFiles.Scan(path, files, mediaList, subdirs, root) paths = Utils.SplitPath(path) shouldStack = True logger.debug('=====================================================') logger.debug('- path:%s' % path) logger.debug('- files count:%s' % len(files)) logger.debug('- subdir count:%s' % len(subdirs)) for _ in subdirs: logger.debug(' * %s' % _) if len(paths) != 0: logger.debug('- paths[0] : %s' % paths[0]) if len(paths) == 1 and len(paths[0]) == 0: return name, year_path = VideoFiles.CleanName(paths[0]) tmp = os.path.split(path) logger.debug(tmp) season_num = None if len(tmp) == 2 and tmp[0] != '': try: match = re.search( r'(?P<season_num>\d{1,4})\s*((?P<season_title>.*?))?', tmp[1], re.IGNORECASE) if match: season_num = match.group('season_num') logger.debug('- season_num:%s', season_num) except: season_num = None logger.debug('- show(by path) name:%s year:%s', name, year_path) logger.debug('- files count : %s', len(files)) for i in files: tempDone = False try: file = os.path.basename(i) logger.debug(' * FILE : %s' % file) for rx in episode_regexps: match = re.search(rx, file, re.IGNORECASE) if match: season = int(match.group('season')) if match.group( 'season') is not None else 1 episode = int(match.group('ep')) if season_num is None: tv_show = Media.Episode(name, season, episode, '', year_path) else: tv_show = Media.Episode(name, season_num, episode, '', year_path) tv_show.display_offset = 0 tv_show.parts.append(i) mediaList.append(tv_show) logger.debug(' - APPEND by episode: %s' % tv_show) tempDone = True break if tempDone == False: for rx in date_regexps: match = re.search(rx, file) if match: year = match.group('year') year = int(year) + 2000 if len(year) == 2 else int( year) month = int(match.group('month')) day = int(match.group('day')) tmp = '%d-%02d-%02d' % (year, month, day) if season_num is None: tv_show = Media.Episode(name, year, None, None, None) else: tv_show = Media.Episode(name, season_num, None, None, None) #tv_show = Media.Episode(name, year, tmp, None, year) tv_show.released_at = tmp tv_show.parts.append(i) mediaList.append(tv_show) logger.debug(' - APPEND by date: %s' % tv_show) tempDone = True break if tempDone == False: logger.debug(' NOT APPEND!!') except Exception, e: logger.error(e)
# If we're inside a Plex Versions directory, remove it and the quality directory from consideration. if 'Plex Versions' in paths and len(paths) > 2: versions_index = paths.index('Plex Versions') del paths[versions_index:versions_index + 2] # See if parent directory is a perfect match (e.g. a directory like "24 - 8x02 - Day 8_ 5_00P.M. - 6_00P.M") if len(files) == 1: for rx in standalone_episode_regexs: res = re.findall(rx, paths[-1]) if len(res): show, junk, year, season, episode, junk, endEpisode, junk, title = res[0] # If it didn't have a show, then grab it from the directory. if len(show) == 0: (show, year) = VideoFiles.CleanName(paths[0]) else: (show, ignore) = VideoFiles.CleanName(show) episode = int(episode) if len(endEpisode) > 0: endEpisode = int(endEpisode) else: endEpisode = episode for ep in range(episode, endEpisode+1): tv_show = Media.Episode(show, season, ep, title, year) tv_show.display_offset = (ep-episode)*100/(endEpisode-episode+1) tv_show.parts.append(files[0]) mediaList.append(tv_show)
def Scan(path, files, mediaList, subdirs, language=None, root=None): # Scan for video files. VideoFiles.Scan(path, files, mediaList, subdirs, root) # Take top two as show/season, but require at least the top one. paths = Utils.SplitPath(path) if len(paths) == 1 and len(paths[0]) == 0: # Run the select regexps we allow at the top level. for i in files: file = os.path.basename(i) for rx in episode_regexps[0:-1]: match = re.search(rx, file, re.IGNORECASE) if match: # Extract data. show = match.group('show') season = int(match.group('season')) episode = int(match.group('ep')) endEpisode = episode if match.groupdict().has_key('secondEp') and match.group( 'secondEp'): endEpisode = int(match.group('secondEp')) # Clean title. name, year = VideoFiles.CleanName(show) if len(name) > 0: for ep in range(episode, endEpisode + 1): tv_show = Media.Episode(name, season, ep, '', year) tv_show.display_offset = (ep - episode) * 100 / ( endEpisode - episode + 1) tv_show.parts.append(i) mediaList.append(tv_show) elif len(paths) > 0 and len(paths[0]) > 0: done = False # See if parent directory is a perfect match (e.g. a directory like "24 - 8x02 - Day 8_ 5_00P.M. - 6_00P.M") if len(files) == 1: for rx in standalone_episode_regexs: res = re.findall(rx, paths[-1]) if len(res): show, junk, year, season, episode, junk, endEpisode, junk, title = res[ 0] # If it didn't have a show, then grab it from the directory. if len(show) == 0: (show, year) = VideoFiles.CleanName(paths[0]) episode = int(episode) if len(endEpisode) > 0: endEpisode = int(endEpisode) else: endEpisode = episode for ep in range(episode, endEpisode + 1): tv_show = Media.Episode(show, season, ep, title, year) tv_show.display_offset = (ep - episode) * 100 / ( endEpisode - episode + 1) tv_show.parts.append(files[0]) mediaList.append(tv_show) done = True break if done == False: # Not a perfect standalone match, so get information from directories. (e.g. "Lost/Season 1/s0101.mkv") season = None seasonNumber = None (show, year) = VideoFiles.CleanName(paths[0]) # Which component looks like season? if len(paths) >= 2: season = paths[len(paths) - 1] match = re.match(season_regex, season, re.IGNORECASE) if match: seasonNumber = int(match.group('season')) # Make sure an episode name didn't make it into the show. for rx in ends_with_episode: show = re.sub(rx, '', show) for i in files: done = False file = os.path.basename(i) (file, ext) = os.path.splitext(file) if ext.lower() in ['.mp4', '.m4v', '.mov']: m4season = m4ep = m4year = 0 m4show = title = '' try: mp4fileTags = mp4file.Mp4File(i) # Show. try: m4show = find_data( mp4fileTags, 'moov/udta/meta/ilst/tvshow').encode('utf-8') except: pass # Season. try: m4season = int( find_data(mp4fileTags, 'moov/udta/meta/ilst/tvseason')) except: pass # Episode. m4ep = None try: # tracknum (can be 101) m4ep = int( find_data(mp4fileTags, 'moov/udta/meta/ilst/tracknum')) except: try: # tvepisodenum (can be S2E16) m4ep = find_data( mp4fileTags, 'moov/udta/meta/ilst/tvepisodenum') except: # TV Episode (can be 101) m4ep = int( find_data(mp4fileTags, 'moov/udta/meta/ilst/tvepisode')) if m4ep is not None: found = False try: # See if it matches regular expression. for rx in episode_regexps[:-1]: match = re.search(rx, file, re.IGNORECASE) if match: m4season = int(match.group('season')) m4ep = int(match.group('ep')) found = True if found == False and re.match( '[0-9]+', str(m4ep)): # Carefully convert to episode number. m4ep = int(m4ep) % 100 elif found == False: m4ep = int(re.findall('[0-9]+', m4ep)[0]) except: pass # Title. try: title = find_data( mp4fileTags, 'moov/udta/meta/ilst/title').encode('utf-8') except: pass # Year. try: m4year = int( find_data(mp4fileTags, 'moov/udta/meta/ilst/year')[:4]) except: pass if year and m4year == 0: m4year = year # If we have all the data we need, add it. if len(m4show) > 0 and m4season > 0 and m4ep > 0: tv_show = Media.Episode(m4show, m4season, m4ep, title, m4year) tv_show.parts.append(i) mediaList.append(tv_show) continue except: pass # Check for date-based regexps first. for rx in date_regexps: match = re.search(rx, file) if match: year = int(match.group('year')) month = int(match.group('month')) day = int(match.group('day')) # Use the year as the season. tv_show = Media.Episode(show, year, None, None, None) tv_show.released_at = '%d-%02d-%02d' % (year, month, day) tv_show.parts.append(i) mediaList.append(tv_show) done = True break if done == False: # Take the year out, because it's not going to help at this point. cleanName, cleanYear = VideoFiles.CleanName(file) if cleanYear != None: file = file.replace(str(cleanYear), 'XXXX') # Minor cleaning on the file to avoid false matches on H.264, 720p, etc. whackRx = [ '([hHx][\.]?264)[^0-9]', '[^[0-9](720[pP])', '[^[0-9](1080[pP])', '[^[0-9](480[pP])' ] for rx in whackRx: file = re.sub(rx, ' ', file) for rx in episode_regexps: match = re.search(rx, file, re.IGNORECASE) if match: # Parse season and episode. the_season = int(match.group('season')) episode = int(match.group('ep')) endEpisode = episode if match.groupdict().has_key( 'secondEp') and match.group('secondEp'): endEpisode = int(match.group('secondEp')) # More validation for the weakest regular expression. if rx == episode_regexps[-1]: # Look like a movie? Skip it. if re.match('.+ \([1-2][0-9]{3}\)', paths[-1]): done = True break # Skip episode 0 on the weak regex since it's pretty much never right. if the_season == 0: break # Make sure this isn't absolute order. if seasonNumber is not None: if seasonNumber != the_season: # Something is amiss, see if it starts with an episode numbers. if re.search('^[0-9]+[ -]', file): # Let the episode matcher have it. break # Treat the whole thing as an episode. episode = episode + the_season * 100 if endEpisode is not None: endEpisode = endEpisode + the_season * 100 for ep in range(episode, endEpisode + 1): tv_show = Media.Episode( show, the_season, ep, None, year) tv_show.display_offset = ( ep - episode) * 100 / (endEpisode - episode + 1) tv_show.parts.append(i) mediaList.append(tv_show) done = True break if done == False: # OK, next let's see if we're dealing with something that looks like an episode. # Begin by cleaning the filename to remove garbage like "h.264" that could throw # things off. # (file, fileYear) = VideoFiles.CleanName(file) # if don't have a good year from before (when checking the parent folders) AND we just got a good year, use it. if not year and fileYear: year = fileYear for rx in just_episode_regexs: episode_match = re.search(rx, file, re.IGNORECASE) if episode_match is not None: the_episode = int(episode_match.group('ep')) the_season = 1 # Now look for a season. if seasonNumber is not None: the_season = seasonNumber # See if we accidentally parsed the episode as season. if the_episode >= 100 and int( the_episode / 100) == the_season: the_episode = the_episode % 100 tv_show = Media.Episode(show, the_season, the_episode, None, year) tv_show.parts.append(i) mediaList.append(tv_show) done = True break if done == False: print "Got nothing for:", file # Stack the results. Stack.Scan(path, files, mediaList, subdirs)
def Scan(path, files, mediaList, subdirs): # Scan for video files. VideoFiles.Scan(path, files, mediaList, subdirs) # Take top two as show/season, but require at least the top one. paths = Utils.SplitPath(path) if len(paths) > 0 and len(paths[0]) > 0: done = False if done == False: # Not a perfect standalone match, so get information from directories. (e.g. "Lost/Season 1/s0101.mkv") season = None seasonNumber = None (show, year) = VideoFiles.CleanName(paths[0]) for i in files: done = False file = os.path.basename(i) (file, ext) = os.path.splitext(file) # See if there's a pytivo metadata file to peek at meta = dict() metadata_filename = '{0}.txt'.format(i.replace('_LQ', '')) if os.path.isfile(metadata_filename): with open(metadata_filename, 'r') as f: for line in f: line = line.strip() if line and len(line): line_a = line.split(' : ') if len(line_a) > 1: key, value = line.split(' : ') meta[key] = value #print "pytivo metadata, ", meta # Skip tv shows based on pytivo metadata file and backup to filename if not present is_movie = False if 'isEpisode' in meta: if meta['isEpisode'] == 'false': is_movie = True elif file.strip().startswith('(Rec'): is_movie = True # Skip tivo recorded movies if is_movie == True: print "File {0} is determined to be a movie, skipping".format( file) continue # Test for matching tivo server files found = False for rx in episode_regexps: match = re.search(rx, file, re.IGNORECASE) if match: season = int(match.group('season')) if match.group( 'season') and match.group('season') != '' else None episode = int(match.group('ep')) if match.group( 'ep') and match.group('ep') != '' else None try: title = match.group('title') if match.group( 'title') else None except IndexError: title = None if 'episodeTitle' in meta: title = meta['episodeTitle'] if 'seriesTitle' in meta: show = meta['seriesTitle'] originalAirDate = None if 'originalAirDate' in meta: originalAirDate = meta['originalAirDate'].split( 'T')[0] if season is None and episode is None and title is None: continue if season is None and originalAirDate: season = int(originalAirDate.split('-')[0]) found = True tv_show = Media.Episode(show, season, episode, title, None) if originalAirDate is not None: tv_show.released_at = originalAirDate tv_show.parts.append(i) mediaList.append(tv_show) break if found == True: continue if done == False: print "Got nothing for:", file # Stack the results. Stack.Scan(path, files, mediaList, subdirs)
def Scan(path, files, mediaList, subdirs, language=None, root=None): VideoFiles.Scan(path, files, mediaList, subdirs, root) paths = Utils.SplitPath(path) shouldStack = True logger.debug('=====================================================') logger.debug('- path:%s' % path) logger.debug('- files count:%s' % len(files)) logger.debug('- subdir count:%s' % len(subdirs)) for _ in subdirs: logger.debug(' * %s' % _) if len(paths) != 0: logger.debug('- paths[0] : %s' % paths[0]) logger.debug('- files count : %s', len(files)) for i in files: tempDone = False try: file = os.path.basename(i) logger.debug(' * FILE : %s' % file) #for idx, rx in enumerate(episode_regexps): for rx in episode_regexps: match = re.search(rx, file, re.IGNORECASE) if match: show = match.group('show').replace( '.', '') if match.groupdict().has_key('show') else '' season = 1 episode = int(match.group('ep')) name, year = VideoFiles.CleanName(show) name = re.sub(r'((.*?기획)|(미니시리즈)|(.*?드라마)|(.*?특집))', '', name).strip() logger.debug( ' - MATCH show:[%s] name:[%s] episode:[%s] year:[%s]', show, name, episode, year) if len(name) > 0: tv_show = Media.Episode(name, season, episode, '', year) tv_show.display_offset = 0 tv_show.parts.append(i) mediaList.append(tv_show) logger.debug(' - APPEND by episode: %s' % tv_show) tempDone = True break if tempDone == False: for rx in date_regexps: match = re.search(rx, file) if match: year = int(match.group('year')) + 2000 month = int(match.group('month')) day = int(match.group('day')) show = match.group('show') tv_show = Media.Episode(show, year, None, None, None) tv_show.released_at = '%d-%02d-%02d' % (year, month, day) tv_show.parts.append(i) mediaList.append(tv_show) logger.debug(' - APPEND by date: %s' % tv_show) tempDone = True break if tempDone == False: logger.error(' NOT APPEND!!') except Exception, e: logger.error(e)
def Scan(path, files, mediaList, subdirs, language=None, root=None): ### Root scan for OS information that i need to complete the Log function ### if path == "": Log("================================================================================") try: os_uname = "" for string in os.uname(): os_uname += string Log("os.uname(): '%s'" % os_uname) # (sysname, nodename, release, version, machine) # Log("Sys.platform: '%s'" % sys.platform) # Log("os.name: '%s'" % os.name) # 'posix', 'nt', 'os2', 'ce', 'java', 'riscos'.) Log("os.getcwd: '%s'" % os.getcwd()) # Current dir: /volume1/homes/plex Log("root folder: '%s'" % root if root is not None else "") except: pass ### Skip folder if empty ### if len(files) == 0: return ### Scan information and uild reverse_path array ### Log("================================================================================") Log("Scan: (root: '%s', path='%s', subdirs: %s, language: '%s')" % (root, path, str(subdirs), language)) VideoFiles.Scan(path, files, mediaList, subdirs, root) # relative_path = path.replace(root, " ") # /group/serie/season/ep folder reverse_path = Utils.SplitPath(relative_path) # Take top two as show/season, but require at least the top one. reverse_path.reverse() ### Skip unwanted folders ### for rx in ignore_dirs_re_findall: result = re.findall(rx, reverse_path[0]) if len(result): Log("Regex ignore_dirs_findall : match for '%s'" % reverse_path[0]) Log("[Folder] '%s'" % reverse_path[0], "Plex Media Scanner Custom - Skipped files") return ### bluray folder management ### # source: https://github.com/doublerebel/plex-series-scanner-bdmv/blob/master/Plex%20Series%20Scanner%20(with%20disc%20image%20support).py if len(reverse_path) >= 3 and reverse_path[0].lower() == 'stream' and reverse_path[1].lower() == 'bdmv': for rx in episode_re_search[0:-1]: match = re.search(rx, reverse_path[2], re.IGNORECASE) if match: episode = int(match.group('ep')) endEpisode = int(match.group('secondEp')) if match.groupdict().has_key('secondEp') and match.group( 'secondEp') else episode show, year = VideoFiles.CleanName(match.group('show')) if len(show) > 0: for ep in range(episode, endEpisode + 1): tv_show = Media.Episode(show, int(match.group('season')), ep, '', year) tv_show.display_offset = (ep - episode) * 100 / (endEpisode - episode + 1) for i in files: tv_show.parts.append(i) mediaList.append(tv_show) Log("show: '%s', year: '%s', season: '%2s', ep: %3s found using Bluray convention (bdmv/stream)" % ( show, xint(year), str(int(match.group('season'))), xint(episode))) return ### File loop for unwanted files, allow to use the number of actual files in folder accurately ### for file in files: # "files" is a list of media files full path filename = os.path.basename(file) # filename contain just the filename of the file ### Filter unwanted file extensions ### if file.split('.')[-1] in ignore_suffixes: # compare file extention to blacklist Log("'%s' ignore_suffixes: match" % filename) Log(file, "Plex Media Scanner Custom - ignored suffixes.log") files.remove(file) # in case we reprocess the lsit latter to precise matches or count number of files continue ### Filter trailers and sample files ### for rx in ignore_files_re_findall: match = re.findall(rx, file) if len(match): Log("'%s' ignore_files_findall: match" % filename) Log(file, "Plex Media Scanner Custom - Ignored files.log") files.remove(file) # in case we reprocess the list latter to precise matches, or count number of files break ### Check if folder is a season folder and remove it do reduce complexity ### folder_season = None for folder in reverse_path[ :-1]: # Doesn't thow errors but gives an empty list if items don't exist, might not be what you want in other cases for rx in specials_re_match + season_re_match: # in anime, more specials folders than season folders, so doing it first match = re.match(rx, folder, re.IGNORECASE) if match: folder_season = 0 if rx in specials_re_match else int(match.group( 'season')) # use "if var is | is not None:" as it's faster than "==None" and "if var:" is false if the variable is: False, 0, 0.0, "", () , {}, [], set() Log("Regex specials_regex/season_regex_match: Regex '%s' match for '%s', season: '%s'" % ( rx, folder, str(folder_season))) reverse_path.remove( folder) # All ways to remove: reverse_path.pop(-1), reverse_path.remove(thing|array[0]) break if match: break # Breaking second for loop doesn't exist parent for ### Clean folder name and get year if present ### misc, folder_year = VideoFiles.CleanName(reverse_path[0]) # Take folder year folder_show = clean_filename(reverse_path[0]) # Log("From folder, show: '%s', year: '%s'" % (folder_show, xint(folder_year))) # ### Main File loop to start adding files now #### for file in files: # "files" is a list of media files full path, File is one of the entries filename = os.path.basename(file) # filename is the filename of the file filename_no_ext = os.path.splitext(filename)[ 0] # filename_no_ext is the filename of the file, albeit with no extension misc, year = VideoFiles.CleanName( filename_no_ext) # Get the year before all '()' are stripped drom the filename without the extension ### Year? ### #if re.match('.+ \([1-2][0-9]{3}\)', paths[-1]): ep = clean_filename(filename_no_ext) # Strip () [], all, ep contain the serie name and ep number for now ### Cleanup episode filename If parent Folder contain serie name ### folder_use = False # Bolean to keep track if folder name in case it is included in the filename if folder_show is not None and not folder_show == "": # If containing folder exist or has name different from "_" (scrubed to "") misc = re.sub(folder_show, '', ep, flags=re.IGNORECASE).lstrip() # misc = ep.replace(folder_show, "") # remove cleaned folder name (if exist) from the show name junk = re.sub(folder_show.replace(" ", "").lower(), '', ep, flags=re.IGNORECASE).lstrip() # misc = ep.replace(folder_show, "") # remove cleaned folder name (if exist) from the show name # Log("ep: '%s', misc: '%s', junk: '%s'" % (ep, misc, junk)) if len(misc) < len(ep) or len(junk) < len( ep): # And remove the cleaned folder name from the now cleaned show, just in case the directory is off by things CleanName handles folder_use = True # indicate to latter use folder name since it is present in filename ep = folder_show + " 01" if misc == "" else misc # episode string name stripped of the folder name If nothing is left, take the folder (movie) ep_nb = ep if ep.rfind(" ") == -1 else ep.rsplit(' ', 1)[ 1] # If there is no space (and ep title) / If there is a space ep_nb is the last part hoping there is no episode title # Log ("#2 - ep: '%s'" % ep) # show, ep, title = ep.partition(match.group('ep')) # split keeping the separator, spare a line and keep the title ### Check for date-based regexps first. ### for rx in date_regexps: match = re.search(rx, ep) if match: # Make sure there's not a stronger season/ep match for the same file. try: for r in episode_regexps[:-1] + standalone_episode_regexs: if re.search(r, file): raise except: break year = int(match.group('year')) month = int(match.group('month')) day = int(match.group('day')) tv_show = Media.Episode(show, year, None, None, None) # Use the year as the season. tv_show.released_at = '%d-%02d-%02d' % (year, month, day) tv_show.parts.append(i) mediaList.append(tv_show) break if match: continue # Used "for ... else" before but needed each sub-section shifted, and want to be able to swap the order quickly # Log ("#3 - ep: '%s'" % ep) ### Check for standalone_episode_re_findall ### for rx in standalone_episode_re_findall: match = re.findall(rx, ep) if len(match): show, misc, year2, season, episode, misc, endEpisode, misc, episode_title = match[0] endEpisode = int(episode) if len(endEpisode) == 0 else int(endEpisode) episode = int(episode) add_episode_into_plex(mediaList, files, file, folder_show if folder_use or show == "" else show, season, int(episode), episode_title, year, endEpisode) Log( "show: '%s', year: '%s', season: '%s', ep: %s found using standalone_episode_re_findall on cleaned string '%s' gotten from filename '%s'" % ( folder_show if folder_use else show, xint(year), xint(season), xint(episode), ep, filename)) break # return if match: continue # Used "for ... else" before but needed each sub-section shifted, and want to be able to swap the order quickly # Log ("#4 - ep: '%s'" % ep) ### Check for episode_re_search ### for rx in episode_re_search: match = re.search(rx, ep, re.IGNORECASE) if match: show = clean_filename(match.group('show')) if not folder_use else folder_show season = int(match.group('season')) if folder_season is None else folder_season episode = int(match.group('ep')) endEpisode = int(match.group('secondEp')) if match.groupdict().has_key('secondEp') and match.group( 'secondEp') else episode add_episode_into_plex(mediaList, files, file, show, season, episode, "", year, endEpisode) Log( "show: '%s', year: '%s', season: '%s', ep: %s found using episode_re_search on cleaned string '%s' gotten from filename '%s' also ep_nb: '%s'" % ( show, xint(year), xint(season), xint(episode), ep, filename, ep_nb)) break if match: continue # Used "for ... else" before but needed each sub-section shifted, and want to be able to swap the order quickly ### Check for just_episode_re_search ### for rx in just_episode_re_search: match = re.search(rx, ep, re.IGNORECASE) if match: season = 1 if folder_season is None else folder_season episode = int(match.group('ep')) if folder_use: show = folder_show else: show = ep[:ep.find(match.group('ep'))].rstrip() # remove eveything from the episode number if show.rfind(" ") != -1 and show.rsplit(' ', 1)[1] in ["ep", "Ep", "EP", "eP", "e", "E"]: show = \ show.rsplit(' ', 1)[0] # remove ep at the end if show == "" or show.lower() in folder_show.lower(): show = folder_show # cut down forms of title point to folder anyway # In case of ep filename "EP 01 title of the episode" fallback to folder name add_episode_into_plex(mediaList, files, file, show, season, episode, "", year, None) Log( "show: '%s', year: '%s', season: '%s', ep: %3s found using just_episode_re_search on cleaned string '%s' gotten from filename '%s'" % ( show, xint(year), xint(season), xint(episode), ep, filename)) break if match: continue # Used "for ... else" before but needed each sub-section shifted, and want to be able to swap the order quickly # Log ("#6 - ep: '%s'" % ep) ### Check for AniDB_re_search ### for rx, offset in AniDB_re_search: match = re.search(rx, ep, re.IGNORECASE) if match: # if match.group('ep').isdigit(): episode = int( match.group('ep') ) # else: episode = 1 # for special, offset in [ ['SPECIAL',0], ['SP',0], ['S',0], ['OPENING',100], ['OP',100], ['NCOP',100], ['ENDING',150], ['ED',150], ['NCED',150], ['T',200], ['TRAILER',200], ['P',300], ['O',400] ]: # Removed ['OAV',0], ['OVA',0], as otherwise Asubi iku yo 13 OAV set as special ## if ep_nb.upper().startswith(special) or ep_nb.upper().startswith(special): # and len(ep_nb)<=4 and (ep_nb[ len(special): ].isdigit() or len(ep_nb)==2): episode = 1 if match.group('ep') == "" or not match.group('ep').isdigit() else int(match.group('ep')) episode = offset + episode Log( "show: '%s', year: '%s', season: '%s', ep: %3s found using AniDB_re_search on cleaned string '%s' gotten from filename '%s'" % ( folder_show, xint(year), "0", xint(episode), ep, filename)) add_episode_into_plex(mediaList, files, file, folder_show, 0, episode, "", year, None) break # else: # Log("AniDB regex ok but not catched afterwards - ep_nb: '%s', offset: '%d', string: '%s', file: '%s'" % (ep_nb, offset, ep_nb[ len(special):], file)) # Log("AniDB Folder: '%s', Filename: '%s', ep: '%s', ep_nb: '%s' misc: '%s', word: '%s'" % (reverse_path[0], filename, ep, ep_nb, misc, ep_nb[ len(special):]), "Plex Media Scanner Custom - Skipped files.log") # break if match: continue # Used "for ... else" before but needed each sub-section shifted, and want to be able to swap the order quickly ### Roman numbers ### doesn't work is ep title present match = re.match(roman_re_match, ep_nb, re.IGNORECASE) if match: ep_nb = roman_to_int(ep_nb) Log( "show: '%s', year: '%s', season: '%s', ep: %3s found using AniDB_re_search on cleaned string '%s' gotten from filename '%s'" % ( folder_show, xint(year), "1", xint(ep_nb), ep, filename)) add_episode_into_plex(mediaList, files, file, folder_show, 1, int(ep_nb), "", year, None) continue # Log ("#7 - ep: '%s'" % ep) ### No regular expression worked ### Log("*no show found for ep: '%s', eb_nb: '%s', filename '%s'" % (ep, ep_nb, filename)) Log("Folder: '%s', Filename: '%s', ep: '%s', ep_nb: '%s'" % (reverse_path[0], filename, ep, ep_nb), "Plex Media Scanner Custom - Skipped files.log")