Package net.pms.dlna

Examples of net.pms.dlna.DLNAMediaSubtitle


    getSubCpOptionForMencoder(null);
  }

  @Test
  public void testGetSubCpOptionForMencoder_withoutExternalSubtitles() throws Exception {
    DLNAMediaSubtitle subtitle = new DLNAMediaSubtitle();
    assertThat(getSubCpOptionForMencoder(subtitle)).isNull();
  }
View Full Code Here


    assertThat(getSubCpOptionForMencoder(subtitle)).isNull();
  }

  @Test
  public void testGetSubCpOptionForMencoder_withoutDetectedCharset() throws Exception {
    DLNAMediaSubtitle subtitle = new DLNAMediaSubtitle();
    File file_cp1251 = FileUtils.toFile(CLASS.getResource("../../util/russian-cp1251.srt"));
    subtitle.setType(VOBSUB);
    subtitle.setExternalFile(file_cp1251);
    assertThat(subtitle.getExternalFileCharacterSet()).isNull();
    assertThat(getSubCpOptionForMencoder(subtitle)).isNull();
  }
View Full Code Here

  }

  @Test
  public void testGetSubCpOptionForMencoder() throws Exception {
    File file_big5 = FileUtils.toFile(CLASS.getResource("../../util/chinese-big5.srt"));
    DLNAMediaSubtitle sub1 = new DLNAMediaSubtitle();
    sub1.setExternalFile(file_big5);
    assertThat(getSubCpOptionForMencoder(sub1)).isEqualTo("enca:zh:big5");

    File file_gb18030 = FileUtils.toFile(CLASS.getResource("../../util/chinese-gb18030.srt"));
    DLNAMediaSubtitle sub2 = new DLNAMediaSubtitle();
    sub2.setExternalFile(file_gb18030);
    assertThat(getSubCpOptionForMencoder(sub2)).isEqualTo("enca:zh:big5");

    File file_cp1251 = FileUtils.toFile(CLASS.getResource("../../util/russian-cp1251.srt"));
    DLNAMediaSubtitle sub3 = new DLNAMediaSubtitle();
    sub3.setExternalFile(file_cp1251);
    assertThat(getSubCpOptionForMencoder(sub3)).isEqualTo("enca:ru:cp1251");

    File file_ibm866 = FileUtils.toFile(CLASS.getResource("../../util/russian-ibm866.srt"));
    DLNAMediaSubtitle sub4 = new DLNAMediaSubtitle();
    sub4.setExternalFile(file_ibm866);
    assertThat(getSubCpOptionForMencoder(sub4)).isEqualTo("enca:ru:cp1251");

    File file_koi8_r = FileUtils.toFile(CLASS.getResource("../../util/russian-koi8-r.srt"));
    DLNAMediaSubtitle sub5 = new DLNAMediaSubtitle();
    sub5.setExternalFile(file_koi8_r);
    assertThat(getSubCpOptionForMencoder(sub5)).isEqualTo("enca:ru:cp1251");
  }
View Full Code Here

  }

  @Test
  public void testGetSubCpOptionForMencoder_UTF() throws Exception {
    File file_utf8 = FileUtils.toFile(CLASS.getResource("../../util/russian-utf8-without-bom.srt"));
    DLNAMediaSubtitle sub1 = new DLNAMediaSubtitle();
    sub1.setExternalFile(file_utf8);
    assertThat(getSubCpOptionForMencoder(sub1)).isNull();

    File file_utf8_2 = FileUtils.toFile(CLASS.getResource("../../util/russian-utf8-with-bom.srt"));
    DLNAMediaSubtitle sub2 = new DLNAMediaSubtitle();
    sub2.setExternalFile(file_utf8_2);
    assertThat(getSubCpOptionForMencoder(sub2)).isNull();

    File file_utf16_le = FileUtils.toFile(CLASS.getResource("../../util/russian-utf16-le.srt"));
    DLNAMediaSubtitle sub3 = new DLNAMediaSubtitle();
    sub3.setExternalFile(file_utf16_le);
    assertThat(getSubCpOptionForMencoder(sub3)).isNull();

    File file_utf16_be = FileUtils.toFile(CLASS.getResource("../../util/russian-utf16-be.srt"));
    DLNAMediaSubtitle sub4 = new DLNAMediaSubtitle();
    sub4.setExternalFile(file_utf16_be);
    assertThat(getSubCpOptionForMencoder(sub4)).isNull();

    File file_utf32_le = FileUtils.toFile(CLASS.getResource("../../util/russian-utf32-le.srt"));
    DLNAMediaSubtitle sub5 = new DLNAMediaSubtitle();
    sub5.setExternalFile(file_utf32_le);
    assertThat(getSubCpOptionForMencoder(sub5)).isNull();

    File file_utf32_be = FileUtils.toFile(CLASS.getResource("../../util/russian-utf32-be.srt"));
    DLNAMediaSubtitle sub6 = new DLNAMediaSubtitle();
    sub6.setExternalFile(file_utf32_be);
    assertThat(getSubCpOptionForMencoder(sub6)).isNull();

    File file_utf8_3 = FileUtils.toFile(CLASS.getResource("../../util/english-utf8-with-bom.srt"));
    DLNAMediaSubtitle sub7 = new DLNAMediaSubtitle();
    sub7.setExternalFile(file_utf8_3);
    assertThat(getSubCpOptionForMencoder(sub7)).isNull();
  }
View Full Code Here

  /**
   * {@inheritDoc}
   */
  @Override
  public boolean isCompatible(DLNAResource resource) {
    DLNAMediaSubtitle subtitle = resource.getMediaSubtitle();

    // Check whether the subtitle actually has a language defined,
    // uninitialized DLNAMediaSubtitle objects have a null language.
    if (subtitle != null && subtitle.getLang() != null) {
      // The resource needs a subtitle, but PMS does not support subtitles for tsMuxeR.
      return false;
    }

    try {
View Full Code Here

                  }
                }
              }

              if (!exists) {
                DLNAMediaSubtitle sub = new DLNAMediaSubtitle();
                sub.setId(100 + (media == null ? 0 : media.getSubtitleTracksList().size())); // fake id, not used
                if (code.length() == 0 || !Iso639.getCodeList().contains(code)) {
                  sub.setLang(DLNAMediaSubtitle.UND);
                  sub.setType(SubtitleType.valueOfFileExtension(ext));
                  if (code.length() > 0) {
                    sub.setFlavor(code);
                    if (sub.getFlavor().contains("-")) {
                      String flavorLang = sub.getFlavor().substring(0, sub.getFlavor().indexOf('-'));
                      String flavorTitle = sub.getFlavor().substring(sub.getFlavor().indexOf('-') + 1);
                      if (Iso639.getCodeList().contains(flavorLang)) {
                        sub.setLang(flavorLang);
                        sub.setFlavor(flavorTitle);
                      }
                    }
                  }
                } else {
                  sub.setLang(code);
                  sub.setType(SubtitleType.valueOfFileExtension(ext));
                }

                try {
                  sub.setExternalFile(f);
                } catch (FileNotFoundException ex) {
                  LOGGER.warn("Exception during external subtitles scan.", ex);
                }

                found = true;
View Full Code Here

      if (format.getIdentifier() == Format.Identifier.WEB) {
        return false;
      }
    }

    DLNAMediaSubtitle subtitle = resource.getMediaSubtitle();

    // Check whether the subtitle actually has a language defined,
    // Uninitialized DLNAMediaSubtitle objects have a null language.
    if (subtitle != null && subtitle.getLang() != null) {
      // This engine only supports external subtitles
      if (subtitle.getExternalFile() != null) {
        return true;
      }

      return false;
    }
View Full Code Here

      if (format.getIdentifier() == Format.Identifier.WEB) {
        return false;
      }
    }

    DLNAMediaSubtitle subtitle = resource.getMediaSubtitle();

    // Check whether the subtitle actually has a language defined,
    // uninitialized DLNAMediaSubtitle objects have a null language.
    if (subtitle != null && subtitle.getLang() != null) {
      // The resource needs a subtitle, but this engine implementation does not support subtitles yet
      return false;
    }

    try {
View Full Code Here

   * @param params
   * The parameters to populate.
   */
  public static void setSubtitleOutputParameters(String fileName, DLNAMediaInfo media, OutputParams params) {
    String currentLang = null;
    DLNAMediaSubtitle matchedSub = null;

    if (params.aid != null) {
      currentLang = params.aid.getLang();
    }

    if (params.sid != null && params.sid.getId() == -1) {
      LOGGER.trace("Don't want subtitles!");
      params.sid = null;
      return;
    }

    /**
     * Check for live subtitles
     */
    if (params.sid != null && !StringUtils.isEmpty(params.sid.getLiveSubURL())) {
      LOGGER.debug("Live subtitles " + params.sid.getLiveSubURL());
      try {
        matchedSub = params.sid;
        String file = OpenSubtitle.fetchSubs(matchedSub.getLiveSubURL(), matchedSub.getLiveSubFile());
        if (!StringUtils.isEmpty(file)) {
          matchedSub.setExternalFile(new File(file));
          params.sid = matchedSub;
          return;
        }
      } catch (IOException e) {
      }
    }

    StringTokenizer st = new StringTokenizer(configuration.getAudioSubLanguages(), ";");

    /**
     * Check for external and internal subtitles matching the user's language
     * preferences
     */
    boolean matchedInternalSubtitles = false;
    boolean matchedExternalSubtitles = false;
    while (st.hasMoreTokens()) {
      String pair = st.nextToken();
      if (pair.contains(",")) {
        String audio = pair.substring(0, pair.indexOf(','));
        String sub = pair.substring(pair.indexOf(',') + 1);
        audio = audio.trim();
        sub = sub.trim();
        LOGGER.trace("Searching for a match for: " + currentLang + " with " + audio + " and " + sub);

        if (Iso639.isCodesMatching(audio, currentLang) || (currentLang != null && audio.equals("*"))) {
          if (sub.equals("off")) {
            /**
             * Ignore the "off" language for external subtitles if the user setting is enabled
             * TODO: Prioritize multiple external subtitles properly instead of just taking the first one we load
             */
            if (configuration.isForceExternalSubtitles()) {
              for (DLNAMediaSubtitle present_sub : media.getSubtitleTracksList()) {
                if (present_sub.getExternalFile() != null) {
                  matchedSub = present_sub;
                  matchedExternalSubtitles = true;
                  LOGGER.trace("Ignoring the \"off\" language because there are external subtitles");
                  break;
                }
              }
            }
            if (!matchedExternalSubtitles) {
              matchedSub = new DLNAMediaSubtitle();
              matchedSub.setLang("off");
            }
          } else {
            for (DLNAMediaSubtitle present_sub : media.getSubtitleTracksList()) {
              if (present_sub.matchCode(sub) || sub.equals("*")) {
                if (present_sub.getExternalFile() != null) {
                  if (configuration.isAutoloadExternalSubtitles()) {
                    // Subtitle is external and we want external subtitles, look no further
                    matchedSub = present_sub;
                    LOGGER.trace("Matched external subtitles track: " + matchedSub);
                    break;
                  } else {
                    // Subtitle is external but we do not want external subtitles, keep searching
                    LOGGER.trace("External subtitles ignored because of user setting: " + present_sub);
                  }
                } else if (!matchedInternalSubtitles) {
                  matchedSub = present_sub;
                  LOGGER.trace("Matched internal subtitles track: " + matchedSub);
                  if (configuration.isAutoloadExternalSubtitles()) {
                    // Subtitle is internal and we will wait to see if an external one is available instead
                    matchedInternalSubtitles = true;
                  } else {
                    // Subtitle is internal and we will use it
                    break;
                  }
                }
              }
            }
          }

          if (matchedSub != null && !matchedInternalSubtitles) {
            break;
          }
        }
      }
    }

    /**
     * Check for external subtitles that were skipped in the above code block
     * because they didn't match language preferences, if there wasn't already
     * a match and the user settings specify it.
     */
    if (matchedSub == null && configuration.isForceExternalSubtitles()) {
      for (DLNAMediaSubtitle present_sub : media.getSubtitleTracksList()) {
        if (present_sub.getExternalFile() != null) {
          matchedSub = present_sub;
          LOGGER.trace("Matched external subtitles track that did not match language preferences: " + matchedSub);
          break;
        }
      }
    }

    /**
     * Disable chosen subtitles if the user has disabled all subtitles or
     * if the language preferences have specified the "off" language.
     *
     * TODO: Can't we save a bunch of looping by checking for isDisableSubtitles
     * just after the Live Subtitles check above?
     */
    if (matchedSub != null && params.sid == null) {
      if (configuration.isDisableSubtitles() || (matchedSub.getLang() != null && matchedSub.getLang().equals("off"))) {
        LOGGER.trace("Disabled the subtitles: " + matchedSub);
      } else {
        params.sid = matchedSub;
      }
    }

    /**
     * Check for forced subtitles.
     */
    if (!configuration.isDisableSubtitles() && params.sid == null && media != null) {
      // Check for subtitles again
      File video = new File(fileName);
      FileUtil.isSubtitlesExists(video, media, false);

      if (configuration.isAutoloadExternalSubtitles()) {
        boolean forcedSubsFound = false;
        // Priority to external subtitles
        for (DLNAMediaSubtitle sub : media.getSubtitleTracksList()) {
          if (matchedSub != null && matchedSub.getLang() != null && matchedSub.getLang().equals("off")) {
            st = new StringTokenizer(configuration.getForcedSubtitleTags(), ",");

            while (sub.getFlavor() != null && st.hasMoreTokens()) {
              String forcedTags = st.nextToken();
              forcedTags = forcedTags.trim();

              if (
                sub.getFlavor().toLowerCase().contains(forcedTags) &&
                Iso639.isCodesMatching(sub.getLang(), configuration.getForcedSubtitleLanguage())
              ) {
                LOGGER.trace("Forcing preferred subtitles: " + sub.getLang() + "/" + sub.getFlavor());
                LOGGER.trace("Forced subtitles track: " + sub);

                if (sub.getExternalFile() != null) {
                  LOGGER.trace("Found external forced file: " + sub.getExternalFile().getAbsolutePath());
                }
                params.sid = sub;
                forcedSubsFound = true;
                break;
              }
            }
            if (forcedSubsFound == true) {
              break;
            }
          } else {
            LOGGER.trace("Found subtitles track: " + sub);

            if (sub.getExternalFile() != null) {
              LOGGER.trace("Found external file: " + sub.getExternalFile().getAbsolutePath());
              params.sid = sub;
              break;
            }
          }
        }
      }
      if (
        matchedSub != null &&
        matchedSub.getLang() != null &&
        matchedSub.getLang().equals("off")
      ) {
        return;
      }

      if (params.sid == null) {
View Full Code Here

          inputStream = dlna.getThumbnailInputStream();
        } else if (dlna.getMedia() != null && fileName.contains("subtitle0000")) {
          // This is a request for a subtitle file
          output(output, "Content-Type: text/plain");
          output(output, "Expires: " + getFUTUREDATE() + " GMT");
          DLNAMediaSubtitle sub = dlna.getMediaSubtitle();
          if (sub != null) {
            try {
              // XXX external file is null if the first subtitle track is embedded:
              // http://www.ps3mediaserver.org/forum/viewtopic.php?f=3&t=15805&p=75534#p75534
              if (sub.isExternal()) {
                inputStream = new FileInputStream(sub.getExternalFile());
              }
            } catch (NullPointerException npe) {
              LOGGER.trace("Could not find external subtitles: " + sub);
            }
          }
        } else {
          // This is a request for a regular file.
          String name = dlna.getDisplayName(mediaRenderer);
          if (dlna.isNoName()) {
            name = dlna.getName() + " " + dlna.getDisplayName(mediaRenderer);
          }

          inputStream = dlna.getInputStream(Range.create(lowRange, highRange, timeseek, timeRangeEnd), mediaRenderer);
          if (dlna.isResume()) {
            // Update timeseek to possibly adjusted resume time
            timeseek = dlna.getResume().getTimeOffset() / (double) 1000;
          }

          if (inputStream == null) {
            // No inputStream indicates that transcoding / remuxing probably crashed.
            LOGGER.error("There is no inputstream to return for " + name);
          } else {
            startStopListenerDelegate.start(dlna);
            output(output, "Content-Type: " + getRendererMimeType(dlna.mimeType(), mediaRenderer));

            if (dlna.getMedia() != null && !configuration.isDisableSubtitles()) {
              // Some renderers (like Samsung devices) allow a custom header for a subtitle URL
              String subtitleHttpHeader = mediaRenderer.getSubtitleHttpHeader();
              if (subtitleHttpHeader != null && !"".equals(subtitleHttpHeader)) {
                // Device allows a custom subtitle HTTP header; construct it
                DLNAMediaSubtitle sub = dlna.getMediaSubtitle();
                if (sub != null) {
                  String subtitleUrl;
                  String subExtension = sub.getType().getExtension();
                  if (isNotBlank(subExtension)) {
                    subExtension = "." + subExtension;
                  }
                  subtitleUrl = "http://" + PMS.get().getServer().getHost() +
                    ':' + PMS.get().getServer().getPort() + "/get/" +
View Full Code Here

TOP

Related Classes of net.pms.dlna.DLNAMediaSubtitle

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.