Skip to content

Commit

Permalink
Merge branch 'release/0.8.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
s-frei committed Nov 6, 2023
2 parents f2bf0f2 + 36bbd0c commit 82e75e5
Show file tree
Hide file tree
Showing 21 changed files with 310 additions and 151 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ updates:
timezone: "Europe/Berlin"
time: "06:00"
target-branch: "develop"
open-pull-requests-limit: 10
open-pull-requests-limit: 25
reviewers:
- "s-frei"
29 changes: 29 additions & 0 deletions .github/workflows/dependabot-auto-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# https://github.com/dependabot/fetch-metadata#enabling-auto-merge

name: "Dependabot auto-merge"

on: pull_request_target

permissions:
pull-requests: write
contents: write

jobs:

dependabot:
runs-on: ubuntu-latest

if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }}

steps:

- name: "Dependabot metadata"
id: dependabot-metadata
uses: dependabot/fetch-metadata@v1

- name: "Enable auto-merge for Dependabot PRs"
if: ${{steps.dependabot-metadata.outputs.update-type == 'version-update:semver-patch'}}
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
Changelog
=========

0.8.2
-----

**Features:**

- Updated dependencies
- First shot of getting YouTubeTrack by URL

**Bugfix:**

- Fix YouTube tracks parsing

0.8.1
-----

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Maven dependency available on [Maven Central](https://search.maven.org/artifact/
<dependency>
<groupId>io.sfrei</groupId>
<artifactId>tracksearch</artifactId>
<version>0.8.0</version>
<version>0.8.2</version>
</dependency>
```

Expand Down
24 changes: 12 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.sfrei</groupId>
<artifactId>tracksearch</artifactId>
<version>0.8.1</version>
<version>0.8.2</version>

<packaging>jar</packaging>

Expand Down Expand Up @@ -42,26 +42,26 @@
<java-version>11</java-version>

<!-- deps -->
<lombok.version>1.18.26</lombok.version>
<lombok.version>1.18.30</lombok.version>
<retrofit.version>2.9.0</retrofit.version>
<okhttp.version>4.11.0</okhttp.version>
<jackson-databind.version>2.15.2</jackson-databind.version>
<jsoup.version>1.16.1</jsoup.version>
<slf4j-api.version>2.0.7</slf4j-api.version>
<junit.version>5.9.3</junit.version>
<okhttp.version>4.12.0</okhttp.version>
<jackson-databind.version>2.15.3</jackson-databind.version>
<jsoup.version>1.16.2</jsoup.version>
<slf4j-api.version>2.0.9</slf4j-api.version>
<junit.version>5.10.1</junit.version>
<assertj-core.version>3.24.2</assertj-core.version>
<logback-classic.version>1.4.8</logback-classic.version>
<logback-classic.version>1.4.11</logback-classic.version>

<!-- test n report -->
<maven-surefire.version>3.1.2</maven-surefire.version>
<maven-surefire.version>3.2.1</maven-surefire.version>
<maven-surefire-tree-reporter.version>1.2.1</maven-surefire-tree-reporter.version>

<!-- build n deploy -->
<lombok-maven-plugin.version>1.18.20.0</lombok-maven-plugin.version>
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>
<maven-javadoc-plugin.version>3.5.0</maven-javadoc-plugin.version>
<maven-release-plugin.version>3.0.0</maven-release-plugin.version>
<maven-source-plugin.version>3.3.0</maven-source-plugin.version>
<maven-javadoc-plugin.version>3.6.0</maven-javadoc-plugin.version>
<maven-release-plugin.version>3.0.1</maven-release-plugin.version>
<maven-scm-provider-gitexe.version>2.0.1</maven-scm-provider-gitexe.version>
<maven-scm-api.version>2.0.1</maven-scm-api.version>
<nexus-staging-maven-plugin.version>1.6.13</nexus-staging-maven-plugin.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private <T extends Track> Optional<String> tryToGetStreamUrl(TrackSearchClient<T
return tryToGetStreamUrl(searchClient, track, requestForCodeFunction, tries);
}
} catch (TrackSearchException e) {
log().error("Error getting stream URL for {}", e, searchClient.getClass().getSimpleName());
log().error("Error getting stream URL for {}", searchClient.getClass().getSimpleName(), e);
return Optional.empty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import io.sfrei.tracksearch.exceptions.SoundCloudException;
import io.sfrei.tracksearch.tracks.GenericTrackList;
import io.sfrei.tracksearch.tracks.SoundCloudTrack;
import io.sfrei.tracksearch.tracks.deserializer.SoundCloudTrackDeserializer;
import io.sfrei.tracksearch.utils.DeserializerUtility;
import io.sfrei.tracksearch.tracks.deserializer.soundcloud.SoundCloudTrackDeserializer;
import io.sfrei.tracksearch.utils.ObjectMapperBuilder;
import io.sfrei.tracksearch.utils.json.JsonElement;
import lombok.extern.slf4j.Slf4j;
import org.jsoup.Jsoup;
Expand Down Expand Up @@ -54,7 +54,8 @@ class SoundCloudUtility {
private static final Pattern ALTERNATIVE_PROGRESSIVE_SOUNDCLOUD_STREAM_URL_PATTERN = Pattern.compile(ALTERNATIVE_PROGRESSIVE_SOUNDCLOUD_STREAM_REGEX);
private static final Pattern ALTERNATIVE_SOUNDCLOUD_STREAM_URL_PATTERN = Pattern.compile(ALTERNATIVE_SOUNDCLOUD_STREAM_REGEX);

private static final ObjectMapper MAPPER = DeserializerUtility.mapperFor(SoundCloudTrack.SoundCloudTrackBuilder.class, new SoundCloudTrackDeserializer());
private static final ObjectMapper MAPPER = ObjectMapperBuilder.create()
.addDeserializer(SoundCloudTrack.SoundCloudTrackBuilder.class, new SoundCloudTrackDeserializer()).get();

protected List<String> getCrossOriginScripts(final String html) {
final Document doc = Jsoup.parse(html);
Expand Down Expand Up @@ -83,12 +84,12 @@ protected GenericTrackList<SoundCloudTrack> getSoundCloudTracks(final String jso
final StreamURLFunction<SoundCloudTrack> streamUrlFunction)
throws SoundCloudException {

final JsonElement responseElement = JsonElement.readHandled(MAPPER, json)
final JsonElement responseElement = JsonElement.readTreeCatching(MAPPER, json)
.orElseThrow(() -> new SoundCloudException("Cannot parse SoundCloudTracks JSON"))
.path("collection");

final List<SoundCloudTrack> scTracks = responseElement.elements()
.map(element -> element.mapToObjectHandled(MAPPER, SoundCloudTrack.SoundCloudTrackBuilder.class))
.map(element -> element.mapCatching(MAPPER, SoundCloudTrack.SoundCloudTrackBuilder.class))
.filter(Objects::nonNull)
.peek(soundCloudTrackBuilder -> soundCloudTrackBuilder.streamUrlFunction(streamUrlFunction))
.map(SoundCloudTrack.SoundCloudTrackBuilder::build)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class YouTubeClient extends SingleSearchClient<YouTubeTrack>
private static final String ADDITIONAL_PAGING_KEY = "continuation";

private static final Map<String, String> VIDEO_SEARCH_PARAMS = Map.of("sp", "EgIQAQ%3D%3D");
private static final Map<String, String> TRACK_PARAMS = Map.of("pbj", "1", "hl", "en", "alt", "json");
public static final Map<String, String> TRACK_PARAMS = Map.of("pbj", "1", "hl", "en", "alt", "json");

private static final Map<String, String> DEFAULT_SEARCH_PARAMS;

Expand Down Expand Up @@ -92,6 +92,14 @@ public static Map<String, String> makeQueryInformation(final String query, final
return new HashMap<>(Map.of(TrackList.QUERY_KEY, query, PAGING_INFORMATION, pagingToken));
}

public YouTubeTrack getTrack(@NonNull final String trackUrl) throws TrackSearchException {
final String trackUrlJSON = trackUrlJSON(api.getForUrlWithParams(trackUrl, TRACK_PARAMS));
final YouTubeTrack youTubeTrack = youTubeUtility.getYouTubeTrack(trackUrlJSON, this::provideStreamUrl);
final YouTubeTrackInfo trackInfo = youTubeUtility.getTrackInfo(trackUrlJSON, trackUrl, this::requestURL);
youTubeTrack.setTrackInfo(trackInfo);
return youTubeTrack;
}

private GenericTrackList<YouTubeTrack> getTracksForSearch(@NonNull final String search, @NonNull final Map<String, String> params, QueryType queryType)
throws TrackSearchException {

Expand Down Expand Up @@ -124,13 +132,16 @@ public TrackList<YouTubeTrack> getNext(@NonNull final TrackList<? extends Track>
throw unsupportedQueryTypeException(YouTubeException::new, trackListQueryType);
}

public YouTubeTrackInfo loadTrackInfo(final YouTubeTrack youtubeTrack) throws TrackSearchException {
private String trackUrlJSON(Call<ResponseWrapper> trackCall) throws TrackSearchException {
final ResponseWrapper trackResponse = Client.request(trackCall);
return trackResponse.getContentOrThrow();
}

private YouTubeTrackInfo loadTrackInfo(final YouTubeTrack youtubeTrack) throws TrackSearchException {
final String trackUrl = youtubeTrack.getUrl();
final Call<ResponseWrapper> trackRequest = api.getForUrlWithParams(trackUrl, TRACK_PARAMS);
final ResponseWrapper trackResponse = Client.request(trackRequest);
final String trackURLContent = trackUrlJSON(api.getForUrlWithParams(trackUrl, TRACK_PARAMS));

final String trackContent = trackResponse.getContentOrThrow();
final YouTubeTrackInfo trackInfo = youTubeUtility.getTrackInfo(trackContent, trackUrl, this::requestURL);
final YouTubeTrackInfo trackInfo = youTubeUtility.getTrackInfo(trackURLContent, trackUrl, this::requestURL);
return youtubeTrack.setAndGetTrackInfo(trackInfo);
}

Expand Down
Loading

0 comments on commit 82e75e5

Please sign in to comment.