Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tobiass.audioaddict.api;
- import java.net.HttpURLConnection;
- import java.net.Proxy;
- import java.net.URL;
- import java.util.Random;
- /**
- * ListenKeyValRequest.java
- * @author _Tobias
- */
- public class ListenKeyValRequest {
- private String key = null;
- private boolean async = true;
- private onFinishListener mFinishListener = null;
- private Proxy mProxy = null;
- private Random mRandom = new Random();
- public ListenKeyValRequest(String listenkey) {
- key = listenkey;
- }
- public ListenKeyValRequest setAsync(boolean arg) {
- async = arg;
- return this;
- }
- public ListenKeyValRequest setListenKey(String arg) {
- key = arg;
- return this;
- }
- public ListenKeyValRequest setProxy(Proxy arg) {
- mProxy = arg;
- return this;
- }
- public ListenKeyValRequest setOnFinishListener(onFinishListener arg) {
- mFinishListener = arg;
- return this;
- }
- public ListenKeyValRequest start() {
- if(key == null) {
- return this;
- }
- Runnable r = new Runnable() {
- public void run() {
- int res = getStatusCode(getStreamUrl()+"?"+key);
- if(res == -1) {
- callFinish(KeyState.FAILURE);
- }
- else if(res == 200) {
- callFinish(KeyState.PREMIUM);
- }
- else if(res == 401) {
- res = getStatusCode("http://listen.di.fm/premium/favorites?"+key);
- if(res == 200) {
- callFinish(KeyState.FREE);
- }
- else if(res == 403) {
- callFinish(KeyState.INVALID);
- }
- else if(res == -1) {
- callFinish(KeyState.FAILURE);
- }
- }
- }
- };
- if(async) {
- new Thread(r).start();
- }
- else {
- r.run();
- }
- return this;
- }
- private int getStatusCode(String url) {
- try {
- HttpURLConnection conn;
- if(mProxy != null) {
- conn = (HttpURLConnection) new URL(url).openConnection(mProxy);
- }
- else {
- conn = (HttpURLConnection) new URL(url).openConnection();
- }
- int code = conn.getResponseCode();
- conn.disconnect();
- return code;
- } catch (Exception e) {
- return -1;
- }
- }
- private String getStreamUrl() {
- String[] urls = {"http://prem2.di.fm:80/chillhop","http://prem4.di.fm:80/chillhop","http://prem1.di.fm:80/chillhop","http://prem2.di.fm:80/downtempolounge","http://prem1.di.fm:80/downtempolounge","http://prem4.di.fm:80/downtempolounge","http://prem2.di.fm:80/trap","http://prem1.di.fm:80/trap","http://prem4.di.fm:80/trap","http://prem2.di.fm:80/sankeys","http://prem4.di.fm:80/sankeys","http://prem1.di.fm:80/sankeys","http://prem2.di.fm:80/trance","http://prem1.di.fm:80/trance","http://prem4.di.fm:80/trance","http://prem2.di.fm:80/vocaltrance","http://prem1.di.fm:80/vocaltrance","http://prem4.di.fm:80/vocaltrance","http://prem2.di.fm:80/lounge","http://prem1.di.fm:80/lounge","http://prem4.di.fm:80/lounge","http://prem2.di.fm:80/chillout","http://prem1.di.fm:80/chillout","http://prem4.di.fm:80/chillout","http://prem2.di.fm:80/vocalchillout","http://prem1.di.fm:80/vocalchillout","http://prem4.di.fm:80/vocalchillout","http://prem2.di.fm:80/progressive","http://prem1.di.fm:80/progressive","http://prem4.di.fm:80/progressive","http://prem2.di.fm:80/house","http://prem1.di.fm:80/house","http://prem4.di.fm:80/house","http://prem2.di.fm:80/mainstage","http://prem1.di.fm:80/mainstage","http://prem4.di.fm:80/mainstage","http://prem2.di.fm:80/umfradio","http://prem4.di.fm:80/umfradio","http://prem1.di.fm:80/umfradio","http://prem2.di.fm:80/minimal","http://prem1.di.fm:80/minimal","http://prem4.di.fm:80/minimal","http://prem2.di.fm:80/harddance","http://prem1.di.fm:80/harddance","http://prem4.di.fm:80/harddance","http://prem2.di.fm:80/eurodance","http://prem1.di.fm:80/eurodance","http://prem4.di.fm:80/eurodance","http://prem2.di.fm:80/techhouse","http://prem1.di.fm:80/techhouse","http://prem4.di.fm:80/techhouse","http://prem2.di.fm:80/electrohouse","http://prem1.di.fm:80/electrohouse","http://prem4.di.fm:80/electrohouse","http://prem2.di.fm:80/bigroomhouse","http://prem4.di.fm:80/bigroomhouse","http://prem1.di.fm:80/bigroomhouse","http://prem2.di.fm:80/psychill","http://prem1.di.fm:80/psychill","http://prem4.di.fm:80/psychill","http://prem2.di.fm:80/goapsy","http://prem1.di.fm:80/goapsy","http://prem4.di.fm:80/goapsy","http://prem2.di.fm:80/progressivepsy","http://prem4.di.fm:80/progressivepsy","http://prem1.di.fm:80/progressivepsy","http://prem2.di.fm:80/hardcore","http://prem1.di.fm:80/hardcore","http://prem4.di.fm:80/hardcore","http://prem2.di.fm:80/djmixes","http://prem1.di.fm:80/djmixes","http://prem4.di.fm:80/djmixes","http://prem2.di.fm:80/russianclubhits","http://prem1.di.fm:80/russianclubhits","http://prem4.di.fm:80/russianclubhits","http://prem2.di.fm:80/ambient","http://prem1.di.fm:80/ambient","http://prem4.di.fm:80/ambient","http://prem2.di.fm:80/drumandbass","http://prem1.di.fm:80/drumandbass","http://prem4.di.fm:80/drumandbass","http://prem2.di.fm:80/eclectronica","http://prem1.di.fm:80/eclectronica","http://prem4.di.fm:80/eclectronica","http://prem2.di.fm:80/classicelectronica","http://prem1.di.fm:80/classicelectronica","http://prem4.di.fm:80/classicelectronica","http://prem2.di.fm:80/epictrance","http://prem4.di.fm:80/epictrance","http://prem1.di.fm:80/epictrance","http://prem2.di.fm:80/ukgarage","http://prem4.di.fm:80/ukgarage","http://prem1.di.fm:80/ukgarage","http://prem2.di.fm:80/breaks","http://prem1.di.fm:80/breaks","http://prem4.di.fm:80/breaks","http://prem2.di.fm:80/cosmicdowntempo","http://prem1.di.fm:80/cosmicdowntempo","http://prem4.di.fm:80/cosmicdowntempo","http://prem2.di.fm:80/techno","http://prem1.di.fm:80/techno","http://prem4.di.fm:80/techno","http://prem2.di.fm:80/soulfulhouse","http://prem1.di.fm:80/soulfulhouse","http://prem4.di.fm:80/soulfulhouse","http://prem2.di.fm:80/deephouse","http://prem4.di.fm:80/deephouse","http://prem1.di.fm:80/deephouse","http://prem2.di.fm:80/deeptech","http://prem1.di.fm:80/deeptech","http://prem4.di.fm:80/deeptech","http://prem2.di.fm:80/tribalhouse","http://prem1.di.fm:80/tribalhouse","http://prem4.di.fm:80/tribalhouse","http://prem2.di.fm:80/funkyhouse","http://prem1.di.fm:80/funkyhouse","http://prem4.di.fm:80/funkyhouse","http://prem2.di.fm:80/deepnudisco","http://prem1.di.fm:80/deepnudisco","http://prem4.di.fm:80/deepnudisco","http://prem2.di.fm:80/spacemusic","http://prem1.di.fm:80/spacemusic","http://prem4.di.fm:80/spacemusic","http://prem2.di.fm:80/hardstyle","http://prem1.di.fm:80/hardstyle","http://prem4.di.fm:80/hardstyle","http://prem2.di.fm:80/chilloutdreams","http://prem1.di.fm:80/chilloutdreams","http://prem4.di.fm:80/chilloutdreams","http://prem2.di.fm:80/liquiddnb","http://prem1.di.fm:80/liquiddnb","http://prem4.di.fm:80/liquiddnb","http://prem2.di.fm:80/darkdnb","http://prem4.di.fm:80/darkdnb","http://prem1.di.fm:80/darkdnb","http://prem2.di.fm:80/classiceurodance","http://prem1.di.fm:80/classiceurodance","http://prem4.di.fm:80/classiceurodance","http://prem2.di.fm:80/handsup","http://prem1.di.fm:80/handsup","http://prem4.di.fm:80/handsup","http://prem2.di.fm:80/club","http://prem1.di.fm:80/club","http://prem4.di.fm:80/club","http://prem2.di.fm:80/classictrance","http://prem1.di.fm:80/classictrance","http://prem4.di.fm:80/classictrance","http://prem2.di.fm:80/classicvocaltrance","http://prem1.di.fm:80/classicvocaltrance","http://prem4.di.fm:80/classicvocaltrance","http://prem2.di.fm:80/clubdubstep","http://prem4.di.fm:80/clubdubstep","http://prem1.di.fm:80/clubdubstep","http://prem2.di.fm:80/dubstep","http://prem1.di.fm:80/dubstep","http://prem4.di.fm:80/dubstep","http://prem2.di.fm:80/liquiddubstep","http://prem1.di.fm:80/liquiddubstep","http://prem4.di.fm:80/liquiddubstep","http://prem2.di.fm:80/glitchhop","http://prem1.di.fm:80/glitchhop","http://prem4.di.fm:80/glitchhop","http://prem2.di.fm:80/discohouse","http://prem1.di.fm:80/discohouse","http://prem4.di.fm:80/discohouse","http://prem2.di.fm:80/classiceurodisco","http://prem1.di.fm:80/classiceurodisco","http://prem4.di.fm:80/classiceurodisco","http://prem2.di.fm:80/futuresynthpop","http://prem1.di.fm:80/futuresynthpop","http://prem4.di.fm:80/futuresynthpop","http://prem2.di.fm:80/latinhouse","http://prem1.di.fm:80/latinhouse","http://prem4.di.fm:80/latinhouse","http://prem2.di.fm:80/oldschoolacid","http://prem1.di.fm:80/oldschoolacid","http://prem4.di.fm:80/oldschoolacid","http://prem2.di.fm:80/chiptunes","http://prem1.di.fm:80/chiptunes","http://prem4.di.fm:80/chiptunes"};
- return urls[getRandomBetween(0, urls.length-1, mRandom)];
- }
- private int getRandomBetween(int a, int b, Random r) {
- return a+r.nextInt(b-a+1);
- }
- private void callFinish(KeyState arg) {
- if(mFinishListener != null) {
- mFinishListener.on(arg);
- }
- }
- public interface onFinishListener {
- public void on(KeyState arg);
- }
- public enum KeyState {
- PREMIUM, FREE, INVALID, FAILURE
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement