예제 #1
0
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)
예제 #2
0
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)
예제 #4
0
def Scan(path, files, mediaList, subdirs, language=None, root=None):
    VideoFiles.Scan(path, files, mediaList, subdirs, root)

    # require alphabetic order
    files.sort()

    # group movie parts as they come in sequence
    prev_media = None
    prev_part_index = None

    for file in files:
        attr = xattr_metadata(file)
        if attr is None:
            continue

        guid = movie_guid(attr)
        if guid is None:
            continue

        print("[XATTR] %s | %s" % (guid, attr))

        part_index = movie_part_index(attr)
        if prev_part_index and part_index and prev_part_index + 1 == part_index and prev_media.guid == guid:
            prev_part_index = part_index
            prev_media.parts.append(file)
            print("[MEDIA] %s | Part %s" % (prev_media, part_index))
            continue

        media = Media.Movie(
            movie_name(attr).encode(
                'utf-8'),  # use str since Plex doesn't like unicode strings
            movie_year(attr))
        media.guid = guid.encode('utf-8')

        original_filename = xattr_filename(file)
        if original_filename:
            media.source = VideoFiles.RetrieveSource(
                original_filename.encode('utf-8'))

        media.parts.append(file)
        mediaList.append(media)

        if part_index == 1:
            prev_media = media
            prev_part_index = 1
        else:
            prev_media = None
            prev_part_index = None

        print("[MEDIA] %s | %s | %s | %s" %
              (media, media.year, media.released_at, media.source))
예제 #5
0
def Scan(path, files, mediaList, subdirs, language=None, root=None):

    # Scan for video files.
    VideoFiles.Scan(path, files, mediaList, subdirs, root)

    for idx, file in enumerate(files):
        log('Scan', 'file: %s', file)

        absFilePath = os.path.abspath(unicodize(file))
        log('Scan', 'absolute file path: %s', absFilePath)

        # Iterate over the list of parsers and parse the file path
        for parser in SERIES_PARSERS:
            if parser.containsMatch(absFilePath) is True:
                log('Scan', 'parser %s contains match - parsing file path',
                    parser)
                parser.parse(absFilePath, lang)

                showTitle = parser.getShowTitle()
                Log('Scan', 'show title %s', showTitle)
                seasonTitle = parser.getSeasonTitle()
                Log('Scan', 'season title %s', seasonTitle)
                episodeNumber = parser.getEpisodeNumber()
                Log('Scan', 'episode number %s', episodeNumber)
                episodeTitle = parser.getEpisodeTitle()
                Log('Scan', 'episode title %s', episodeTitle)

                vid = Media.Episode(showTitle, seasonTitle, episodeNumber,
                                    episodeTitle, None)
                if parser.getEpisodeReleaseDate() is not None:
                    vid.released_at = parser.getEpisodeReleaseDate()
                vid.parts.append(file)
                mediaList.append(vid)
                print mediaList
예제 #6
0
def Scan(path, files, mediaList, subdirs, language=None, root=None):
	VideoFiles.Scan(path, files, mediaList, subdirs, root)
	
	for i in files:
		logging.debug("file:"+i)
        file = os.path.basename(i)
        logging.debug("basename:"+file)
        match = re.search(episode_regexp, file, re.IGNORECASE)
        if match:
			year = match.group('year')
			race = int(match.group('race'))
			sessionnumber = int(match.group('session'))
			session = sessionmap[sessionnumber]
			episode = match.group('episode')
			
			logging.debug("Found F1 episode - Year: %d, Race: %d, Session: %s, Episode: %s", year, race, session, episode)
			
			racetitle = year + " " + str(episode) + " Grand Prix"
			description = session + " - " + racetitle
			
			tv_show = Media.Episode(year, race, sessionnumber, description, year)	
			tv_show.parts.append(i)
			mediaList.append(tv_show)
			logging.debug("tv_show created")
	Stack.Scan(path, files, mediaList, subdirs)
예제 #7
0
def Scan(path, files, mediaList, subdirs):

    if len(files) >= 1:

        # Iterate through all the files
        for file in files:
            if (file.endswith("/info")):
                dir = os.path.dirname(file)
                infoFile = open(file).read()
                title = re.search('^T (.*)$', infoFile, re.M)
                if title:
                    title = title.groups(1)[0]
                else:
                    title = "Unnamed VDR recording"

                movie = Media.Movie(title)

                for ts_filename in sorted(os.listdir(dir)):
                    if (ts_filename.endswith(".ts")):
                        if (ts_filename.endswith("00001.ts")):
                            movie.source = VideoFiles.RetrieveSource(
                                dir + "/" + ts_filename)
                        movie.parts.append(dir + "/" + ts_filename)

                if len(movie.parts) > 0:
                    mediaList.append(movie)
def Scan(path, files, mediaList, subdirs, language=None, root=None):
    VideoFiles.Scan(path, files, mediaList, subdirs, root)

    for file in files:
        attr = xattr_metadata(file)
        if attr is None:
            continue

        print("[XATTR] %s" % attr)

        # single episode | multi episode
        episodes = list_episodes(attr)
        multi_episode_count = len(episodes)

        for i, attr in enumerate(episodes):
            guid = series_guid(attr)
            name = series_name(attr)
            special = episode_special_number(attr)

            media = Media.Episode(
                name.encode(
                    'utf-8'
                ),  # use str since Plex doesn't like unicode strings
                0 if special else episode_season_number(attr),
                special if special else episode_number(attr),
                episode_title(attr).encode(
                    'utf-8'
                ),  # use str since Plex doesn't like unicode strings
                series_year(attr))

            date = episode_date(attr)
            if date:
                media.released_at = date.strftime('%Y-%m-%d')

            if (multi_episode_count > 1):
                media.display_offset = (i * 100) / multi_episode_count

            original_filename = xattr_filename(file)
            if original_filename:
                media.source = VideoFiles.RetrieveSource(
                    original_filename.encode('utf-8'))

            media.parts.append(file)
            mediaList.append(media)

            print("[MEDIA] %s | %s | %s | %s" %
                  (media, media.year, media.released_at, media.source))
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
예제 #10
0
def Scan(path, files, mediaList, subdirs, language=None, root=None):
    log('Scan', 'path: %s', path)
    log('Scan', 'files: %s', files)
    log('Scan', 'mediaList: %s', mediaList)
    log('Scan', 'subdirs: %s', subdirs)
    log('Scan', 'language: %s', language)
    log('Scan', 'root: %s', root)

    # Scan for video files.
    VideoFiles.Scan(path, files, mediaList, subdirs, root)

    for idx, file in enumerate(files):
        log('Scan', 'file: %s', file)
        # http://127.0.0.1:8111/api/ep/getbyfilename?apikey=d422dfd2-bdc3-4219-b3bb-08b85aa65579&filename=%5Bjoseole99%5D%20Clannad%20-%2001%20(1280x720%20Blu-ray%20H264)%20%5B8E128DF5%5D.mkv

        episode_data = HttpReq("api/ep/getbyfilename?filename=%s" %
                               (urllib.quote(os.path.basename(file))))
        if len(episode_data) == 0: break
        if (try_get(episode_data, "code", 200) == 404): break

        series_data = HttpReq("api/serie/fromep?id=%d&nocast=1&notag=1" %
                              episode_data['id'])
        showTitle = series_data['name'].encode(
            "utf-8")  #no idea why I need to do this.
        log('Scan', 'show title: %s', showTitle)

        seasonYear = episode_data['year']
        log('Scan', 'season year: %s', seasonYear)
        seasonNumber = 0
        seasonStr = try_get(episode_data, 'season', None)
        if episode_data['eptype'] == 'Credits':
            seasonNumber = -1  #season -1 for OP/ED
        elif episode_data['eptype'] == 'Trailer':
            seasonNumber = -2  #season -2 for Trailer
        elif seasonStr == None:
            if episode_data['eptype'] == 'Episode': seasonNumber = 1
            elif episode_data['eptype'] == 'Special': seasonNumber = 0
        else:
            seasonNumber = int(seasonStr.split('x')[0])
            if seasonNumber <= 0 and episode_data['eptype'] == 'Episode':
                seasonNumber = 1

        if seasonNumber <= 0 and Prefs['IncludeOther'] == False:
            continue  #Ignore this by choice.

        if (series_data["ismovie"] == 0 or seasonNumber <= 0):
            continue
        vid = Media.Movie(showTitle, int(seasonYear))
        log('Scan', 'vid: %s', vid)
        vid.parts.append(file)
        mediaList.append(vid)

    log('Scan', 'stack media')
    Stack.Scan(path, files, mediaList, subdirs)
    log('Scan', 'media list %s', mediaList)
예제 #11
0
def Scan(path, files, mediaList, subdirs, language=None, root=None):
    try:
        Log.debug('path: %s', path)
        Log.debug('files: %s', files)
        Log.debug('mediaList: %s', mediaList)
        Log.debug('subdirs: %s', subdirs)
        Log.debug('language: %s', language)
        Log.info('root: %s', root)

        # Scan for video files.
        VideoFiles.Scan(path, files, mediaList, subdirs, root)

        for idx, file in enumerate(files):
            Log.info('file: %s', file)
            # http://127.0.0.1:8111/api/ep/getbyfilename?apikey=d422dfd2-bdc3-4219-b3bb-08b85aa65579&filename=%5Bjoseole99%5D%20Clannad%20-%2001%20(1280x720%20Blu-ray%20H264)%20%5B8E128DF5%5D.mkv

            episode_data = HttpReq("api/ep/getbyfilename?filename=%s" %
                                   (urllib.quote(os.path.basename(file))))
            if len(episode_data) == 0: break
            if (try_get(episode_data, "code", 200) == 404): break

            series_data = HttpReq("api/serie/fromep?id=%d&nocast=1&notag=1" %
                                  episode_data['id'])
            if (series_data["ismovie"] == 1):
                break  # Ignore movies in preference for Shoko Movie Scanner
            showTitle = series_data['name'].encode(
                "utf-8")  #no idea why I need to do this.
            Log.info('show title: %s', showTitle)

            seasonNumber = 0
            seasonStr = try_get(episode_data, 'season', None)
            if seasonStr == None:
                if episode_data['eptype'] == 'Episode': seasonNumber = 1
                if episode_data['eptype'] == 'Credits':
                    seasonNumber = -1  #season -1 for OP/ED
            else:
                seasonNumber = seasonStr.split('x')[0]

            if seasonNumber <= 0 and Prefs['IncludeOther'] == False:
                break  #Ignore this by choice.

            Log.info('season number: %s', seasonNumber)
            episodeNumber = int(episode_data['epnumber'])
            Log.info('episode number: %s', episodeNumber)

            vid = Media.Episode(showTitle, int(seasonNumber), episodeNumber)
            Log.info('vid: %s', vid)
            vid.parts.append(file)
            mediaList.append(vid)

        Log.info('stack media')
        Stack.Scan(path, files, mediaList, subdirs)
        Log.debug('media list %s', mediaList)
    except Exception as e:
        Log.error("Error in Scan: '%s'" % e)
예제 #12
0
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)
예제 #13
0
def Scan(path, files, mediaList, subdirs):

  #logging.basicConfig(filename='/tmp/vdrscanner.log',level=logging.DEBUG)

  if len(files) >= 1:

    # Iterate through all the files
    for file in files:
      if (file.endswith("/info")):
        dir = os.path.dirname(file)
        infoFile = open(file).read()

        title = re.search('^T (.*)$', infoFile,re.M)

        # accepted formats for Episode 3 of season 1, episode name "epname"
        # (3:22) epname
        # (3:22/s1) epname
        # (Ep 3:22) epname
        # (Ep 3:22/s1) epname
        # (Ep. 3:22) epname
        # (Ep. 3:22/s1) epname
        #      
        # Both S and D lines are scanned.
        episode = re.search('^(?:S|D) \((?:Ep\.|Ep)?\s*(\d+)(?:\:\d+)?(?:\/s(\d+))?\)\.\s+(.*)$', infoFile, re.M)

        if episode and title:
            tvshow = True
        else:
            tvshow = False

        # some shows that lack episode info for some reason
        forceshow = re.search('^T (Ren and Stimpy|Die Ren & Stimpy Show|Simpsonit)', infoFile, re.M)
        if forceshow and title:
            tvshow = True
 
        if not tvshow:
	    if title:
                title = title.groups(1)[0]
            else:
                title = "Unknown"

            #logging.debug('Title : %s' %title)

	    movie = Media.Movie(title)

            for ts_filename in sorted(os.listdir(dir)):
                if (ts_filename.endswith(".ts")):
                    if (ts_filename.endswith("00001.ts")):
                        movie.source = VideoFiles.RetrieveSource(dir+"/"+ts_filename)
                    movie.parts.append(dir+"/"+ts_filename)

	    if len(movie.parts)>0:
    	        mediaList.append(movie)
예제 #14
0
  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)
예제 #15
0
def Scan(path, files, mediaList, subdirs, lang=None, root=None):

    log('Scan', '')

    log('Scan', 'path: %s', path)
    log('Scan', 'files: %s', files)
    log('Scan', 'mediaList: %s', mediaList)
    log('Scan', 'subdirs: %s', subdirs)
    log('Scan', 'lang: %s', lang)
    log('Scan', 'root: %s', root)

    # For each directory Scan is called for, the directories' files ( that is not  sub directories ) are passed in as well.
    # The VideoFiles automatically filters for filetypes that are typically not wanted. Removing .txt etc
    VideoFiles.Scan(path, files, mediaList, subdirs, root)

    ## Files Array will now be populated with 'desireable' files.  These are strings of the full file and path
    for idx, file in enumerate(files):
        log('Scan:VideoFiles', 'VideoFiles: %s', file)
예제 #16
0
def Scan(path, files, mediaList, subdirs):
    # Scan for video files.
    print files
    VideoFiles.Scan(path, files, mediaList, subdirs)
    scanner = GenericScanner()
    # Run the select regexps we allow at the top level.
    for file in files:
        filename, ext = os.path.splitext(os.path.basename(file))
        show = customScan(filename)
        if show is None:
            show = scanner.scan(filename)
        if show is None:
            show = scanner.scan(file)
        if show is not None:
            print(filename)
            print(
                "  Show: %s\n  Season: %d\n  episode: %d\n  title: %s\n  Year: %s"
                % (show.show, show.season, show.episode, show.name, show.year))
            show.parts.append(file)
            mediaList.append(show)
예제 #17
0
def Scan(path, files, mediaList, subdirs):
    VideoFiles.Scan(path, files, mediaList, subdirs)
    paths = Utils.SplitPath(path)

    logging.debug("---------------------------------------------------")
    logging.debug("Paths: %s" % paths)

    if len(paths) == 1 and len(paths[0]) > 0:
        pathAnime = paths[0]
        (animeName, animeYear) = getAnime(pathAnime)
        findEpisodes(animeName, animeYear, 1, files, mediaList)

    elif len(paths) == 2:
        pathAnime = paths[0]
        (animeName, animeYear) = getAnime(pathAnime)

        pathSeason = paths[1]
        seasonNumber = getSeason(pathSeason)
        findEpisodes(animeName, animeYear, seasonNumber, files, mediaList)

    Stack.Scan(path, files, mediaList, subdirs)
예제 #18
0
def Scan(path, files, mediaList, subdirs):
    # Scan for video files.
    VideoFiles.Scan(path, files, mediaList, subdirs)
    LogMsg("SicktubeScanner.VideoFiles.Scan({0}, {1}, {2}, {3})".format(
        path, files, mediaList, subdirs))

    for mediaFile in files:
        (file, ext) = os.path.splitext(mediaFile)
        if ext == 'json':
            continue
        infoJsonFile = file + '.info.json'
        LogMsg("{0} | {1} | {2} | {3}".format(os.path.basename(mediaFile),
                                              mediaFile, infoJsonFile,
                                              os.path.exists(infoJsonFile)))

        # Create the movie
        (name, ext) = os.path.splitext(os.path.basename(mediaFile))
        # Is there a .info.json file indicating we've used our scanner?
        if not os.path.exists(infoJsonFile):
            movie = Media.Movie(name)
            movie.parts.append(mediaFile)
        else:
            downloadInfo = json.load(open(infoJsonFile))
            movie = Media.Movie("{0}".format(downloadInfo['title']))
            #movie = Media.Movie(os.path.basename(mediaFile))
            movie.parts.append(mediaFile)
            # Source URL
            if 'webpage_url' in downloadInfo:
                movie.source = "{0}".format(downloadInfo['webpage_url'])
            # Website/Movie ID
            if 'id' in downloadInfo:
                movie.guid = "{0}".format(downloadInfo['id'])
            # Year
            if 'upload_date' in downloadInfo:
                dateObj = datetime.strptime(downloadInfo['upload_date'],
                                            '%Y%m%d')
                movie.year = "{0}".format(dateObj.year)
        mediaList.append(movie)
    # Stack the results.
    Stack.Scan(path, files, mediaList, subdirs)
def Scan(path, files, mediaList, subdirs):
    print "********************************************"
    print "Starting scan of " + path

    # Scan for video files.
    VideoFiles.Scan(path, files, mediaList, subdirs)
    print "After videofiles scan " + path
    # Run the select regexps we allow at the top level.
    for i in files:
        file = os.path.basename(i)
        print "File found: " + file
        for rx in episode_regexps[0:1]:
            match = re.search(rx, file, re.IGNORECASE)
            if match:

                # Extract data.
                print "Match found on file: " + file
                show = match.group('show')
                year = int(match.group('year'))
                month = int(match.group('month'))
                day = int(match.group('day'))
                ep = '%0*d' % (2, month) + '%0*d' % (2, day)
                title = '%0*d' % (4, year) + "-" + ep
                print "Extracted Details:"
                print "Show: " + show
                print "Year: " + '%0*d' % (4, year)
                print "Month: " + '%0*d' % (2, month)
                print "Day:" + '%0*d' % (2, day)
                print "ep: " + ep
                print "Title: " + title
                if len(show) > 0:
                    tv_show = Media.Episode(show, year, ep, ep, None)
                    tv_show.released_at = '%d-%02d-%02d' % (year, month, day)
                    tv_show.parts.append(i)
                    mediaList.append(tv_show)
            else:
                print 'No match found on %s' % file

    # Stack the results.
    Stack.Scan(path, files, mediaList, subdirs)
예제 #20
0
def Scan(path, files, mediaList, subdirs, language=None, root=None):
    log('Scan', 'path: %s', path)
    log('Scan', 'files: %s', files)
    log('Scan', 'mediaList: %s', mediaList)
    log('Scan', 'subdirs: %s', subdirs)
    log('Scan', 'language: %s', language)
    log('Scan', 'root: %s', root)

    # Scan for video files.
    VideoFiles.Scan(path, files, mediaList, subdirs, root)

    for idx, file in enumerate(files):
        log('Scan', 'file: %s', file)
        # http://127.0.0.1:8111/api/ep/getbyfilename?apikey=d422dfd2-bdc3-4219-b3bb-08b85aa65579&filename=%5Bjoseole99%5D%20Clannad%20-%2001%20(1280x720%20Blu-ray%20H264)%20%5B8E128DF5%5D.mkv

        episode_data = HttpReq("api/ep/getbyfilename?filename=%s" %
                               (urllib.quote(os.path.basename(file))))
        if len(episode_data) == 0: break
        if (try_get(episode_data, "code", 200) == 404): break

        series_data = HttpReq("api/serie/fromep?id=%d&nocast=1&notag=1" %
                              episode_data['id'])
        if (series_data["ismovie"] == 0):
            continue
        showTitle = series_data['name'].encode(
            "utf-8")  #no idea why I need to do this.
        log('Scan', 'show title: %s', showTitle)

        seasonYear = episode_data['year']
        log('Scan', 'season year: %s', seasonYear)

        vid = Media.Movie(showTitle, int(seasonYear))
        log('Scan', 'vid: %s', vid)
        vid.parts.append(file)
        mediaList.append(vid)

    log('Scan', 'stack media')
    Stack.Scan(path, files, mediaList, subdirs)
    log('Scan', 'media list %s', mediaList)
예제 #21
0
  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)
예제 #22
0
  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)
예제 #23
0
  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)
예제 #24
0
def Scan(path, files, mediaList, subdirs, language=None, root=None):

    # Scan for video files.
    VideoFiles.Scan(path, files, mediaList, subdirs, root)

    filesToRemove = []

    for i in files:
        file = os.path.basename(i).lower()

        if re.match(episode_regexp, file):
            filesToRemove.append(i)
        else:
            for j in VideoFiles.source_dict['dtv']:
                if j in file:
                    filesToRemove.append(i)
                    break

    # Uniquify and remove.
    for i in list(set(filesToRemove)):
        files.remove(i)

    MovieScanner.Scan(path, files, mediaList, subdirs, language, root)
def Scan(path, files, mediaList, subdirs, language=None, root=None):

    Log.debug('path: %s', path)
    Log.debug('files: %s', files)
    Log.debug('subdirs: %s', subdirs)

    # Scan for video files.
    VideoFiles.Scan(path, files, mediaList, subdirs, root)
    
    for idx, file in enumerate(files):
        try:
            Log.info('file: %s', file)
            # http://127.0.0.1:8111/api/ep/getbyfilename?apikey=d422dfd2-bdc3-4219-b3bb-08b85aa65579&filename=%5Bjoseole99%5D%20Clannad%20-%2001%20(1280x720%20Blu-ray%20H264)%20%5B8E128DF5%5D.mkv

            episode_data = HttpReq("api/ep/getbyfilename?filename=%s" % (urllib.quote(os.path.basename(file))))
            if len(episode_data) == 0: continue
            if (try_get(episode_data, "code", 200) == 404): continue

            series_data = HttpReq("api/serie/fromep?id=%d&nocast=1&notag=1" % episode_data['id'])
            if not (try_get(series_data, "ismovie", 0)) or (episode_data['eptype'] != 'Episode'): continue # Skip series and extras
            showTitle = series_data['name'].encode("utf-8") #no idea why I need to do this.
            Log.info('show title: %s', showTitle)

            seasonYear = episode_data['year']
            Log.info('season year: %s', seasonYear)

            vid = Media.Movie(showTitle, int(seasonYear))
            Log.info('vid: %s', vid)
            vid.parts.append(file)
            mediaList.append(vid)
        except Exception as e:
            Log.error("Error in Scan: '%s'" % e)
            continue

    Log.info('Scan', 'stack media')
    Stack.Scan(path, files, mediaList, subdirs)
    Log.info('Scan', 'media list %s', mediaList)
예제 #26
0
def Scan(path, files, mediaList, subdirs, lang=None, root=None):

    log('Scan', '')

    log('Scan', 'path: %s', path)
    log('Scan', 'files: %s', files)
    log('Scan', 'mediaList: %s', mediaList)
    log('Scan', 'subdirs: %s', subdirs)
    log('Scan', 'lang: %s', lang)
    log('Scan', 'root: %s', root)

    # For each directory Scan is called for, the directories' files ( that is not  sub directories ) are passed in as well.
    # The VideoFiles automatically filters for filetypes that are typically not wanted. Removing .txt etc
    VideoFiles.Scan(path, files, mediaList, subdirs, root)

    ## Files Array will now be populated with 'desireable' files.  These are strings of the full file and path
    for idx, file in enumerate(files):
        log('Scan:VideoFiles', 'VideoFiles: %s', file)
        # Lang, appears to be the Library Path of the file, and we want to remove that to get the important parts
        file_path = file.replace(lang, '')
        log('Scan:ForEachFile', 'Important bits: %s', file_path)
        # Using the File Delimiter, split the string
        split_path = file_path.split('/')
        log('Scan:ForEachFile', 'Split bits: %s', split_path)
        # For the Lazy if three , Else if four
        if len(split_path) == 3:
            media = Media.Episode(split_path[1], None, None, split_path[2],
                                  None)

        if len(split_path) == 4:
            media = Media.Episode(split_path[1], split_path[2], None,
                                  split_path[3], None)

        media.parts.append(file)
        mediaList.append(media)
        print mediaList
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)
예제 #28
0
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)
예제 #29
0
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)
예제 #30
0
def Scan(path, files, mediaList, subdirs, language=None, root=None, **kwargs):

    def strip_name_from_ts_file(tsfile):
         #Retrievess the programma name from a dreambox enigma2 file
         #This has the form of YYYYMMDD HHMM - Channel - Programmename.ts
         #code is borrowed from Enigma2 Movies.py  by Quinten
         #https://forums.plex.tv/index.php/topic/68991-scanner-for-enigma2-ts-file
         #Also transforms the  '_ ' to ': ' "
         base_name = os.path.splitext(os.path.basename(tsfile))[0]
         tmp_name = base_name.split(' - ' ,2)[2].strip()
         return re.sub(r'_ ',': ', tmp_name)

    if debug:
        logfile = open(debugfile, 'a')
        logfile.write("=======================================================\n")
        logfile.write(time.strftime("%c"))
        logfile.write(" --- Entering DREAMBOX DEBUG SCANNER\n")
        logfile.write("recvieved following parameters :\n")
        logfile.write("path parameter      : ")
        logfile.write(str(path))
        logfile.write('\n')
        logfile.write("files parameter     : ")
        logfile.write(str(files))
        logfile.write('\n')
        logfile.write("mediaList parameter : ")
        logfile.write(str(mediaList))
        logfile.write('\n')
        logfile.write("subdirs parameter   : ")
        logfile.write(str(subdirs))
        logfile.write('\n')
        logfile.write("language parameter  : ")
        logfile.write(str(language))
        logfile.write('\n')
        logfile.write("root parameter      : ")
        logfile.write(str(root))
        logfile.write('\n')
        logfile.write("kwargs parameter    : ")
        logfile.write(str(kwargs))
        logfile.write('\n')
        logfile.write("========================================================\n")
        logfile.write("               START PRFOCESSING FILES SECTION          \n ")

    year = ''
    genre = ''
    name = ''

    for scan_file in files:
        # Only process files having a ts extension (these are the movie files)
        if scan_file.endswith(".ts"):
            # chek then if we have the ts.meta meta file
            if os.path.isfile(scan_file + ".meta"):

                if debug:
                    logfile.write(str("found ts.meta file : " + str(scan_file + ".meta") + "\n"))

                # lookup title and year from the ts.meta file
                meta = open(scan_file + ".meta", 'r')
                lines = meta.readlines()

                if debug:
                    logfile.write("Content of the ")
                    logfile.write(str(scan_file + ".meta" + "\n"))
                    logfile.write(str(lines))
                    logfile.write("\n")

                name = lines[1].strip()

                if name:
                    if debug:
                        logfile.write(str("substracted the programname " + (name) + "\n"))
                else:
                    # programma name is empty in the ts.meta file, so we take it from the filename
                    name = strip_name_from_ts_file(tsfile=scan_file)
                    if debug:
                        logfile.write(str("no title in ts.meta file found, abstracted form filename : " + (name) + "\n"))

                # line 3 in the meta file contains multiple formats.  In this directory we
                # assume onlu movies are to be processed
                # Most common format we have encounterd yet :
                # <genre>.<year>.<short description>  where all fields  ar not always there
                # <year>.<genre>.<short description>
                # <descripton><(year)><(duration)>
                # empty
                # <free text>

                if lines[2].strip():
                    # we do have content
                    if re.match(r'\d{4}\.', lines[2]):
                        if debug:
                            logfile.write("first RegExp matches, first field is the year\n")

                        line_array = lines[2].split('.', 2)
                        elements = len(line_array)
                        year = line_array[0]

                        if elements >= 2:
                            genre = line_array[1]
                        else:
                            genre = ''

                        if elements >= 3:
                            short_info = line_array[2]
                        else:
                            short_info = ''

                    elif re.search(r'\.\d{4}\.', lines[2]):
                        if debug:
                            logfile.write("Second RegExp matches, second field is the year\n")

                        line_array = lines[2].split('.', 2)
                        elements = len(line_array)
                        genre = line_array[0]
                        year = line_array[1]

                        if elements >= 3:
                            short_info = line_array[2]
                        else:
                            short_info = ''

                    elif re.search(r'\(\d{4}\)', lines[2]):
                        if debug:
                            logfile.write("Third RegExp matches, year after info\n")

                        pat = re.compile(r'\(\d{4}\)')
                        res = pat.search(lines[2])
                        short_info = lines[2][0:res.start()-1]
                        year = lines[2][res.start()+1:res.end()-1]
                        genre = ''
                    else:
                        if debug:
                            logfile.write("line not empty, but no match found\n")

                        # we handle this as short info
                        genre = ''
                        year = ''
                        short_info = lines[2]
                else:
                    # empty line
                    if debug:
                        logfile.write("empty line\n")

                    year = ''
                    genre = ''
                    short_info = ''
            else:
                name = strip_name_from_ts_file(tsfile=scan_file)
                year = ''

            if debug:
                logfile.write(str("the year of the movie is " + str(year) + "\n"))
                logfile.write(str("the genre of the movie is " + str(genre) + "\n"))
                logfile.write(str("the info of the movie is " + str(short_info) + "\n"))

            movie = Media.Movie(name, year)
            movie.source = VideoFiles.RetrieveSource(scan_file)
            movie.parts.append(scan_file)

            if debug:
                logfile.write("========================================\n")
                logfile.write(str(movie))
                logfile.write("\n")
                logfile.write("========================================\n")

            mediaList.append(movie)

    if debug:
        logfile.write(" ========================================================================\n")
        logfile.close()