Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add YouTube streams #121

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ highest plane on the network? The longest flight? The flight that has been conne

[![Streamers Table](assets/images/showcase/table_streamers.png)](assets/images/showcase/table_streamers.png)

Want to find a VATSIM stream to watch? This table lists all users that have included a link to their twitch stream in
their remarks. [Want to make sure you show up here when you're streaming?](/streamers)
Want to find a VATSIM stream to watch? This table lists all users that have included a link to their Twitch or YouTube
stream in their remarks. [Want to make sure you show up here when you're streaming?](/streamers)

#### Distance Measure

Expand Down
7 changes: 6 additions & 1 deletion docs/streamers.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@

### [← back](/)

VATprism will show users which clients are streaming on Twitch.
VATprism will show users which clients are streaming on Twitch and YouTube.

[![Stramer Detail View](assets/images/showcase/detail_streamer.png)](assets/images/showcase/detail_streamer.png)

#### Want to make sure you show up?

**Twitch**
Simply put `twitch.tv/<your-username>` or `twitch.tv <your-username>` in your remarks and VATprism will automatically
add a link to your Twitch stream to your pilot view and will add you to the streamers table.

**YouTube**
Simply put `youtube.com/<your-username>` or `youtube.com <your-username>` in your remarks and VATprism will automatically
add a link to your YouTube stream to your pilot view and will add you to the streamers table.

[![Streamers Table](assets/images/showcase/table_streamers.png)](assets/images/showcase/table_streamers.png)

### [← back](/)
55 changes: 40 additions & 15 deletions src/main/java/net/marvk/fs/vatsim/map/data/Urls.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,70 @@
import java.util.stream.Collectors;

public class Urls {
private static final Pattern URL = Pattern.compile("(?<twitchWithSpace>twitch\\.tv[ /][A-Z0-9_]+)|(?:(?:https?[: ]\\/\\/)?(?<content>(www)?(?:[a-z0-9-]{1,256}\\.)+(?:[a-z]{2,})(?:\\/[a-z0-9-_]+)*\\/?))", Pattern.CASE_INSENSITIVE);
private static final Pattern TWITCH_URL = Pattern.compile("(?<twitchWithSpace>twitch\\.tv[ /][A-Z0-9_]+)|(?:(?:https?[: ]\\/\\/)?(?<content>(www)?(?:[a-z0-9-]{1,256}\\.)+(?:[a-z]{2,})(?:\\/[a-z0-9-_]+)*\\/?))", Pattern.CASE_INSENSITIVE);
private static final Pattern YOUTUBE_URL = Pattern.compile("(?<youtubeWithSpace>youtube\\.com[ /][A-Z0-9_]+)|(?:(?:https?[: ]\\/\\/)?(?<content>(www)?(?:[a-z0-9-]{1,256}\\.)+(?:[a-z]{2,})(?:\\/[a-z0-9-_@]+)*\\/?))", Pattern.CASE_INSENSITIVE);

private final ReadOnlyListWrapper<String> urls = new ReadOnlyListWrapper<>(FXCollections.observableArrayList());

private final StringProperty twitchUrl = new SimpleStringProperty();
private final BooleanProperty twitch = new SimpleBooleanProperty();
private final StringProperty url = new SimpleStringProperty();
private final BooleanProperty livestream = new SimpleBooleanProperty();
private final StringProperty platform = new SimpleStringProperty();

public ReadOnlyListProperty<String> getUrls() {
return urls.getReadOnlyProperty();
}

public String getTwitchUrl() {
return twitchUrl.get();
public String getUrl() {
return url.get();
}

public ReadOnlyStringProperty twitchUrlProperty() {
return twitchUrl;
public ReadOnlyStringProperty urlProperty() {
return url;
}

public boolean isTwitch() {
return twitch.get();
public boolean getLivestream() {
return livestream.get();
}

public ReadOnlyBooleanProperty twitchProperty() {
return twitch;
public ReadOnlyBooleanProperty livestreamProperty() {
return livestream;
}

public ReadOnlyStringProperty platformProperty() {
return platform;
}

void setUrlsFromString(final String s) {
urls.setAll(parseStrings(s));

final Optional<String> maybeTwitchUrl = urls.stream().filter(e -> e.contains("twitch")).findFirst();
final Optional<String> maybeStreamUrl = urls.stream().filter(e -> e.contains("twitch")
|| e.contains("youtube")).findFirst();

platform.set("Unknown");
if (maybeStreamUrl.isPresent() && maybeStreamUrl.get().contains("youtube")) {
platform.set("YouTube");
} else {
platform.set("Twitch.tv");
}

twitchUrl.set(maybeTwitchUrl.orElse(null));
twitch.set(maybeTwitchUrl.isPresent());
url.set(maybeStreamUrl.orElse(null));
livestream.set(maybeStreamUrl.isPresent());
}

private static List<String> parseStrings(final String s) {
if (s == null || s.isBlank()) {
return Collections.emptyList();
}

return URL
if (s.toLowerCase(Locale.ROOT).contains("youtube.com/")) {
return YOUTUBE_URL
.matcher(s.replaceAll("/./\s+$", ""))
.results()
.map(Urls::getGroup)
.map(e -> e.toLowerCase(Locale.ROOT))
.collect(Collectors.toList());
}
return TWITCH_URL
.matcher(s.replaceAll("/./\s+$", ""))
.results()
.map(Urls::getGroup)
Expand All @@ -67,6 +89,9 @@ private static String getGroup(final java.util.regex.MatchResult e) {
return e.group(2);
}

if (g1.toLowerCase(Locale.ROOT).contains("youtube")) {
return g1.replaceAll("(?i)youtube\\.com\s+", "youtube\\.com/");
}
return g1.replaceAll("(?i)twitch\\.tv\s+", "twitch\\.tv/");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class ClientDetailView extends DataDetailSubView<ClientDetailViewModel, C
@FXML
private FontIcon questionMarkIcon;
@FXML
private FontIcon livestreamIcon;
@FXML
private HBox headerLabelContainer;
@FXML
private Label headerLabel;
Expand Down Expand Up @@ -68,10 +70,21 @@ protected List<Label> labels() {
@Override
public void initialize() {
super.initialize();
viewModel.twitchStreamProperty().addListener((observable, oldValue, newValue) -> {
viewModel.livestreamProperty().addListener((observable, oldValue, newValue) -> {
if (newValue) {
headerPane.getStyleClass().add("twitch-container");
viewModel.livestreamPlatformProperty().addListener((observable1, oldValue1, newValue1) -> {
if (newValue1.equals("YouTube")) {
livestreamIcon.setIconLiteral("ion4-logo-youtube");
headerPane.getStyleClass().remove("twitch-container");
headerPane.getStyleClass().add("youtube-container");
} else {
livestreamIcon.setIconLiteral("ion4-logo-twitch");
headerPane.getStyleClass().remove("youtube-container");
headerPane.getStyleClass().add("twitch-container");
}
});
} else {
headerPane.getStyleClass().remove("youtube-container");
headerPane.getStyleClass().remove("twitch-container");
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import com.google.inject.Inject;
import javafx.application.HostServices;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.beans.property.ReadOnlyBooleanWrapper;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.beans.property.*;
import net.marvk.fs.vatsim.api.VatsimApiUrlProvider;
import net.marvk.fs.vatsim.map.data.Client;
import net.marvk.fs.vatsim.map.data.Preferences;
Expand All @@ -14,8 +11,9 @@
public class ClientDetailViewModel extends DataDetailSubViewModel<Client> {
private final HostServices hostServices;
private final VatsimApiUrlProvider urlProvider;
private final ReadOnlyBooleanWrapper twitchStream = new ReadOnlyBooleanWrapper();
private final ReadOnlyObjectWrapper<String> twitchStreamUrl = new ReadOnlyObjectWrapper<>();
private final ReadOnlyBooleanWrapper livestream = new ReadOnlyBooleanWrapper();
private final ReadOnlyObjectWrapper<String> livestreamUrl = new ReadOnlyObjectWrapper<>();
private final ReadOnlyStringWrapper livestreamPlatform = new ReadOnlyStringWrapper();

@Inject
public ClientDetailViewModel(final HostServices hostServices, final VatsimApiUrlProvider urlProvider, final Preferences preferences) {
Expand All @@ -25,17 +23,26 @@ public ClientDetailViewModel(final HostServices hostServices, final VatsimApiUrl
final BooleanProperty social = preferences.booleanProperty("general.social");

data.addListener((observable, oldValue, newValue) -> {
twitchStream.bind(newValue.getUrls().twitchProperty().and(social));
twitchStreamUrl.bind(newValue.getUrls().twitchUrlProperty());
livestream.bind(newValue.getUrls().livestreamProperty().and(social));
livestreamUrl.bind(newValue.getUrls().urlProperty());
livestreamPlatform.bind(newValue.getUrls().platformProperty());
});
}

public boolean isTwitchStream() {
return twitchStream.get();
public boolean isLivestream() {
return livestream.get();
}

public ReadOnlyBooleanProperty twitchStreamProperty() {
return twitchStream.getReadOnlyProperty();
public ReadOnlyBooleanProperty livestreamProperty() {
return livestream.getReadOnlyProperty();
}

public String getLivestreamPlatform() {
return livestreamPlatform.get();
}

public ReadOnlyStringProperty livestreamPlatformProperty() {
return livestreamPlatform.getReadOnlyProperty();
}

public void openStats() {
Expand All @@ -45,8 +52,8 @@ public void openStats() {
}

public void openStream() {
if (twitchStreamUrl.get() != null) {
hostServices.showDocument("https://" + twitchStreamUrl.get());
if (livestreamUrl.get() != null) {
hostServices.showDocument("https://" + livestreamUrl.get());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,18 @@ protected void initializeColumns() {
.build();

this.<String>newColumnBuilder()
.title("Twitch Username")
.objectObservableValueFactory(e -> e.getUrls().twitchUrlProperty())
.toStringMapper(e -> e.replaceAll("(?:www\\.)?twitch\\.tv/", ""))
.title("Platform")
.objectObservableValueFactory(e -> e.getUrls().platformProperty())
.toStringMapper(e -> e)
.sortable()
.widthFactor(0.8)
.build();

this.<String>newColumnBuilder()
.title("Username")
.objectObservableValueFactory(e -> e.getUrls().urlProperty())
.toStringMapper(e -> e.replaceAll("(?:www\\.)?twitch\\.tv/", "")
.replaceAll("(?:www\\.)?youtube\\.com/", ""))
.sortable()
.widthFactor(2.0)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public StreamersTableViewModel(final HostServices hostServices, final Preference

this.filteredList = new FilteredList<>(clientRepository.list());
this.filteredList.predicateProperty().bind(Bindings.createObjectBinding(
() -> e -> e.getUrls().isTwitch(),
() -> e -> e.getUrls().getLivestream(),
currentTime
));
Notifications.CLIENTS_RELOADED.subscribe(() -> currentTime.set(LocalDateTime.now()));
Expand All @@ -42,9 +42,9 @@ public ObservableList<Client> items() {
}

public void openStream(final Client client) {
final String twitchUrl = client.getUrls().getTwitchUrl();
if (twitchUrl != null) {
hostServices.showDocument("https://" + twitchUrl);
final String livestreamUrl = client.getUrls().getUrl();
if (livestreamUrl != null) {
hostServices.showDocument("https://" + livestreamUrl);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<Insets left="5.0"/>
</padding>
</Label>
<FontIcon styleClass="live-twitch-logo" iconLiteral="ion4-logo-twitch"/>
<FontIcon styleClass="live-logo" fx:id="livestreamIcon"/>
</HBox>
<HBox styleClass="header-label-container" alignment="CENTER" spacing="5" fx:id="headerLabelContainer">
<Label styleClass="header-label" fx:id="headerLabel"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
* {
-twitch: #9146FF;
-youtube: #FF0000;
}

.twitch-container {
Expand All @@ -9,14 +10,29 @@
-fx-cursor: hand;
}

.youtube-container {
-fx-background-color: linear-gradient(from 0% 0% to 100% 100%, -vatsim-background-color-light, -youtube);
-fx-background-radius: 0 10 10 0;
-fx-background-insets: 0 10 0 0;
-fx-cursor: hand;
}

.twitch-container:hover {
-fx-background-color: -twitch;
}

.youtube-container:hover {
-fx-background-color: -youtube;
}

.twitch-container .header-label {
-fx-text-fill: white;
}

.youtube-container .header-label {
-fx-text-fill: white;
}

.header-pane .live-dot {
visibility: hidden;
}
Expand All @@ -26,20 +42,49 @@
visibility: visible;
}

.header-pane .live-twitch-logo {
.youtube-container .live-dot {
-fx-text-fill: red;
visibility: visible;
}

.header-pane .live-logo {
visibility: hidden;
}

.twitch-container .live-twitch-logo {
.header-pane .live-logo {
visibility: hidden;
}

.twitch-container .live-logo {
-fx-icon-color: -twitch;
visibility: visible;
}

.twitch-container:hover .live-twitch-logo {
.youtube-container .live-logo {
-fx-icon-color: -youtube;
visibility: visible;
}

.twitch-container:hover .live-logo {
-fx-icon-color: white;
visibility: visible;
}

.youtube-container:hover .live-logo {
-fx-icon-color: white;
visibility: visible;
}

.twitch-container:hover .live-dot {
-fx-text-fill: white;
visibility: visible;
}

.youtube-container:hover .live-dot {
-fx-text-fill: white;
visibility: visible;
}

.header-pane .question-mark-icon {
-fx-icon-color: -vatsim-text-color;
}
Expand All @@ -55,3 +100,7 @@
.twitch-container .question-mark-icon {
-fx-icon-color: white;
}

.youtube-container .question-mark-icon {
-fx-icon-color: white;
}