File Source: NoatunSource.java

         /* 
    P/P   *  Method: com.dmdirc.addons.mediasource_dcop.NoatunSource__static_init
          */
     1  /*
     2   * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
     3   *
     4   * Permission is hereby granted, free of charge, to any person obtaining a copy
     5   * of this software and associated documentation files (the "Software"), to deal
     6   * in the Software without restriction, including without limitation the rights
     7   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     8   * copies of the Software, and to permit persons to whom the Software is
     9   * furnished to do so, subject to the following conditions:
    10   *
    11   * The above copyright notice and this permission notice shall be included in
    12   * all copies or substantial portions of the Software.
    13   *
    14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    20   * SOFTWARE.
    21   */
    22  
    23  package com.dmdirc.addons.mediasource_dcop;
    24  
    25  import com.dmdirc.addons.nowplaying.MediaSource;
    26  import com.dmdirc.addons.nowplaying.MediaSourceState;
    27  
    28  import java.util.List;
    29  
    30  /**
    31   * Uses DCOP to retrieve now playing info from Noatun.
    32   *
    33   * @author chris
    34   */
    35  public class NoatunSource implements MediaSource {
    36      
    37      /** Instantiates the media source. */
             /* 
    P/P       *  Method: void com.dmdirc.addons.mediasource_dcop.NoatunSource()
              */
    38      public NoatunSource() {
    39          //Do nothing
    40      }
    41      
    42      /** {@inheritDoc} */
    43      @Override
    44      public MediaSourceState getState() {
                 /* 
    P/P           *  Method: MediaSourceState getState()
                  * 
                  *  Presumptions:
                  *    com.dmdirc.plugins.ExportedService:execute(...)@61 != null
                  *    java.util.List:get(...)@47 != null
                  * 
                  *  Postconditions:
                  *    return_value in Addr_Set{&com.dmdirc.addons.nowplaying.MediaSourceState__static_init.new MediaSourceState(MediaSourceState__static_init#1),&com.dmdirc.addons.nowplaying.MediaSourceState__static_init.new MediaSourceState(MediaSourceState__static_init#2),&com.dmdirc.addons.nowplaying.MediaSourceState__static_init.new MediaSourceState(MediaSourceState__static_init#3),&com.dmdirc.addons.nowplaying.MediaSourceState__static_init.new MediaSourceState(MediaSourceState__static_init#4),&com.dmdirc.addons.nowplaying.MediaSourceState__static_init.new MediaSourceState(MediaSourceState__static_init#5)}
                  * 
                  *  Test Vectors:
                  *    java.lang.Integer:parseInt(...)@49: {0}, {1}, {2}, {-231..-1, 3..232-1}
                  *    java.util.List:size(...)@46: {-231..0}, {1..232-1}
                  */
    45          final List<String> res = DcopMediaSourcePlugin.getDcopResult("dcop noatun Noatun state");
    46          if (res.size() > 0) {
    47              final String result = res.get(0).trim();
    48              try {
    49                  final int status = (Integer.parseInt(result));
    50                  switch (status) {
    51                      case 0:
    52                          return MediaSourceState.STOPPED;
    53                      case 1:
    54                          return MediaSourceState.PAUSED;
    55                      case 2:
    56                          return MediaSourceState.PLAYING;
    57                      default:
    58                          return MediaSourceState.NOTKNOWN;
    59                  }
    60              } catch (NumberFormatException nfe) {
    61                  return MediaSourceState.CLOSED;
    62              }
    63          } else {
    64              return MediaSourceState.CLOSED;
    65          }
    66      }
    67      
    68      /** {@inheritDoc} */
    69      @Override
    70      public String getAppName() {
                 /* 
    P/P           *  Method: String getAppName()
                  * 
                  *  Postconditions:
                  *    return_value == &amp;"Noatun"
                  */
    71          return "Noatun";
    72      }
    73      
    74      /** {@inheritDoc} */
    75      @Override
    76      public String getArtist() {
                 /* 
    P/P           *  Method: String getArtist()
                  * 
                  *  Presumptions:
                  *    com.dmdirc.plugins.ExportedService:execute(...)@61 != null
                  *    java.util.List:get(...)@77 != null
                  * 
                  *  Postconditions:
                  *    java.lang.String:substring(...)._tainted == 0
                  *    return_value in Addr_Set{&amp;java.lang.String:substring(...),&amp;""}
                  * 
                  *  Test Vectors:
                  *    java.lang.String:indexOf(...)@79: {-231..-2, 0..232-1}, {-1}
                  */
    77          final String result = DcopMediaSourcePlugin.getDcopResult(
    78                  "dcop noatun Noatun title").get(0);
    79          if (result.indexOf(" - ") == -1) {
    80              return "";
    81          }
    82          return result.substring(0, result.indexOf(" - "));
    83      }
    84  
    85      /** {@inheritDoc} */
    86      @Override
    87      public String getTitle() {
                 /* 
    P/P           *  Method: String getTitle()
                  * 
                  *  Presumptions:
                  *    com.dmdirc.plugins.ExportedService:execute(...)@61 != null
                  *    java.lang.String:indexOf(...)@93 <= 232-4
                  *    java.util.List:get(...)@88 != null
                  * 
                  *  Postconditions:
                  *    java.lang.String:substring(...)._tainted == 0
                  *    return_value in Addr_Set{&amp;java.lang.String:substring(...),&amp;""}
                  * 
                  *  Test Vectors:
                  *    java.lang.String:indexOf(...)@90: {-231..-2, 0..232-1}, {-1}
                  */
    88          final String result = DcopMediaSourcePlugin.getDcopResult(
    89                  "dcop noatun Noatun title").get(0);
    90          if (result.indexOf(" - ") == -1) {
    91              return "";
    92          }
    93          return result.substring(result.indexOf(" - ") + 3, result.length());
    94      }
    95  
    96      /** {@inheritDoc} */
    97      @Override
    98      public String getAlbum() {
                 /* 
    P/P           *  Method: String getAlbum()
                  * 
                  *  Postconditions:
                  *    return_value == null
                  */
    99          return null;
   100      }
   101  
   102      /** {@inheritDoc} */
   103      @Override
   104      public String getLength() {
                 /* 
    P/P           *  Method: String getLength()
                  * 
                  *  Presumptions:
                  *    com.dmdirc.plugins.ExportedService:execute(...)@61 != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   105          return DcopMediaSourcePlugin.getDcopResult(
   106                  "dcop noatun Noatun lengthString").get(0);
   107      }
   108  
   109      /** {@inheritDoc} */
   110      @Override
   111      public String getTime() {
                 /* 
    P/P           *  Method: String getTime()
                  * 
                  *  Presumptions:
                  *    com.dmdirc.plugins.ExportedService:execute(...)@61 != null
                  * 
                  *  Postconditions:
                  *    java.lang.StringBuilder:toString(...)._tainted == 0
                  *    return_value == &amp;java.lang.StringBuilder:toString(...)
                  */
   112          return duration(Integer.parseInt(DcopMediaSourcePlugin.getDcopResult(
   113                  "dcop noatun Noatun position").get(0)) /1000);
   114      }
   115  
   116      /** {@inheritDoc} */
   117      @Override
   118      public String getFormat() {
                 /* 
    P/P           *  Method: String getFormat()
                  * 
                  *  Postconditions:
                  *    return_value == null
                  */
   119          return null;
   120      }
   121  
   122      /** {@inheritDoc} */
   123      @Override
   124      public String getBitrate() {
                 /* 
    P/P           *  Method: String getBitrate()
                  * 
                  *  Postconditions:
                  *    return_value == null
                  */
   125          return null;
   126      }
   127      
   128      /**
   129       * Get the duration in seconds as a string.
   130       *
   131       * @param secondsInput to get duration for
   132       *
   133       * @return Duration as a string
   134       */
   135      private String duration(final long secondsInput) {
                 /* 
    P/P           *  Method: String duration(long)
                  * 
                  *  Postconditions:
                  *    java.lang.StringBuilder:toString(...)._tainted == 0
                  *    return_value == &amp;java.lang.StringBuilder:toString(...)
                  * 
                  *  Test Vectors:
                  *    secondsInput: {-263..3_599}, {3_600..264-1}
                  *    secondsInput/3_600: {-2_562_047_788_015_215..0}, {1..5_124_095_576_030_431}
                  *    secondsInput/60: {-153_722_867_280_912_930..59}, {60..307_445_734_561_825_860}
                  */
   136          final StringBuilder result = new StringBuilder();
   137          final long hours = secondsInput / 3600;
   138          final long minutes = secondsInput / 60 % 60;
   139          final long seconds = secondsInput % 60;
   140          
   141          if (hours > 0) { 
   142              result.append(hours).append(":");
   143          }
   144          
   145          result.append(minutes).append(":");
   146          result.append(seconds).append(":");
   147          
   148          return result.toString();
   149      }
   150      
   151  }








SofCheck Inspector Build Version : 2.17854
NoatunSource.java 2009-Jun-25 01:54:24
NoatunSource.class 2009-Sep-02 17:04:15