Java源码示例:com.wrapper.spotify.SpotifyApi

示例1
public SpotifyApi getSpotifyApi() {
    if (this.spotifyApi == null) {
        SpotifyApi.Builder builder = new SpotifyApi.Builder()
                .setClientId(clientId)
                .setClientSecret(clientSecret)
                .setRedirectUri(redirectUri);
        if (StringUtils.isNotBlank(accessToken)) {
            builder.setAccessToken(accessToken);
        }
        if (StringUtils.isNotBlank(refreshToken)) {
            builder.setRefreshToken(refreshToken);
        }
        this.spotifyApi = builder.build();
    }
    return spotifyApi;
}
 
示例2
public SpotifyPlayer(SpotifyApi spotifyApi, SpotifyEffectType defaultEffect,
		Color[] defaultPalette, Aurora[] auroras, SpotifyPanel panel,
		PanelCanvas canvas) throws UnauthorizedException,
		HttpRequestException, StatusCodeException
{
	this.spotifyApi = spotifyApi;
	this.defaultPalette = defaultPalette.clone();
	palette = defaultPalette.clone();
	usingDefaultPalette = true;
	this.auroras = auroras;
	this.panel = panel;
	this.canvas = canvas;
	setEffect(defaultEffect);
	if (auroras != null)
	{
		enableExternalStreaming();
		start();
	}
}
 
示例3
public SpotifyAudioSourceManager(YoutubeAudioSourceManager youtubeAudioSourceManager, DunctebotConfig.Apis config) {
    this.config = config;

    final String clientId = config.spotify.clientId;
    final String clientSecret = config.spotify.clientSecret;
    final String youtubeApiKey = config.googl;

    if (clientId == null || clientSecret == null || youtubeApiKey == null) {
        logger.error("Could not load Spotify keys");
        this.spotifyApi = null;
        this.service = null;
        this.youtubeAudioSourceManager = null;
    } else {
        this.youtubeAudioSourceManager = youtubeAudioSourceManager;
        this.spotifyApi = new SpotifyApi.Builder()
            .setClientId(clientId)
            .setClientSecret(clientSecret)
            .build();

        this.service = Executors.newScheduledThreadPool(2, (r) -> new Thread(r, "Spotify-Token-Update-Thread"));
        service.scheduleAtFixedRate(this::updateAccessToken, 0, 1, TimeUnit.HOURS);
    }
}
 
示例4
@Override
public SavedShow createModelObject(JsonObject jsonObject) {
  if (jsonObject == null || jsonObject.isJsonNull()) {
    return null;
  }

  try {
    return new Builder()
      .setAddedAt(
        hasAndNotNull(jsonObject, "added_at")
          ? SpotifyApi.parseDefaultDate(jsonObject.get("added_at").getAsString())
          : null)
      .setShow(
        hasAndNotNull(jsonObject, "show")
          ? new ShowSimplified.JsonUtil().createModelObject(
          jsonObject.getAsJsonObject("show"))
          : null)
      .build();
  } catch (ParseException e) {
    SpotifyApi.LOGGER.log(Level.SEVERE, e.getMessage());
    return null;
  }
}
 
示例5
public SavedTrack createModelObject(JsonObject jsonObject) {
  if (jsonObject == null || jsonObject.isJsonNull()) {
    return null;
  }

  try {
    return new Builder()
      .setAddedAt(
        hasAndNotNull(jsonObject, "added_at")
          ? SpotifyApi.parseDefaultDate(jsonObject.get("added_at").getAsString())
          : null)
      .setTrack(
        hasAndNotNull(jsonObject, "track")
          ? new Track.JsonUtil().createModelObject(
          jsonObject.getAsJsonObject("track"))
          : null)
      .build();
  } catch (ParseException e) {
    SpotifyApi.LOGGER.log(Level.SEVERE, e.getMessage());
    return null;
  }
}
 
示例6
public SavedAlbum createModelObject(JsonObject jsonObject) {
  if (jsonObject == null || jsonObject.isJsonNull()) {
    return null;
  }

  try {
    return new Builder()
      .setAddedAt(
        hasAndNotNull(jsonObject, "added_at")
          ? SpotifyApi.parseDefaultDate(jsonObject.get("added_at").getAsString())
          : null)
      .setAlbum(
        hasAndNotNull(jsonObject, "album")
          ? new Album.JsonUtil().createModelObject(
          jsonObject.getAsJsonObject("album"))
          : null)
      .build();
  } catch (ParseException e) {
    SpotifyApi.LOGGER.log(Level.SEVERE, e.getMessage());
    return null;
  }
}
 
示例7
public PlayHistory createModelObject(JsonObject jsonObject) {
  if (jsonObject == null || jsonObject.isJsonNull()) {
    return null;
  }

  try {
    return new Builder()
      .setTrack(
        hasAndNotNull(jsonObject, "track")
          ? new TrackSimplified.JsonUtil().createModelObject(
          jsonObject.getAsJsonObject("track"))
          : null)
      .setPlayedAt(
        hasAndNotNull(jsonObject, "played_at")
          ? SpotifyApi.parseDefaultDate(jsonObject.get("played_at").getAsString())
          : null)
      .setContext(
        hasAndNotNull(jsonObject, "context")
          ? new Context.JsonUtil().createModelObject(
          jsonObject.getAsJsonObject("context"))
          : null)
      .build();
  } catch (ParseException e) {
    SpotifyApi.LOGGER.log(Level.SEVERE, e.getMessage());
    return null;
  }
}
 
示例8
/**
 * The request build method.
 *
 * @return An {@link AuthorizationCodeUriRequest}.
 */
public AuthorizationCodeUriRequest build() {
  setHost(SpotifyApi.DEFAULT_AUTHENTICATION_HOST);
  setPort(SpotifyApi.DEFAULT_AUTHENTICATION_PORT);
  setScheme(SpotifyApi.DEFAULT_AUTHENTICATION_SCHEME);
  setPath("/authorize");

  return new AuthorizationCodeUriRequest(this);
}
 
示例9
/**
 * The request build method.
 *
 * @return An {@link AuthorizationCodeRefreshRequest}.
 */
public AuthorizationCodeRefreshRequest build() {
  setContentType(ContentType.APPLICATION_FORM_URLENCODED);
  setHost(SpotifyApi.DEFAULT_AUTHENTICATION_HOST);
  setPort(SpotifyApi.DEFAULT_AUTHENTICATION_PORT);
  setScheme(SpotifyApi.DEFAULT_AUTHENTICATION_SCHEME);
  setPath("/api/token");

  return new AuthorizationCodeRefreshRequest(this);
}
 
示例10
/**
 * The request build method.
 *
 * @return An {@link AuthorizationCodeRequest}.
 */
public AuthorizationCodeRequest build() {
  setContentType(ContentType.APPLICATION_FORM_URLENCODED);
  setHost(SpotifyApi.DEFAULT_AUTHENTICATION_HOST);
  setPort(SpotifyApi.DEFAULT_AUTHENTICATION_PORT);
  setScheme(SpotifyApi.DEFAULT_AUTHENTICATION_SCHEME);
  setPath("/api/token");

  return new AuthorizationCodeRequest(this);
}
 
示例11
/**
 * The request build method.
 *
 * @return A {@link ClientCredentialsRequest}.
 */
public ClientCredentialsRequest build() {
  setContentType(ContentType.APPLICATION_FORM_URLENCODED);
  setHost(SpotifyApi.DEFAULT_AUTHENTICATION_HOST);
  setPort(SpotifyApi.DEFAULT_AUTHENTICATION_PORT);
  setScheme(SpotifyApi.DEFAULT_AUTHENTICATION_SCHEME);
  setPath("/api/token");

  return new ClientCredentialsRequest(this);
}
 
示例12
protected AbstractRequest(Builder<T, ?> builder) {
  assert (builder != null);
  assert (builder.path != null);
  assert (!builder.path.equals(""));

  this.httpManager = builder.httpManager;

  URIBuilder uriBuilder = new URIBuilder();
  uriBuilder
    .setScheme(builder.scheme)
    .setHost(builder.host)
    .setPort(builder.port)
    .setPath(builder.path);
  if (builder.queryParameters.size() > 0) {
    uriBuilder
      .setParameters(builder.queryParameters);
  }

  try {
    this.uri = uriBuilder.build();
  } catch (URISyntaxException e) {
    SpotifyApi.LOGGER.log(Level.SEVERE, e.getMessage());
  }

  this.headers = builder.headers;
  this.contentType = builder.contentType;
  this.body = builder.body;
  this.bodyParameters = builder.bodyParameters;
}
 
示例13
public BT setPathParameter(final String name, final String value) {
  assert (name != null && value != null);
  assert (!name.equals("") && !value.equals(""));

  String encodedValue = null;

  try {
    encodedValue = URLEncoder.encode(value, "UTF-8");
  } catch (UnsupportedEncodingException e) {
    SpotifyApi.LOGGER.log(Level.SEVERE, e.getMessage());
  }
  listAddOnce(this.pathParameters, new BasicNameValuePair(name, encodedValue));
  return self();
}
 
示例14
public SpotifyApi getSpotifyApi()
{
	return spotifyApi;
}
 
示例15
public SpotifyPlaylistExporter(Monitor monitor, SpotifyApi spotifyApi) {
  this.monitor = monitor;
  this.spotifyApi = spotifyApi;
}
 
示例16
public SpotifyPlaylistImporter(Monitor monitor, SpotifyApi spotifyApi) {
  this.monitor = monitor;
  this.spotifyApi = spotifyApi;
}
 
示例17
public SpotifyAudioSourceManager(SpotifyCredentials credentials, YoutubeAudioSourceManager youtubeManager) {
    this.api = SpotifyApi.builder().setClientId(credentials.id).setClientSecret(credentials.secret).build();
    this.youtubeManager = youtubeManager;
    this.loaders = Arrays.asList(this::getSpotifyTrack, this::getSpotifyAlbum, this::getSpotifyPlaylist);
}
 
示例18
public PlaylistTrack createModelObject(JsonObject jsonObject) {
  if (jsonObject == null || jsonObject.isJsonNull()) {
    return null;
  }

  try {
    IPlaylistItem track = null;

    if (hasAndNotNull(jsonObject, "track")) {
      final JsonObject trackObj = jsonObject.getAsJsonObject("track");

      if (hasAndNotNull(trackObj, "type")) {
        String type = trackObj.get("type").getAsString().toLowerCase();

        if (type.equals("track")) {
          track = new Track.JsonUtil().createModelObject(trackObj);
        } else if (type.equals("episode")) {
          track = new Episode.JsonUtil().createModelObject(trackObj);
        }
      }
    }

    return new Builder()
      .setAddedAt(
        hasAndNotNull(jsonObject, "added_at")
          ? SpotifyApi.parseDefaultDate(jsonObject.get("added_at").getAsString())
          : null)
      .setAddedBy(
        hasAndNotNull(jsonObject, "added_by")
          ? new User.JsonUtil().createModelObject(
          jsonObject.get("added_by").getAsJsonObject())
          : null)
      .setIsLocal(
        hasAndNotNull(jsonObject, "is_local")
          ? jsonObject.get("is_local").getAsBoolean()
          : null)
      .setTrack(track)
      .build();
  } catch (ParseException e) {
    SpotifyApi.LOGGER.log(Level.SEVERE, e.getMessage());
    return null;
  }
}