Ejemplo n.º 1
0
  def ScanForMedia(cls):
    if mediamanager.SCANNER_VERBOSE:
      logger.log(u'ScanForMedia :: Starting', logger.DEBUG)
    _files = []
    _media = {}

    for _source in mediamanager.SOURCES:
      if mediamanager.SCANNER_VERBOSE:
        logger.log(u'ScanForMedia :: Getting files from source ' + _source, logger.DEBUG)
      if re.match('^(~).*$', _source) is not None:
        _files.extend(Files.getFilesFromDir(os.path.join(os.path.expanduser("~"), re.match('^~\/(.*)$', _source).group(1))))
      else:
        _files.extend(Files.getFilesFromDir(_source))

    if mediamanager.SCANNER_VERBOSE:
      logger.log(u'ScanForMedia :: Found %d files' % len(_files), logger.DEBUG)

    for item in _files:
      if isinstance(item, Files.VideoInfo):
        match = re.match('^(.*)\..*$',item.basename)
        if match is not None:
          _media[match.group(1)] = item

    if mediamanager.SCANNER_VERBOSE:
      logger.log(u'ScanForMedia :: Found %d video files' % len(_media.keys()), logger.DEBUG)
      logger.log(u'ScanForMedia :: Completed', logger.DEBUG)
    return _media
Ejemplo n.º 2
0
def updatePending(force=False):

  with PENDING_LOCK:

    global MEDIA, PENDING, PENDING_LASTRUN

    current_time = datetime.datetime.now()
    should_run = False
    if force or PENDING_LASTRUN is None or current_time - PENDING_LASTRUN >= datetime.timedelta(minutes=mediamanager.MEDIA_PENDING_CYCLETIME):
      should_run = True

    if should_run:
      PENDING_LASTRUN = current_time

      _files = []

      pattern = re.compile('^.*\.(' + mediamanager.TRANSCODER_PENDING_EXTENSION + ')$', re.I)

      for _source in mediamanager.SOURCES:
        if re.match('^(~).*$', _source) is not None:
          _files.extend(Files.getFilesFromDir(os.path.join(os.path.expanduser("~"), re.match('^~\/(.*)$', _source).group(1)), pattern))
        else:
          _files.extend(Files.getFilesFromDir(_source, pattern))

      _pending = {}

      for _file in _files:
        _name = re.match('^(.*)\..*$', _file.basename).group(1)
        if _name in MEDIA.keys():
          _pending[_name] = _file

      PENDING = _pending
      return True
    else:
      return False
Ejemplo n.º 3
0
def is_pending(fileInfo):
  pattern = re.compile('^.*\.(' + mediamanager.TRANSCODER_PENDING_EXTENSION + ')$', re.I)

  _files = Files.getFilesFromDir(os.path.dirname(fileInfo.path), pattern)

  for _file in _files:
    _name = re.match('^(.*)\..*$', _file.basename).group(1)
    if _name == re.match('^(.*)\..*$', fileInfo.basename).group(1):
      return True
    else:
      return False
Ejemplo n.º 4
0
def cleanPending():
  with PENDING_LOCK:

    _files = []

    pattern = re.compile('^.*\.(' + mediamanager.TRANSCODER_PENDING_EXTENSION + ')$', re.I)

    for _source in mediamanager.SOURCES:
      if re.match('^(~).*$', _source) is not None:
        _files.extend(Files.getFilesFromDir(os.path.join(os.path.expanduser("~"), re.match('^~\/(.*)$', _source).group(1)), pattern))
      else:
        _files.extend(Files.getFilesFromDir(_source, pattern))

    for _file in _files:
      try:
        logger.log("CleanPending :: Removing pending file; %s" % _file.path, logger.DEBUG)
        os.remove(_file.path)
      except Exception, e:
        logger.log("CleanPending :: Exception raised cleaing up pending file; %s" % _file.path, logger.DEBUG)
        logger.log("CleanPending :: Exception :: %s" % e, logger.DEBUG)