Esempio n. 1
0
  public TranscodeFileImpl lookupFile(TranscodeProfile profile, DiskManagerFileInfo file) {
    try {
      synchronized (this) {
        if (device_files == null) {

          loadDeviceFile();
        }

        String key =
            ByteFormatter.encodeString(file.getDownloadHash())
                + ":"
                + file.getIndex()
                + ":"
                + profile.getUID();

        if (device_files.containsKey(key)) {

          try {
            return (new TranscodeFileImpl(this, key, device_files));

          } catch (Throwable e) {

            device_files.remove(key);

            log("Failed to deserialise transcode file", e);
          }
        }
      }
    } catch (Throwable e) {
    }

    return (null);
  }
Esempio n. 2
0
 @Override
 public Collection<FileInfo> getContentUrls(Download d) {
   final Collection<FileInfo> result = new ArrayList<FileInfo>(d.getDiskManagerFileInfo().length);
   for (DiskManagerFileInfo fileInfo : d.getDiskManagerFileInfo()) {
     result.add(
         new FileInfo(
             fileInfo.getFile().getName(),
             fileInfo.getLength(),
             getContentURL(fileInfo),
             fileTypeRecognizer.recognize(fileInfo.getFile())));
   }
   return result;
 }
Esempio n. 3
0
 public File getImageFile(Download download) throws TorrentException {
   TorrentFile activeFile = CoreTools.getBiggestPreviewableFile(download);
   if (activeFile == null) {
     return null;
   }
   DiskManagerFileInfo fileInfo = CoreTools.getDiskManagerFileInfo(activeFile, download);
   if (fileInfo == null) {
     return null;
   }
   try {
     return FFMpegAsyncOperationManager.getInstance()
         .getPreviewImage(
             download.getTorrent().getHash(), fileInfo.getFile(), 0, TimeUnit.MILLISECONDS);
   } catch (DataNotAvailableException e) {
     return null;
   }
 }
Esempio n. 4
0
  /*
  	public static File getPrimaryFile(Download d) {
  		DiskManagerFileInfo info = getPrimaryFileInfo(d);

  		if ( info == null ){
  			return( null );
  		}else{
  			return( info.getFile( true ));
  		}
  	}

  	public static int getPrimaryFileIndex(DownloadManager dm ){
  		return( getPrimaryFileIndex( PluginCoreUtils.wrap( dm )));
  	}

  	public static int getPrimaryFileIndex(Download d) {
  		DiskManagerFileInfo info = getPrimaryFileInfo(d);

  		if ( info == null ){
  			return( -1 );
  		}else{
  			return( info.getIndex());
  		}
  	}

  	public static DiskManagerFileInfo getPrimaryFileInfo(Download d) {
  		long size = d.getTorrent().getSize();
  		DiskManagerFileInfo[] infos = d.getDiskManagerFileInfo();
  		for(int i = 0; i < infos.length ; i++) {
  			DiskManagerFileInfo info = infos[i];
  			if ( info.isSkipped() || info.isDeleted()){
  				continue;
  			}
  			if( info.getLength() > (long)fileSizeThreshold * size / 100l) {
  				return info;
  			}
  		}
  		return null;
  	}
  */
  public static boolean isExternallyPlayable(Download d, int file_index, boolean complete_only) {

    int primary_file_index = -1;

    if (file_index == -1) {

      DownloadManager dm = PluginCoreUtils.unwrap(d);

      if (dm == null) {

        return (false);
      }

      DiskManagerFileInfo file = null;
      try {
        file = PluginCoreUtils.wrap(dm.getDownloadState().getPrimaryFile());
      } catch (DownloadException e) {
        return false;
      }

      if (file == null) {

        return (false);
      }

      if (file.getDownloaded() != file.getLength()) {

        if (complete_only || getMediaServerContentURL(file) == null) {

          return (false);
        }
      }

      primary_file_index = file.getIndex();

    } else {

      DiskManagerFileInfo file = d.getDiskManagerFileInfo(file_index);

      if (file.getDownloaded() != file.getLength()) {

        if (complete_only || getMediaServerContentURL(file) == null) {

          return (false);
        }
      }

      primary_file_index = file_index;
    }

    if (primary_file_index == -1) {

      return false;
    }

    return (isExternallyPlayable(d.getDiskManagerFileInfo()[primary_file_index]));
  }
Esempio n. 5
0
  private static boolean isExternallyPlayable(DiskManagerFileInfo file) {
    String name = file.getFile(true).getName();

    int extIndex = name.lastIndexOf(".");

    if (extIndex > -1) {

      String ext = name.substring(extIndex);

      if (ext == null) {

        return false;
      }

      ext = ext.toLowerCase();

      if (getPlayableFileExtensions().indexOf(ext) > -1) {

        return true;
      }
    }

    return false;
  }
Esempio n. 6
0
  public TranscodeFileImpl allocateFile(
      TranscodeProfile profile, boolean no_xcode, DiskManagerFileInfo file, boolean for_job)
      throws TranscodeException {
    TranscodeFileImpl result = null;

    setError(KEY_FILE_ALLOC_ERROR, null);

    try {
      synchronized (this) {
        if (device_files == null) {

          loadDeviceFile();
        }

        String key =
            ByteFormatter.encodeString(file.getDownloadHash())
                + ":"
                + file.getIndex()
                + ":"
                + profile.getUID();

        if (device_files.containsKey(key)) {

          try {
            result = new TranscodeFileImpl(this, key, device_files);

          } catch (Throwable e) {

            device_files.remove(key);

            log("Failed to deserialise transcode file", e);
          }
        }

        if (result == null) {

          String ext = profile.getFileExtension();

          String target_file = file.getFile(true).getName();

          if (ext != null && !no_xcode) {

            int pos = target_file.lastIndexOf('.');

            if (pos != -1) {

              target_file = target_file.substring(0, pos);
            }

            target_file += ext;
          }

          target_file = allocateUniqueFileName(target_file);

          File output_file = getWorkingDirectory(true);

          if (!output_file.canWrite()) {

            throw (new TranscodeException(
                "Can't write to transcode folder '" + output_file.getAbsolutePath() + "'"));
          }

          output_file = new File(output_file.getAbsoluteFile(), target_file);

          result =
              new TranscodeFileImpl(
                  this, key, profile.getName(), device_files, output_file, for_job);

          result.setSourceFile(file);

          device_files_last_mod = SystemTime.getMonotonousTime();

          device_files_dirty = true;

        } else {

          result.setSourceFile(file);

          result.setProfileName(profile.getName());
        }
      }
    } catch (Throwable e) {

      setError(KEY_FILE_ALLOC_ERROR, Debug.getNestedExceptionMessage(e));

      throw (new TranscodeException("File allocation failed", e));
    }

    for (TranscodeTargetListener l : listeners) {

      try {
        l.fileAdded(result);

      } catch (Throwable e) {

        Debug.out(e);
      }
    }

    return (result);
  }
Esempio n. 7
0
  public static DiskManagerFileInfo unwrap(
      final org.gudy.azureus2.plugins.disk.DiskManagerFileInfo info) throws DownloadException {
    if (info instanceof DiskManagerFileInfoImpl) {

      return (((DiskManagerFileInfoImpl) info).getCore());
    }

    if (info == null) {

      return (null);
    }

    try {
      Download dl = info.getDownload();

      if (dl != null) {

        org.gudy.azureus2.core3.download.DownloadManager dm = unwrap(dl);

        return (dm.getDiskManagerFileInfo()[info.getIndex()]);
      }
    } catch (Throwable e) {
    }

    // no underlying download, lash something up

    return (new DiskManagerFileInfo() {
      public void setPriority(int b) {
        info.setNumericPriority(b);
      }

      public void setSkipped(boolean b) {
        info.setSkipped(b);
      }

      public boolean setLink(File link_destination) {
        info.setLink(link_destination);

        return (true);
      }

      public boolean setLinkAtomic(File link_destination) {
        info.setLink(link_destination);

        return (true);
      }

      public File getLink() {
        return (info.getLink());
      }

      public boolean setStorageType(int type) {
        return (false);
      }

      public int getStorageType() {
        return (ST_LINEAR);
      }

      public int getAccessMode() {
        return (info.getAccessMode());
      }

      public long getDownloaded() {
        return (info.getDownloaded());
      }

      public String getExtension() {
        return ("");
      }

      public int getFirstPieceNumber() {
        return (info.getFirstPieceNumber());
      }

      public int getLastPieceNumber() {
        return ((int) ((info.getLength() + info.getPieceSize() - 1) / info.getPieceSize()));
      }

      public long getLength() {
        return (info.getLength());
      }

      public int getNbPieces() {
        return (info.getNumPieces());
      }

      public int getPriority() {
        return (info.getNumericPriorty());
      }

      public boolean isSkipped() {
        return (info.isSkipped());
      }

      public int getIndex() {
        return (info.getIndex());
      }

      public DownloadManager getDownloadManager() {
        return (null);
      }

      public org.gudy.azureus2.core3.disk.DiskManager getDiskManager() {
        return (null);
      }

      public File getFile(boolean follow_link) {
        if (follow_link) {

          return (info.getLink());

        } else {

          return (info.getFile());
        }
      }

      public TOTorrentFile getTorrentFile() {
        return (null);
      }

      public DirectByteBuffer read(long offset, int length) throws IOException {

        throw (new IOException("unsupported"));
      }

      public void flushCache() throws Exception {}

      public int getReadBytesPerSecond() {
        return (0);
      }

      public int getWriteBytesPerSecond() {
        return (0);
      }

      public long getETA() {
        return (-1);
      }

      public void close() {}

      public void addListener(DiskManagerFileInfoListener listener) {}

      public void removeListener(DiskManagerFileInfoListener listener) {}
    });
  }