Exemplo n.º 1
0
  public static void generate_preview_for_torrent(TOTorrent created, File file)
      throws TOTorrentException {

    logger.finer("generating preview..2.");
    try {
      File largestFile = null;
      long largest = 0;
      for (TOTorrentFile f : created.getFiles()) {
        if (f == null) {
          continue;
        }

        if (InOrderType.getType(f.getRelativePath()) == null) {
          continue;
        }
        if (f.getLength() > largest) {
          largest = f.getLength();
          if (file.isDirectory() == false) {
            largestFile = new File(file.getParent(), f.getRelativePath());
          } else {
            largestFile = new File(file, f.getRelativePath());
          }
        }
      }

      if (largestFile != null) {
        logger.finer("largest is: " + largestFile.getAbsolutePath());
      }

      try {
        FFMpegAsyncOperationManager.getInstance()
            .getPreviewImage(created.getHash(), largestFile, 10, TimeUnit.SECONDS);
      } catch (TorrentException e) {
        // this should never happen...
        e.printStackTrace();
      } catch (DataNotAvailableException e) {
        logger.finest("unable to create preview for file: " + largest);
      }
    } catch (NullPointerException e) {
      logger.warning("Preview generation null pointer: " + e.toString());
      e.printStackTrace();
    }
  }
Exemplo n.º 2
0
  public static boolean generate_audio_info_xml(
      File saveLocation, TOTorrent inTorrent, File metaFile) {

    Map<String, Properties> audio_file_properties = new HashMap<String, Properties>();

    if (inTorrent.isSimpleTorrent()) {
      Properties p = new Properties();
      InOrderType type = InOrderType.getType(saveLocation.getName());
      if (type != null) {

        if (type.getFileTypeFilter().equals(FileTypeFilter.Audio)) {
          try {
            AudioFile f = AudioFileIO.read(saveLocation);
            Tag tag = f.getTag();

            if (tag != null) {
              AudioHeader audioHeader = f.getAudioHeader();
              setPropsFromTagAndHeader(p, audioHeader, tag);
            }

            if (p.size() > 0) {
              audio_file_properties.put(saveLocation.getName(), p);
            }
          } catch (Exception e) {
            System.err.println("audio tag parse error: " + e.toString());
          }
        }
      }
    } else {
      for (TOTorrentFile torrent_file : inTorrent.getFiles()) {
        Properties p = new Properties();
        audio_file_properties.put(torrent_file.getRelativePath(), p);

        InOrderType type = InOrderType.getType(torrent_file.getRelativePath());
        if (type != null) {

          if (type.getFileTypeFilter().equals(FileTypeFilter.Audio)) {
            try {
              File file = new File(saveLocation, torrent_file.getRelativePath());
              AudioFile f = AudioFileIO.read(file);
              Tag tag = f.getTag();

              if (tag != null) {
                AudioHeader audioHeader = f.getAudioHeader();
                setPropsFromTagAndHeader(p, audioHeader, tag);

                if (p.size() > 0) {
                  audio_file_properties.put(saveLocation.getName(), p);
                }
              }
            } catch (Exception e) {
              System.err.println("audio tag parse error: " + e.toString());
            }
          } // if it's an audio type
        } // if this file has a recognizable type
      } // for over torrent files
    }

    if (audio_file_properties.size() > 0) {
      try {
        XMLEncoder encoder =
            new XMLEncoder(new BufferedOutputStream(new FileOutputStream(metaFile)));
        encoder.writeObject(audio_file_properties);
        encoder.close();
        logger.fine(
            "wrote audio properties xml for: " + (new String(inTorrent.getName(), "UTF-8")));
      } catch (Exception e) {
        try {
          logger.warning(
              "error writing audio properties for: "
                  + new String(inTorrent.getName(), "UTF-8")
                  + " / "
                  + e.toString());
        } catch (UnsupportedEncodingException e1) {
          e1.printStackTrace();
        }
        e.printStackTrace();
        return false;
      }

      return true;
    }
    return false;
  }