Skip to content

Commit

Permalink
Upgrade deps, retry get track
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasVolkmann committed Mar 8, 2020
1 parent d827f72 commit 725d50a
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ image: gradle:alpine

variables:
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
VERSION: "0.9.2"
VERSION: "0.9.3"

before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
Expand Down
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
# Spotify + Reddit = Spottit
![Spottit Logo](resources/img/spottit-logo-drawn-cropped.png?raw=true "Spottit Logo")
[![Build Status](https://travis-ci.com/AndreasVolkmann/spotify-reddit.svg?branch=master)](https://travis-ci.com/AndreasVolkmann/spotify-reddit)
[![GitHub release](https://img.shields.io/badge/Version-0.9.2-blue.svg)](https://github.com/AndreasVolkmann/spotify-reddit/releases/)
[![GitHub release](https://img.shields.io/badge/Version-0.9.3-blue.svg)](https://github.com/AndreasVolkmann/spotify-reddit/releases/)
[![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy)

Dynamic Spotify playlists, based on Reddit. Easily set up your own subreddit playlist.
Dynamic Spotify playlists, based on Reddit. Easily set up your own subreddit playlist.

Follow [Reddit Electronic Music's Spotify](https://open.spotify.com/user/8j1md7p5ntsj62xu2yeapolfi?si=qj_fqiZYTYeXKUzN9mUxCA)
to see some of the generated playlists.

### Table of Contents
* [How to use](#how-to-use)
* [Configuration](#configuration)
* [Deployment](#deployment)
### Table of Contents
* [How to use](#how-to-use)
* [Configuration](#configuration)
* [Deployment](#deployment)

### How to use
To use the program, define your own `config.yml` and run the program with `-c ${PATH_TO_YOUR_CONFIG.YML}`.
The following assumes that your config is called config.yml and is located in the same directory as the jar.

Before running for the first time, you need to authorize the application.
Before running for the first time, you need to authorize the application.

Run with `-ma`: `java -jar spottit-${version}.jar -c config.yml -ma`

This will obtain a refresh token, so that you do not need to authorize again.
This will obtain a refresh token, so that you do not need to authorize again.

Once this is done, you can omit the `-ma`. The application should now update the playlists.
It is also possible to specify the refresh token via an environment variable called `REFRESH_TOKEN`.

It is also possible to specify the refresh token via an environment variable called `REFRESH_TOKEN`.


### Configuration
To customize the application, edit the
To customize the application, edit the
[example_config.yml](https://github.com/AndreasVolkmann/spotify-reddit/blob/master/example_config.yml)
and fill in your own information.

Expand Down Expand Up @@ -66,7 +66,7 @@ playlists:
sort: TOP
timePeriod: ALL
# Omit minUpvotes to allow any reddit post to be added

# set this to true, if the playlist is private
isPrivate: true

Expand Down Expand Up @@ -97,7 +97,7 @@ The last part is your playlist's ID.
##### Tag Filtering
Some subreddits make extensive use of tags, which basically means anything that is captured in parenthesis `()` `[]`.

The `tagFilter` can be declared at playlist level and is used to filter out reddit posts based on their tags.
The `tagFilter` can be declared at playlist level and is used to filter out reddit posts based on their tags.

Example config:
```yaml
Expand All @@ -109,25 +109,25 @@ playlists:
# Example post that would be included: [FRESH] Luca Brasi - Clothes I Slept In
includeExact:
- FRESH
# Tag contains
# Example post that would be included: Foghorns - All Glands on Deck (indie/folk/punk)
include:
- punk
# Tag must not be equal
# Example post that would be excluded: [Album] Maps & Atlases - Lightlessness Is Nothing New
excludeExact:
- Album
# Tag must not include
# Example post that would be excluded: [FRESH VIDEO] Preoccupations - Decompose
exclude:
# Example post that would be excluded: [FRESH VIDEO] Preoccupations - Decompose
exclude:
- video
```

##### Date Filtering
Sometimes you want to only add tracks that match a certain date criteria.
Sometimes you want to only add tracks that match a certain date criteria.

The `dateFilter` can be declared at playlist level and supports different ways of checking a track's release date.

Expand All @@ -139,7 +139,7 @@ playlists:
dateFilter:
# Tracks that have been released since the beginning of 2018
startingFrom: 2018-01-01
# The release date can not exceed the current date minus the specified distance
# Given a maxDistance of 1 month and 1 year, a track may not be older than 1 month and 1 year
# Given the current date of 2018-06-16, include only tracks that are released since 2017-05-16
Expand All @@ -149,7 +149,7 @@ playlists:
```

##### Scheduling
As a solution to the limited Heroku Scheduler frequency options, one can specify an execution schedule in the config.
As a solution to the limited Heroku Scheduler frequency options, one can specify an execution schedule in the config.

Use `schedule` to define when the lists should be updated. If the current date doesn't match, the program won't run.

Expand All @@ -161,7 +161,7 @@ playlists:
schedule:
# Only execute on Mondays
dayOfWeek: MONDAY
# Only execute on the first day of the month, for example 2018-06-01
dayOfMonth: 1
```
Expand Down Expand Up @@ -198,7 +198,7 @@ More details about deploying to Heroku below.
* Set the frequency to `Every 10 minutes` and save
* In order to see the output, use `heroku logs --ps scheduler` from your local project. See more [here](https://devcenter.heroku.com/articles/scheduler#inspecting-output)
* Once everything works, edit your job and pass your config `java -jar build/libs/spottit-0.7.0.jar -c config.yml`
* Currently, the Heroku Scheduler has limited frequency options. Use a daily frequency and specify details in your `config.yml`.
* Currently, the Heroku Scheduler has limited frequency options. Use a daily frequency and specify details in your `config.yml`.
See [the Scheduling section](#scheduling)

![Spottit Heroku Scheduler](resources/img/spottit-heroku-scheduler.PNG?raw=true "Spottit Heroku Scheduler")
27 changes: 13 additions & 14 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.40'
id "com.github.ben-manes.versions" version "0.21.0"
id 'org.springframework.boot' version '2.1.6.RELEASE'
id 'org.jetbrains.kotlin.jvm' version '1.3.70'
id "com.github.ben-manes.versions" version "0.28.0"
id 'org.springframework.boot' version '2.2.5.RELEASE'
}

ext {
ktor_version = '1.1.3'
spotify_api_vesrion = '2.2.0'
ktor_version = '1.3.1'
spotify_api_vesrion = '4.2.1'
jrawVersion = '1.1.0'
junit_version = '5.5.0-M1'
junit_version = '5.6.0'
}

group 'me.avo'
version '0.9.2'
version '0.9.3'

task stage(dependsOn: ['bootJar', 'clean'])
build.mustRunAfter clean
Expand All @@ -29,20 +29,19 @@ dependencies {
compile "net.dean.jraw:JRAW:$jrawVersion"

/* Server */
compile group: "io.ktor", name: "ktor-server-core", version: ktor_version
compile group: "io.ktor", name: "ktor-server-cio", version: ktor_version
compile "io.ktor:ktor-freemarker:$ktor_version"

/* Util */
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
compile 'org.kodein.di:kodein-di-generic-jvm:6.2.0'
compile 'org.kodein.di:kodein-di-generic-jvm:6.5.3'
compile 'com.github.salomonbrys.kotson:kotson:2.5.0'
compile 'org.yaml:snakeyaml:1.24'
compile 'com.apurebase:arkenv:2.0.0'
compile 'org.apache.commons:commons-text:1.6'
compile 'org.yaml:snakeyaml:1.25'
compile 'com.apurebase:arkenv:3.1.0'
compile 'org.apache.commons:commons-text:1.8'

testImplementation "io.strikt:strikt-core:0.21.0"
testCompile group: 'org.amshove.kluent', name: 'kluent', version: '1.50'
testImplementation "io.strikt:strikt-core:0.24.0"
testCompile group: 'org.amshove.kluent', name: 'kluent', version: '1.60'
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: junit_version
testRuntime "org.junit.jupiter:junit-jupiter-engine:$junit_version"
}
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
35 changes: 15 additions & 20 deletions gradlew
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
Expand Down Expand Up @@ -125,8 +125,8 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
Expand Down Expand Up @@ -154,19 +154,19 @@ if $cygwin ; then
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
i=`expr $i + 1`
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi

Expand All @@ -175,14 +175,9 @@ save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
APP_ARGS=`save "$@"`

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "$@"
5 changes: 4 additions & 1 deletion gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem http://www.apache.org/licenses/LICENSE-2.0
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -29,6 +29,9 @@ if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

Expand Down
5 changes: 1 addition & 4 deletions src/main/kotlin/me/avo/spottit/config/Arguments.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ package me.avo.spottit.config

import com.apurebase.arkenv.Arkenv
import com.apurebase.arkenv.argument
import com.apurebase.arkenv.feature.ProfileFeature
import java.io.File

object Arguments : Arkenv(programName = "Spottit", configuration = {
install(ProfileFeature())
}) {
object Arguments : Arkenv("Spottit") {

val configPath: String by argument("-c", "--config") {
description = "The path to your config.yml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class ElectronicSearchAlgorithm(
else -> searchForTrack(track)
}

private fun getTrack(track: RedditTrack): Triple<RedditTrack, Track, Int> {
private fun getTrack(track: RedditTrack): Triple<RedditTrack, Track?, Int> {
val id = track.url.substringAfter("/track/").substringBefore("?")
val spotifyTrack = spotifyApi.getTrack(id).build().execute()
val spotifyTrack = spotifyApi.getTrack(id).build().executeRequest()
return Triple(track, spotifyTrack, if (spotifyTrack != null) 1 else 0)
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/me/avo/spottit/service/ManualAuthService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class ManualAuthService(
openUrlInBrowser(uri)
} finally {
Thread.sleep(5000)
val timeout = 2L
println("Shutting down server in $timeout seconds")
server.stop(timeout, timeout, TimeUnit.SECONDS)
val timeout = 2000L
println("Shutting down server in $timeout ms")
server.stop(timeout, timeout)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.wrapper.spotify.exceptions.detailed.TooManyRequestsException
import com.wrapper.spotify.model_objects.specification.Paging
import com.wrapper.spotify.model_objects.specification.Track
import com.wrapper.spotify.requests.data.search.simplified.SearchTracksRequest
import com.wrapper.spotify.requests.data.tracks.GetTrackRequest
import me.avo.spottit.model.RedditTrack
import me.avo.spottit.util.RetrySupport

Expand All @@ -23,6 +24,8 @@ interface SpotifySearchAlgorithm : RetrySupport {
else -> throw ex
}

fun SearchTracksRequest.executeRequest(stack: Int = 0): Paging<Track> = retry(::execute)
fun SearchTracksRequest.executeRequest(): Paging<Track> = retry(::execute)

fun GetTrackRequest.executeRequest(): Track? = retry(::execute)

}
2 changes: 1 addition & 1 deletion src/test/kotlin/me/avo/spottit/server/TemplatesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal class TemplatesTest {
}.start(false)
openUrlInBrowser(url)
Thread.sleep(3000)
server.stop(2L, 2L, TimeUnit.SECONDS)
server.stop(2000L, 2000L)
}

@Test fun auth() {
Expand Down
Loading

0 comments on commit 725d50a

Please sign in to comment.