Example #1
0
  /**
   * @param dl
   * @since 3.0.2.3
   */
  public static String getMediaServerContentURL(Download dl) {

    // TorrentListViewsUtils.debugDCAD("enter - getMediaServerContentURL");

    PluginManager pm = AzureusCoreFactory.getSingleton().getPluginManager();
    PluginInterface pi = pm.getPluginInterfaceByID("azupnpav", false);

    if (pi == null) {
      Logger.log(new LogEvent(LogIDs.UI3, "Media server plugin not found"));
      return null;
    }

    if (!pi.getPluginState().isOperational()) {
      Logger.log(new LogEvent(LogIDs.UI3, "Media server plugin not operational"));
      return null;
    }

    try {
      Program program = Program.findProgram(".qtl");
      boolean hasQuickTime =
          program == null ? false : (program.getName().toLowerCase().indexOf("quicktime") != -1);

      pi.getIPC().invoke("setQuickTimeAvailable", new Object[] {new Boolean(hasQuickTime)});

      Object url = pi.getIPC().invoke("getContentURL", new Object[] {dl});
      if (url instanceof String) {
        return (String) url;
      }
    } catch (Throwable e) {
      Logger.log(
          new LogEvent(LogIDs.UI3, LogEvent.LT_WARNING, "IPC to media server plugin failed", e));
    }

    return null;
  }
Example #2
0
 private IPCInterface getMediaIpc() {
   if (mediaIpc == null) {
     final PluginInterface mediaInterface = pluginManager.getPluginInterfaceByID("azupnpav", true);
     if (mediaInterface == null) {
       throw new RuntimeException(
           "couldnot find azupnpav plugin - check it is installed and started up");
     }
     mediaIpc = mediaInterface.getIPC();
   }
   return mediaIpc;
 }
  public static void bind_audio_xml(DownloadManager real_dl, boolean force) {
    try {
      /** Don't do this multiple times. */
      if (real_dl.getDownloadState() != null && force == false) {
        if (real_dl.getDownloadState().getAttribute(FileCollection.ONESWARM_ALBUM_ATTRIBUTE)
            != null) {
          return;
        }
        if (real_dl.getDownloadState().getAttribute(FileCollection.ONESWARM_ARTIST_ATTRIBUTE)
            != null) {
          return;
        }
      }

      File metaInfoDir = CoreInterface.getMetaInfoDir(real_dl.getTorrent().getHash());
      File audio_xml = new File(metaInfoDir, PreviewImageGenerator.AUDIO_INFO_FILE);
      if (audio_xml.exists() == false) {
        logger.finest(
            "no xml data for: " + real_dl.getDisplayName() + " / skipping audio info bind");
        return;
      }

      XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(new FileInputStream(audio_xml)));
      Map<String, Properties> audio_file_properties =
          (Map<String, Properties>) decoder.readObject();
      decoder.close();

      boolean setArtist = false, setAlbum = false;
      for (Properties p : audio_file_properties.values()) {
        for (String attrib : new String[] {FileCollection.ONESWARM_ARTIST_ATTRIBUTE}) {
          if (p.getProperty(attrib) != null) {
            real_dl
                .getDownloadState()
                .setAttribute(FileCollection.ONESWARM_ARTIST_ATTRIBUTE, p.getProperty(attrib));
            logger.fine(
                "bound artist: " + p.getProperty(attrib) + " for " + real_dl.getDisplayName());
            setArtist = true;

            if (COConfigurationManager.getBooleanParameter("oneswarm.add.id3.tags")) {
              logger.fine(
                  "adding id3 tag for album: " + p.getProperty(attrib).replaceAll("/", "-"));
              String[] tags =
                  real_dl
                      .getDownloadState()
                      .getListAttribute(FileCollection.ONESWARM_TAGS_ATTRIBUTE);
              if (tags == null) {
                tags = new String[0];
              }
              String[] neu = new String[tags.length + 1];
              System.arraycopy(tags, 0, neu, 0, tags.length);
              neu[tags.length] = "Artists/" + p.getProperty(attrib).replaceAll("/", "-");
              real_dl
                  .getDownloadState()
                  .setListAttribute(FileCollection.ONESWARM_TAGS_ATTRIBUTE, neu);
            }

            break;
          }
        }

        for (String attrib : new String[] {FileCollection.ONESWARM_ALBUM_ATTRIBUTE}) // to
        // deal
        // with
        // old
        // versions
        {
          if (p.getProperty(attrib) != null) {
            real_dl
                .getDownloadState()
                .setAttribute(FileCollection.ONESWARM_ALBUM_ATTRIBUTE, p.getProperty(attrib));
            logger.fine(
                "bound album: " + p.getProperty(attrib) + " for " + real_dl.getDisplayName());
            setAlbum = true;

            if (COConfigurationManager.getBooleanParameter("oneswarm.add.id3.tags")) {
              logger.fine(
                  "adding id3 tag for album: " + p.getProperty(attrib).replaceAll("/", "-"));
              String[] tags =
                  real_dl
                      .getDownloadState()
                      .getListAttribute(FileCollection.ONESWARM_TAGS_ATTRIBUTE);
              if (tags == null) {
                tags = new String[0];
              }
              String[] neu = new String[tags.length + 1];
              System.arraycopy(tags, 0, neu, 0, tags.length);
              neu[tags.length] = "Albums/" + p.getProperty(attrib).replaceAll("/", "-");
              real_dl
                  .getDownloadState()
                  .setListAttribute(FileCollection.ONESWARM_TAGS_ATTRIBUTE, neu);
            }

            break;
          }
        }
        if (setArtist && setAlbum) {
          break;
        }
      }

      /** Need to regenerate our file list to incorporate this new info */
      if (setArtist || setAlbum) {
        PluginInterface f2fIf =
            AzureusCoreImpl.getSingleton().getPluginManager().getPluginInterfaceByID("osf2f");
        if (f2fIf != null) {
          if (f2fIf.isOperational() == true) {
            IPCInterface ipc = f2fIf.getIPC();
            if (ipc != null) {
              ipc.invoke("refreshFileLists", new Object[0]);
            } else {
              logger.warning("f2f IPC is null, couldn't regenerate file list after audio binding");
            }
          } else {
            logger.warning(
                "Couldn't regenerate file list after audio info binding, f2f plugin is not operational");
          }
        } else {
          logger.warning(
              "Couldn't regenerate file list after audio info binding, f2f plugin interface is null");
        }
      }

    } catch (Exception e) {
      logger.warning(
          "error binding audio xml to download manager: "
              + real_dl.getDisplayName()
              + " / "
              + e.toString());
    }
  }