Added 2 radios, located in Belo Horizonte city.
[amarok-radio-streams:amarok-brazilian-radios.git] / main.js
1 /*#########################################################################
2 #                                                                         #
3 #   Simple script shamelessly recopied from:                              #
4 #                                                                         #
5 #   Copyright                                                             #
6 #                                                                         #
7 #   (C)  2010 Anselmo Lacerda Silveira de Melo <anselmolsm@gmail.com>     #
8 #   (C)  2010 Emile de Weerd <mederel+radionederland@gmail.com>           #
9 #   (C)  2009 Àlvar Cuevas i Fajardo <alvar@cuevas.cat>                   #
10 #   (C)  2008 Eirik Johansen Bjørgan  <eirikjbj@gmail.com>                #
11 #   (C)  2007, 2008 Nikolaj Hald Nielsen  <nhnFreespirit@gmail.com>       #
12 #   (C)  2008 Peter ZHOU <peterzhoulei@gmail.com>                         #
13 #   (C)  2008 Mark Kretschmann <kretschmann@kde.org>                      #
14 #                                                                         #
15 #   This program is free software; you can redistribute it and/or modify  #
16 #   it under the terms of the GNU General Public License as published by  #
17 #   the Free Software Foundation; either version 2 of the License, or     #
18 #   (at your option) any later version.                                   #
19 #                                                                         #
20 #   This program is distributed in the hope that it will be useful,       #
21 #   but WITHOUT ANY WARRANTY; without even the implied warranty of        #
22 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
23 #   GNU General Public License for more details.                          #
24 #                                                                         #
25 #   You should have received a copy of the GNU General Public License     #
26 #   along with this program; if not, write to the                         #
27 #   Free Software Foundation, Inc.,                                       #
28 #   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         #
29 ##########################################################################*/
30
31 Importer.loadQtBinding("qt.core");
32 Importer.loadQtBinding("qt.gui");
33
34 function Station( name, url )
35 {
36     this.name = name;
37     this.url = url;
38 }
39
40 categories = new Object;
41
42 categories["  Belo Horizonte"]= new Array(
43     new Station( "Band News BH", "http://servidor25.crossdigital.com.br:8000/bandnewsbelohorizonte"),
44     new Station( "CBN BH", "http://wm-sgr-live.globo.com/sgr_off_cbnbh_live.wma"),
45     new Station( "Guarani FM", "http://cdn.upx.net.br/listen/00108.wmx"),
46     new Station( "Antena 1", "mms://wmedialive.telium.com.br/antenaum")
47 );
48
49 categories["  Brasilia"]= new Array(
50     new Station( "Band News BSB", "http://servidor25.crossdigital.com.br:8000/bandnewsbrasilia"),
51     new Station( "CBN BSB", "http://wm-sgr-live.globo.com/sgr_off_cbnbsb_live.wma"),
52     new Station( "Nova Brasil FM", "http://00086.cdn.upx.net.br/listen.wmx")
53 );
54
55 categories["  Campinas"]= new Array(
56     new Station( "Nova Brasil FM", "http://00086.cdn.upx.net.br/listen.wmx")
57 );
58
59 categories["  Curitiba"]= new Array(
60     new Station( "Band News Curitiba", "http://servidor25.crossdigital.com.br:8000/bandnewscuritiba")
61 );
62
63 categories["  Fortaleza"]= new Array(
64     new Station( "Universitária FM", "mms://200.129.35.230:8080/ouvir")
65 );
66
67 categories["  Porto Alegre"]= new Array(
68     new Station( "Band News POA", "http://servidor25.crossdigital.com.br:8000/bandnewsportoalegre"),
69     new Station( "Ipanema FM", "http://65.60.52.122:8700")
70 );
71
72 categories["  Recife"]= new Array(
73     new Station( "Nova Brasil FM", "http://00086.cdn.upx.net.br/listen.wmx")
74 );
75
76 categories["  Rio de Janeiro"]= new Array(
77     new Station( "Band News RJ", "http://servidor25.crossdigital.com.br:8000/bandnewsrj"),
78     new Station( "CBN RJ", "http://wm-sgr-live.globo.com/sgr_off_cbnfmrj_live.wma"),
79     new Station( "Cidade Web Rock", "mms://200.222.115.50/CidadeWebRock_CidadeWebrock128"),
80     new Station( "JBFM", "mms://200.222.115.52/OiFM_JBFM")
81 );
82
83
84 categories["  Sao Paulo"]= new Array(
85     new Station( "Backstage Heavy Rock", "http://67.212.166.210:8424"),
86     new Station( "Backstage Classic Rock", "http://65.60.52.122:8700"),
87     new Station( "Band News SP", "http://servidor25.crossdigital.com.br:8000/bandnewssp"),
88     new Station( "Band FM", "http://servidor24.crossdigital.com.br:8000/bandfm"),
89     new Station( "Bandeirantes AM", "http://servidor25.crossdigital.com.br:8000/bandeirantesam"),
90     new Station( "CBN SP", "http://wm-sgr-live.globo.com/sgr_off_cbnfmsp_live.wma"),
91     new Station( "Jovem Pan AM", "mms://p.mm.uol.com.br/ampan"),
92     new Station( "Kiss FM", "http://75.126.86.2:8098/"),
93     new Station( "Nativa", "http://servidor25.crossdigital.com.br:8000/nativafm"),
94     new Station( "Nova Brasil FM", "http://00086.cdn.upx.net.br/listen.wmx"),
95     new Station( "Rádio Mitsubishi", "http://servidor24.crossdigital.com.br:8000/mtsubishifm"),
96     new Station( "Rádio Trânsito", "http://74.86.203.122:8000/radiotransito")
97 );
98
99 categories["  Salvador"]= new Array(
100     new Station( "Band News Salvador", "http://servidor25.crossdigital.com.br:8000/bandnewssalvador"),
101     new Station( "Nova Brasil FM", "http://00086.cdn.upx.net.br/listen.wmx")
102 );
103
104 function BrazilianRadios()
105 {
106     ScriptableServiceScript.call( this, "Brazilian Radios", 2, "List of Brazilian radios", "A collection of radios from many cities in Brazil", true);
107     Amarok.debug( "ok." );
108 }
109
110
111 function onConfigure()
112 {
113     Amarok.alert( "This script does not require configuring." );
114 }
115
116 function onPopulating( level, callbackData, filter )
117 {
118         // For some reason Amarok appends a "%20", remove it
119         filter = filter.toLowerCase().replace("%20","");
120
121         if ( level == 1 )
122         {
123                 for( att in categories )
124                 {
125                         if(filter.length > 0)
126                         {
127                                 var hasItems = false;
128                                 var stationArray = categories[att];
129                                 for ( i = 0; i < stationArray.length; i++ )
130                                 {
131                                         if(stationArray[i].name.toLowerCase().indexOf(filter) != -1)
132                                         {
133                                                 hasItems = true;
134                                                 break;
135                                         }
136                                 }
137                                 if(!hasItems) continue;
138                         }
139
140                         var cover = Amarok.Info.scriptPath() + "/" + "radio.png";
141                         Amarok.debug ("att: " + att + ", " + categories[att].name);
142
143                         item = Amarok.StreamItem;
144                         item.level = 1;
145                         item.callbackData = att;
146                         item.itemName = att;
147                         item.playableUrl = "";
148                         item.infoHtml = "";
149                         item.coverUrl = cover;
150                         script.insertItem( item );
151
152                 }
153                 script.donePopulating();
154         }
155         else if ( level == 0 )
156         {
157                 Amarok.debug( " Populating station level..." );
158                 //add the station streams as leaf nodes
159
160                 var stationArray = categories[callbackData];
161
162                 for ( i = 0; i < stationArray.length; i++ )
163                 {
164                         name = stationArray[i].name;
165                         if(name.toLowerCase().indexOf(filter) == -1) continue;
166                         item = Amarok.StreamItem;
167                         item.level = 0;
168                         item.callbackData = "";
169                         item.itemName = stationArray[i].name;
170                         item.playableUrl = stationArray[i].url;
171                         item.album = stationArray[i].name;
172                                                         item.artist = "Radio Stream";
173                                                         item.coverUrl = cover;
174                         script.insertItem( item );
175                 }
176                 script.donePopulating();
177         }
178 }
179
180 function onCustomize() {
181     var currentDir = Amarok.Info.scriptPath() + "/";
182     var iconPixmap = new QPixmap(currentDir+"icon.png");
183     script.setIcon(iconPixmap);
184 }
185
186 Amarok.configured.connect( onConfigure );
187
188 script = new BrazilianRadios();
189 script.populate.connect( onPopulating );
190 script.customize.connect( onCustomize );