001package silicondust;
002/*-
003 * ##########################################################################
004 * TV H/W, EPGs, and Recording
005 * $Id: HDHRPrimeProtocol.java 5999 2020-05-18 16:41:28Z ball $
006 * $HeadURL: svn+ssh://svn.hcf.dev/var/spool/scm/repository.svn/silicondust/trunk/src/main/java/silicondust/HDHRPrimeProtocol.java $
007 * %%
008 * Copyright (C) 2013 - 2020 Allen D. Ball
009 * %%
010 * Licensed under the Apache License, Version 2.0 (the "License");
011 * you may not use this file except in compliance with the License.
012 * You may obtain a copy of the License at
013 *
014 *      http://www.apache.org/licenses/LICENSE-2.0
015 *
016 * Unless required by applicable law or agreed to in writing, software
017 * distributed under the License is distributed on an "AS IS" BASIS,
018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019 * See the License for the specific language governing permissions and
020 * limitations under the License.
021 * ##########################################################################
022 */
023import ball.http.annotation.Protocol;
024import java.io.IOException;
025import java.util.List;
026import javax.ws.rs.ApplicationPath;
027import javax.ws.rs.GET;
028import javax.ws.rs.Path;
029import javax.ws.rs.PathParam;
030import javax.ws.rs.QueryParam;
031import org.apache.http.HttpResponse;
032import org.apache.http.client.ClientProtocolException;
033import org.apache.http.client.HttpResponseException;
034
035import static java.util.Objects.requireNonNull;
036import static org.apache.commons.lang3.StringUtils.EMPTY;
037
038/**
039 * {@link.uri http://www.silicondust.com/ SiliconDust} HD Homerun Prime
040 * (CableCard) HTTP client protocol.
041 *
042 * @author {@link.uri mailto:ball@hcf.dev Allen D. Ball}
043 * @version $Revision: 5999 $
044 */
045@Protocol(charset = "UTF-8")
046@ApplicationPath("http://{host}:{port}/")
047public interface HDHRPrimeProtocol {
048
049    /**
050     * {@link.uri http://www.silicondust.com/ SiliconDust} HD Homerun Prime
051     * (CableCard) line-up request.
052     *
053     * @param   host            The host IP or name.
054     * @param   port            The port.
055     * @param   show            What to show.
056     * @param   type            The type of output.
057     *
058     * @return  The {@link HttpResponse} containing the line-up.
059     *
060     * @throws  IOException     See {@link ball.http.ProtocolClient}.
061     * @throws  HttpResponseException
062     *                          See {@link ball.http.ProtocolClient}.
063     * @throws  ClientProtocolException
064     *                          See {@link ball.http.ProtocolClient}.
065     */
066    @GET @Path("lineup.{type}")
067    public HttpResponse getLineup(@PathParam(EMPTY) String host,
068                                  @PathParam(EMPTY) Integer port,
069                                  @QueryParam(EMPTY) String show,
070                                  @PathParam(EMPTY) String type)
071        throws HttpResponseException, ClientProtocolException, IOException;
072
073    /**
074     * {@link.uri http://www.silicondust.com/ SiliconDust} HD Homerun Prime
075     * (CableCard) line-up request (providing results in JSON).
076     *
077     * @param   host            The host IP or name.
078     * @param   show            What to show.
079     *
080     * @return  The {@link HttpResponse} containing the line-up.
081     *
082     * @throws  IOException     See {@link ball.http.ProtocolClient}.
083     * @throws  HttpResponseException
084     *                          See {@link ball.http.ProtocolClient}.
085     * @throws  ClientProtocolException
086     *                          See {@link ball.http.ProtocolClient}.
087     */
088    default HttpResponse getLineup(String host,
089                                   String show) throws HttpResponseException,
090                                                       ClientProtocolException,
091                                                       IOException {
092        return getLineup(host, 80, show, "json");
093    }
094
095    /**
096     * {@link.uri http://www.silicondust.com/ SiliconDust} HD Homerun Prime
097     * (CableCard) line-up request.
098     *
099     * @param   host            The host IP or name.
100     * @param   port            The port.
101     *
102     * @return  The {@link HttpResponse} containing the line-up.
103     *
104     * @throws  IOException     See {@link ball.http.ProtocolClient}.
105     * @throws  HttpResponseException
106     *                          See {@link ball.http.ProtocolClient}.
107     * @throws  ClientProtocolException
108     *                          See {@link ball.http.ProtocolClient}.
109     */
110    @GET @Path("lineup.json")
111    public List<LineupEntry> getLineup(@PathParam(EMPTY) String host,
112                                       @PathParam(EMPTY) Integer port)
113        throws HttpResponseException, ClientProtocolException, IOException;
114
115    /**
116     * {@link.uri http://www.silicondust.com/ SiliconDust} HD Homerun Prime
117     * (CableCard) line-up request.
118     *
119     * @param   host            The host IP or name.
120     *
121     * @return  The {@link HttpResponse} containing the line-up.
122     *
123     * @throws  IOException     See {@link ball.http.ProtocolClient}.
124     * @throws  HttpResponseException
125     *                          See {@link ball.http.ProtocolClient}.
126     * @throws  ClientProtocolException
127     *                          See {@link ball.http.ProtocolClient}.
128     */
129    default List<LineupEntry> getLineup(String host) throws HttpResponseException,
130                                                            ClientProtocolException,
131                                                            IOException {
132        return getLineup(host, 80);
133    }
134
135    /**
136     * {@link.uri http://www.silicondust.com/ SiliconDust} HD Homerun Prime
137     * (CableCard) stream ("record") request.
138     *
139     * @param   host            The host IP or name.
140     * @param   port            The port.
141     * @param   tuner           The tuner to use.
142     * @param   channel         The channel to tune.
143     * @param   duration        The time to stream in seconds.
144     *
145     * @return  The {@link HttpResponse} containing the stream.
146     *
147     * @throws  IOException     See {@link ball.http.ProtocolClient}.
148     * @throws  HttpResponseException
149     *                          See {@link ball.http.ProtocolClient}.
150     * @throws  ClientProtocolException
151     *                          See {@link ball.http.ProtocolClient}.
152     */
153    @GET @Path("{tuner}/{channel}")
154    public HttpResponse stream(@PathParam(EMPTY) String host,
155                               @PathParam(EMPTY) Integer port,
156                               @PathParam(EMPTY) String tuner,
157                               @PathParam(EMPTY) String channel,
158                               @QueryParam(EMPTY) Integer duration)
159        throws HttpResponseException, ClientProtocolException, IOException;
160
161    /**
162     * {@link.uri http://www.silicondust.com/ SiliconDust} HD Homerun Prime
163     * (CableCard) stream ("record") request (auto-select tuner).
164     *
165     * @param   host            The host IP or name.
166     * @param   tuner           The tuner to use (may be {@code null}).
167     * @param   channel         The channel to tune.
168     * @param   duration        The time to stream in seconds.
169     *
170     * @return  The {@link HttpResponse} containing the stream.
171     *
172     * @throws  IOException     See {@link ball.http.ProtocolClient}.
173     * @throws  HttpResponseException
174     *                          See {@link ball.http.ProtocolClient}.
175     * @throws  ClientProtocolException
176     *                          See {@link ball.http.ProtocolClient}.
177     */
178    default HttpResponse stream(String host,
179                                Integer tuner,
180                                Integer channel,
181                                Integer duration) throws HttpResponseException,
182                                                         ClientProtocolException,
183                                                         IOException {
184        return stream(host, 5004,
185                      (tuner != null) ? ("tuner" + tuner) : "auto",
186                      "v" + requireNonNull(channel), duration);
187    }
188}