4545import tv .bouyguestelecom .fr .bboxapilibrary .callback .IBboxMedia ;
4646import tv .bouyguestelecom .fr .bboxapilibrary .callback .IBboxMessage ;
4747import tv .bouyguestelecom .fr .bboxapilibrary .callback .IBboxRegisterApp ;
48+ import tv .bouyguestelecom .fr .bboxapilibrary .callback .IBboxSearchEpgByExternalId ;
4849import tv .bouyguestelecom .fr .bboxapilibrary .callback .IBboxSearchEpgBySummary ;
4950import tv .bouyguestelecom .fr .bboxapilibrary .callback .IBboxSendMessage ;
5051import tv .bouyguestelecom .fr .bboxapilibrary .callback .IBboxSetVolume ;
@@ -79,8 +80,8 @@ public class Bbox implements IBbox {
7980 private static final String URL_SESSION_ID = URL_API_BOX + "/security/sessionId" ;
8081 private static final String URL_GET_APPLICATIONS = URL_API_BOX + "/applications" ;
8182 private static final String LOCAL_URL_GET_CHANNELS = URL_API_BOX + "/media/tvchannellist" ;
82- // private static final String LOCAL_URL_GET_TODAY_EPG = URL_API_BOX + "/media/programs";
83- // private static final String LOCAL_URL_GET_EPG_BY_ID = URL_API_BOX + "/media/program";
83+ // private static final String LOCAL_URL_GET_TODAY_EPG = URL_API_BOX + "/media/programs";
84+ // private static final String LOCAL_URL_GET_EPG_BY_ID = URL_API_BOX + "/media/program";
8485 private static final String URL_GET_CURRENT_CHANNEL = URL_API_BOX + "/media" ;
8586 private static final String URL_REGISTER_APP = URL_API_BOX + "/applications/register" ;
8687 private static final String URL_NOTIFICATION = URL_API_BOX + "/notification" ;
@@ -91,26 +92,20 @@ public class Bbox implements IBbox {
9192 private static final String URL_VOLUME = URL_API_BOX + "/userinterface/volume" ;
9293
9394 private static Bbox instance ;
94-
95+ private static int ALLEPG = 0 ;
96+ private static int CURRENTEPG = 1 ;
97+ private static int SELECTEDEPG = 2 ;
9598 private OkHttpClient mClient ;
96-
9799 private WebSocket mWebSocket ;
98-
99100 private String mSessionId ;
100101 private String mToken ;
101102 private Long mValidityToken = (long ) -1 ;
102103 private Long mValiditySessionId = (long ) -1 ;
103104 private boolean hasSecurity = true ;
104-
105-
106105 private ListenerList <IBboxMedia > notifMedia = new ListenerList <>();
107106 private ListenerList <IBboxApplication > notifApps = new ListenerList <>();
108107 private ListenerList <IBboxMessage > notifMsg = new ListenerList <>();
109108
110- private static int ALLEPG = 0 ;
111- private static int CURRENTEPG = 1 ;
112- private static int SELECTEDEPG = 2 ;
113-
114109
115110 private Bbox () {
116111 mClient = new OkHttpClient ();
@@ -199,8 +194,9 @@ public void onResponse(Call call, Response response) throws IOException {
199194 mSessionId = response .headers ().get ("x-sessionid" );
200195 mValiditySessionId = System .currentTimeMillis () + 60 * 1000 ;
201196 iBboxGetSessionId .onResponse (mSessionId );
202- } else { int responseCode = response .code ();
203- Log .w (TAG , "Cannot obtain bboxapi sessionId: " +responseCode );
197+ } else {
198+ int responseCode = response .code ();
199+ Log .w (TAG , "Cannot obtain bboxapi sessionId: " + responseCode );
204200 mSessionId = null ;
205201 mValiditySessionId = (long ) -1 ;
206202 iBboxGetSessionId .onFailure (call .request (), response .code ());
@@ -600,6 +596,7 @@ public void onFailure(Request request, int errorCode) {
600596 }
601597 });
602598 }
599+
603600 @ Override
604601 public void getRecommendationsTV (final String appId , final String appSecret , final String user , final Univers [] universes , final int limit ,
605602 final IBboxGetRecommendationTv iBboxGetRecommendationTv ) {
@@ -620,12 +617,12 @@ public void onResponse(String token) {
620617
621618 urlBuilder .addPathSegment (pathSegment );
622619
623- StringBuilder universesStr = new StringBuilder ();
620+ StringBuilder universesStr = new StringBuilder ();
624621 for (Univers univers : universes ) {
625622 universesStr .append (univers .getValue ());
626623 universesStr .append (',' );
627624 }
628- universesStr .deleteCharAt (universesStr .length ()- 1 );
625+ universesStr .deleteCharAt (universesStr .length () - 1 );
629626 urlBuilder .addPathSegment (universesStr .toString ());
630627 urlBuilder .addQueryParameter ("limit" , String .valueOf (limit ));
631628
@@ -903,7 +900,6 @@ public void removeMsgListener(String ip, String appId, String channelListenerId)
903900 }
904901
905902
906-
907903 private String buildJsonRequestToken (String appId , String appSecret ) {
908904 JSONObject jObject = new JSONObject ();
909905 try {
@@ -1383,7 +1379,6 @@ public void onFailure(Request request, int errorCode) {
13831379 }
13841380
13851381
1386-
13871382 @ Override
13881383 public void unsubscribeNotification (final String ip , String appId , String appSecret , final String channelId ,
13891384 final IBboxUnsubscribe iBboxUnsubscribe ) {
@@ -1475,6 +1470,113 @@ public void onFailure(Request request, int errorCode) {
14751470 }
14761471
14771472
1473+ @ Override
1474+ public void SearchEpgByExternalId (String ip , String appid , String appSecret , final String token , final String period , final String profil , final int typeEpg , final String epgChannelNumber , final String externalId , final IBboxSearchEpgByExternalId iBboxSearchEpgByExternalId ) {
1475+
1476+ Bbox .getInstance ().getCurrentChannel (ip , appid , appSecret , new IBboxGetCurrentChannel () {
1477+ @ Override
1478+ public void onResponse (Channel channel ) {
1479+ if (channel != null && "play" .equals (channel .getMediaState ())) {
1480+ Log .v (TAG , "Get curent channel ==> " + channel .toString ());
1481+ getChanelForExternalId (token , profil , channel .getName (), period , typeEpg , epgChannelNumber , externalId , iBboxSearchEpgByExternalId );
1482+ }
1483+ }
1484+
1485+ @ Override
1486+ public void onFailure (Request request , int i ) {
1487+ Log .e (TAG , "Get current channels failure " + i );
1488+ }
1489+ });
1490+ }
1491+
1492+
1493+ /*
1494+ @epgChannelNumber set to null if @typeEpg = 0 or 1
1495+ @typeEpg 0 all
1496+ 1 current channel
1497+ 2 list epg need to set epgChannelNumber
1498+ */
1499+
1500+ private void getChanelForExternalId (final String token , final String profil , String name , final String period , final int typeEpg , final String epgChannelNumber , final String externalId , final IBboxSearchEpgByExternalId iBboxSearchEpgByExternalId ) {
1501+ OkHttpClient httpClient = new OkHttpClient ();
1502+ HttpUrl .Builder urlBuilder = HttpUrl .parse (URL_GET_CHANNELS ).newBuilder ();
1503+ urlBuilder .addQueryParameter ("profil" , profil );
1504+ urlBuilder .addQueryParameter ("name" , name );
1505+
1506+ Request request = new Request .Builder ()
1507+ .url (urlBuilder .build ().toString ())
1508+ .addHeader ("x-token" , token )
1509+ .build ();
1510+
1511+ Call call = httpClient .newCall (request );
1512+
1513+ call .enqueue (new okhttp3 .Callback () {
1514+ @ Override
1515+ public void onFailure (okhttp3 .Call call , IOException e ) {
1516+ Log .e (TAG , "Get ChanelForExternalId failure" );
1517+ iBboxSearchEpgByExternalId .onFailure (call .request (), HttpURLConnection .HTTP_BAD_REQUEST );
1518+ }
1519+
1520+ @ Override
1521+ public void onResponse (okhttp3 .Call call , okhttp3 .Response response ) throws IOException {
1522+ if (response .code () == HttpURLConnection .HTTP_OK ) {
1523+ List <Channel > channels = Parser .parseChannels (response );
1524+
1525+ if (!channels .isEmpty ()) {
1526+ Log .v (TAG , "Get ChanelForExternalId ==> : " + channels .toString ());
1527+ if (typeEpg == ALLEPG )
1528+ getDetailProgramForExternalId (token , period , profil , null , externalId , iBboxSearchEpgByExternalId );
1529+ else if (typeEpg == CURRENTEPG )
1530+ getDetailProgramForExternalId (token , period , profil , String .valueOf (channels .get (0 ).getEpgChannelNumber ()), externalId , iBboxSearchEpgByExternalId );
1531+
1532+ else if (typeEpg == SELECTEDEPG )
1533+ getDetailProgramForExternalId (token , period , profil , epgChannelNumber , externalId , iBboxSearchEpgByExternalId );
1534+
1535+ }
1536+ }
1537+ }
1538+ });
1539+ }
1540+
1541+ private void getDetailProgramForExternalId (String token , String period , String profil , String epgChannelNumber , String externalId , final IBboxSearchEpgByExternalId iBboxSearchEpgByExternalId ) {
1542+ OkHttpClient httpClient = new OkHttpClient ();
1543+ HttpUrl .Builder urlBuilder = HttpUrl .parse (URL_GET_EPG ).newBuilder ();
1544+ urlBuilder .addQueryParameter ("period" , period );
1545+ urlBuilder .addQueryParameter ("profil" , profil );
1546+ if (epgChannelNumber != null && !epgChannelNumber .isEmpty ())
1547+ urlBuilder .addQueryParameter ("epgChannelNumber" , epgChannelNumber );
1548+ urlBuilder .addQueryParameter ("externalId" , externalId );
1549+
1550+ Request request = new Request .Builder ()
1551+ .url (urlBuilder .build ().toString ())
1552+ .addHeader ("x-token" , token )
1553+ .build ();
1554+
1555+ Call call = httpClient .newCall (request );
1556+
1557+ call .enqueue (new okhttp3 .Callback () {
1558+ @ Override
1559+ public void onFailure (okhttp3 .Call call , IOException e ) {
1560+ Log .e (TAG , "Get DetailProgramForExternalId failure" );
1561+ iBboxSearchEpgByExternalId .onFailure (call .request (), HttpURLConnection .HTTP_BAD_REQUEST );
1562+ }
1563+
1564+ @ Override
1565+ public void onResponse (okhttp3 .Call call , okhttp3 .Response response ) throws IOException {
1566+ if (response .code () == HttpURLConnection .HTTP_OK ) {
1567+
1568+ List <Epg > detailEpg = Parser .parseJsonListEpg (response );
1569+ if (!detailEpg .isEmpty ()) {
1570+ Log .v (TAG , "Get DetailProgramForExternalId" );
1571+ iBboxSearchEpgByExternalId .onResponse (detailEpg );
1572+ }
1573+ }
1574+ }
1575+ });
1576+ }
1577+
1578+
1579+
14781580
14791581
14801582 /*
@@ -1503,9 +1605,9 @@ public void onFailure(Request request, int i) {
15031605 });
15041606 }
15051607
1506- private void getChanel (final String token , final String profil , String name , final String period , final int typeEpg , final String epgChannelNumber , final String longSummary , final IBboxSearchEpgBySummary iBboxSearchEpgBySummary ) {
1608+ private void getChanel (final String token , final String profil , String name , final String period , final int typeEpg , final String epgChannelNumber , final String longSummary , final IBboxSearchEpgBySummary iBboxSearchEpgBySummary ) {
15071609 OkHttpClient httpClient = new OkHttpClient ();
1508- HttpUrl .Builder urlBuilder = HttpUrl .parse ("https://api.bbox.fr/v1.3/media/channels" ).newBuilder ();
1610+ HttpUrl .Builder urlBuilder = HttpUrl .parse (URL_GET_CHANNELS ).newBuilder ();
15091611 urlBuilder .addQueryParameter ("profil" , profil );
15101612 urlBuilder .addQueryParameter ("name" , name );
15111613
@@ -1531,7 +1633,7 @@ public void onResponse(okhttp3.Call call, okhttp3.Response response) throws IOEx
15311633 if (!channels .isEmpty ()) {
15321634 Log .v (TAG , "Get channels ==> : " + channels .toString ());
15331635 if (typeEpg == ALLEPG )
1534- getDetailProgram (token , period , profil , null , longSummary ,iBboxSearchEpgBySummary );
1636+ getDetailProgram (token , period , profil , null , longSummary , iBboxSearchEpgBySummary );
15351637 else if (typeEpg == CURRENTEPG )
15361638 getDetailProgram (token , period , profil , String .valueOf (channels .get (0 ).getEpgChannelNumber ()), longSummary , iBboxSearchEpgBySummary );
15371639
@@ -1544,9 +1646,9 @@ else if (typeEpg == SELECTEDEPG)
15441646 });
15451647 }
15461648
1547- private void getDetailProgram (String token , String period , String profil , String epgChannelNumber , String longSummary ,final IBboxSearchEpgBySummary iBboxSearchEpgBySummary ) {
1649+ private void getDetailProgram (String token , String period , String profil , String epgChannelNumber , String longSummary , final IBboxSearchEpgBySummary iBboxSearchEpgBySummary ) {
15481650 OkHttpClient httpClient = new OkHttpClient ();
1549- HttpUrl .Builder urlBuilder = HttpUrl .parse ("https://api.bbox.fr/v1.3/media/live" ).newBuilder ();
1651+ HttpUrl .Builder urlBuilder = HttpUrl .parse (URL_GET_EPG ).newBuilder ();
15501652 urlBuilder .addQueryParameter ("period" , period );
15511653 urlBuilder .addQueryParameter ("profil" , profil );
15521654 if (epgChannelNumber != null && !epgChannelNumber .isEmpty ())
@@ -1582,8 +1684,6 @@ public void onResponse(okhttp3.Call call, okhttp3.Response response) throws IOEx
15821684 }
15831685
15841686
1585-
1586-
15871687 private String buildJsonRequestMessage (String appId , String msg ) {
15881688 JSONObject jObject = new JSONObject ();
15891689 try {
0 commit comments