Examples of DLNAMediaSubtitle


Examples of net.pms.dlna.DLNAMediaSubtitle

                  }
                }
              }

              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

Examples of net.pms.dlna.DLNAMediaSubtitle

          output(output, "Expires: " + getFUTUREDATE() + " GMT");
          List<DLNAMediaSubtitle> subs = dlna.getMedia().getSubtitleTracksList();

          if (subs != null && !subs.isEmpty()) {
            // TODO: maybe loop subs to get the requested subtitle type instead of using the first one
            DLNAMediaSubtitle sub = subs.get(0);
            if (sub.isExternal()) {
              inputStream = new java.io.FileInputStream(sub.getExternalFile());
            }
          }
        } else {
          // This is a request for a regular file.
          String name = dlna.getDisplayName(mediaRenderer);
          inputStream = dlna.getInputStream(Range.create(lowRange, highRange, timeseek, timeRangeEnd), mediaRenderer);
          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 (!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
                List<DLNAMediaSubtitle> subs = dlna.getMedia().getSubtitleTracksList();

                if (subs != null && !subs.isEmpty()) {
                  DLNAMediaSubtitle sub = subs.get(0);
                  String subtitleUrl;
                  String subExtension = sub.getType().getExtension();

                  if (isNotBlank(subExtension)) {
                    subtitleUrl = "http://" + PMS.get().getServer().getHost()
                        + ':' + PMS.get().getServer().getPort() + "/get/"
                        + id + "/subtitle0000." + subExtension;
View Full Code Here

Examples of net.pms.dlna.DLNAMediaSubtitle

          output.setHeader(HttpHeaders.Names.EXPIRES, getFUTUREDATE() + " GMT");
          List<DLNAMediaSubtitle> subs = dlna.getMedia().getSubtitleTracksList();

          if (subs != null && !subs.isEmpty()) {
            // TODO: maybe loop subs to get the requested subtitle type instead of using the first one
            DLNAMediaSubtitle sub = subs.get(0);
            if (sub.isExternal()) {
              inputStream = new java.io.FileInputStream(sub.getExternalFile());
            }
          }
        } else {
          // This is a request for a regular file.

          // If range has not been initialized yet and the DLNAResource has its
          // own start and end defined, initialize range with those values before
          // requesting the input stream.
          Range.Time splitRange = dlna.getSplitRange();

          if (range.getStart() == null && splitRange.getStart() != null) {
            range.setStart(splitRange.getStart());
          }

          if (range.getEnd() == null && splitRange.getEnd() != null) {
            range.setEnd(splitRange.getEnd());
          }

          inputStream = dlna.getInputStream(Range.create(lowRange, highRange, range.getStart(), range.getEnd()), mediaRenderer);

          if (!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
            List<DLNAMediaSubtitle> subs = dlna.getMedia().getSubtitleTracksList();

            if (subs != null && !subs.isEmpty()) {
              DLNAMediaSubtitle sub = subs.get(0);
              String subtitleUrl;
              String subExtension = sub.getType().getExtension();
              if (isNotBlank(subExtension)) {
                subtitleUrl = "http://" + PMS.get().getServer().getHost()
                    + ':' + PMS.get().getServer().getPort() + "/get/"
                    + id + "/subtitle0000." + subExtension;
              } else {
View Full Code Here

Examples of net.pms.dlna.DLNAMediaSubtitle

        logger.trace("Chose a default audio track: " + params.aid);
      }
    }

    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;
    }

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

    while (st1.hasMoreTokens()) {
      String pair = st1.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")) {
            matchedSub = new DLNAMediaSubtitle();
            matchedSub.setLang("off");
          } else {
            for (DLNAMediaSubtitle present_sub : media.getSubtitleTracksList()) {
              if (present_sub.matchCode(sub) || sub.equals("*")) {
                matchedSub = present_sub;
                logger.trace("Found a match: " + matchedSub);
                break;
              }
            }
          }

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

    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;
      }
    }

    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")) {
            StringTokenizer st = new StringTokenizer(configuration.getForcedSubtitleTags(), ",");

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

              if (sub.getFlavor().toLowerCase().indexOf(forcedTags) > -1
                  && 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

Examples of net.pms.dlna.DLNAMediaSubtitle

    List<String> options = new ArrayList<String>();
    String subsOption = null;
    String padding = null;
    final RendererConfiguration renderer = params.mediaRenderer;

    DLNAMediaSubtitle tempSubs = null;
    if (!isDisableSubtitles(params)) {
      tempSubs = getSubtitles(params);
    }

    final boolean isResolutionTooHighForRenderer = renderer.isVideoRescale() // renderer defines a max width/height
        && (media != null && media.isMediaparsed())
        && ((media.getWidth() > renderer.getMaxVideoWidth())
          || (media.getHeight() > renderer.getMaxVideoHeight()));

    if (tempSubs != null) {
      StringBuilder s = new StringBuilder();
      CharacterIterator it = new StringCharacterIterator(ProcessUtil.getShortFileNameIfWideChars(tempSubs.getExternalFile().getAbsolutePath()));

      for (char ch = it.first(); ch != CharacterIterator.DONE; ch = it.next()) {
        switch (ch) {
          case ':':
            s.append("\\\\:");
View Full Code Here

Examples of net.pms.dlna.DLNAMediaSubtitle

   * @param params The {@link net.pms.io.OutputParams} context object used to store miscellaneous parameters for this request.
   * @return Converted subtitle file
   * @throws IOException
   */
  public DLNAMediaSubtitle getSubtitles(OutputParams params) throws IOException {
    DLNAMediaSubtitle tempSubs = null;

    if (params.sid.getId() == -1) {
      return null;
    }

View Full Code Here

Examples of net.pms.dlna.DLNAMediaSubtitle

      if (input != null) {
        input.close();
      }
    }

    final  DLNAMediaSubtitle convertedSubtitles = new DLNAMediaSubtitle();
    convertedSubtitles.setExternalFile(convertedSubtitlesFile);
    convertedSubtitles.setType(inputSubtitles.getType());
    convertedSubtitles.setLang(inputSubtitles.getLang());
    convertedSubtitles.setFlavor(inputSubtitles.getFlavor());
    convertedSubtitles.setId(inputSubtitles.getId());
    return convertedSubtitles;
  }
View Full Code Here

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

Examples of net.pms.dlna.DLNAMediaSubtitle

    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

Examples of net.pms.dlna.DLNAMediaSubtitle

  }

  @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
TOP
Copyright © 2018 www.massapi.com. 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.