Skip to content

Commit

Permalink
Passthrough client id for twitch requests
Browse files Browse the repository at this point in the history
Add option to settings to provide the client id to livestreamer to bypass the new oauth requirement
  • Loading branch information
laurencee committed Sep 15, 2016
1 parent 678c4cf commit 54d4e7f
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 7 deletions.
3 changes: 3 additions & 0 deletions ExternalAPIs/TwitchTv/RequestConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ namespace ExternalAPIs.TwitchTv
public static class RequestConstants
{
public const string AcceptHeader = "application/vnd.twitchtv.v3+json";
public const string ClientIdHeaderKey = "Client-ID";
public const string ClientIdHeaderValue = "lf8xspujnqfqcdlj11zq77dfen2tqjo";

public const string TwitchTvApiRoot = "https://api.twitch.tv/kraken";
public const string UserFollows = TwitchTvApiRoot + "/users/{0}/follows/channels";
public const string Streams = TwitchTvApiRoot + "/streams";
Expand Down
1 change: 1 addition & 0 deletions ExternalAPIs/TwitchTv/TwitchTvReadonlyClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public class TwitchTvReadonlyClient : ITwitchTvReadonlyClient
{
HttpClient httpClient = HttpClientExtensions.CreateCompressionHttpClient();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(RequestConstants.AcceptHeader));
httpClient.DefaultRequestHeaders.Add(RequestConstants.ClientIdHeaderKey, RequestConstants.ClientIdHeaderValue);
return httpClient.ExecuteRequest<T>(request, cancellationToken);
}
}
Expand Down
4 changes: 2 additions & 2 deletions GlobalAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]

[assembly: AssemblyVersion("2.7.0.0")]
[assembly: AssemblyFileVersion("2.7.0.0")]
[assembly: AssemblyVersion("2.8.0.0")]
[assembly: AssemblyFileVersion("2.8.0.0")]
14 changes: 13 additions & 1 deletion Livestream.Monitor/Core/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class Settings : PropertyChangedBase
private string livestreamerFullPath;
private string chromeFullPath;
private int minimumEventViewers = DEFAULT_MINIMUM_EVENT_VIEWERS;
private bool disableNotifications;
private bool disableNotifications, passthroughClientId;
private bool hideStreamOutputMessageBoxOnLoad;

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
Expand Down Expand Up @@ -124,6 +124,18 @@ public bool HideStreamOutputMessageBoxOnLoad
}
}

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public bool PassthroughClientId
{
get { return passthroughClientId; }
set
{
if (value == passthroughClientId) return;
passthroughClientId = value;
NotifyOfPropertyChange(() => PassthroughClientId);
}
}

/// <summary>
/// Channel names in this collection should not raise notifications. <para/>
/// We store these in settings so it can apply to both monitored and popular streams.
Expand Down
10 changes: 9 additions & 1 deletion Livestream.Monitor/Model/StreamLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Caliburn.Micro;
using Livestream.Monitor.Core;
using Livestream.Monitor.Core.Utility;
using Livestream.Monitor.Model.ApiClients;
using Livestream.Monitor.ViewModels;
using Action = System.Action;

Expand Down Expand Up @@ -96,6 +97,13 @@ public void OpenStream(LivestreamModel livestreamModel, string streamQuality)
if (livestreamModel?.ApiClient == null || !livestreamModel.Live) return;

string livestreamerArgs = $"{livestreamModel.StreamUrl} {streamQuality}";

// hack to pass through the client id to livestreamer
if (settingsHandler.Settings.PassthroughClientId && livestreamModel.ApiClient is TwitchApiClient)
{
livestreamerArgs = $"--http-header {ExternalAPIs.TwitchTv.RequestConstants.ClientIdHeaderKey}={ExternalAPIs.TwitchTv.RequestConstants.ClientIdHeaderValue} {livestreamerArgs}";
}

var messageBoxViewModel = ShowLivestreamerLoadMessageBox(
title: $"Stream '{livestreamModel.DisplayName}'",
messageText: $"Launching livestreamer....{Environment.NewLine}'livestreamer.exe {livestreamerArgs}'");
Expand All @@ -105,7 +113,7 @@ public void OpenStream(LivestreamModel livestreamModel, string streamQuality)
{
messageBoxViewModel.MessageText += Environment.NewLine + $"[NOTE] Channel is not a twitch partner so falling back to {StreamQuality.Best} quality";
}

lock (watchingStreamsLock)
{
watchingStreams.Add(livestreamModel);
Expand Down
20 changes: 17 additions & 3 deletions Livestream.Monitor/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ public class SettingsViewModel : Screen, INotifyDataErrorInfo
private string chromeFullPath;
private string livestreamerFullPath;
private int minimumEventViewers;
private bool disableNotifications;
private bool hideStreamOutputOnLoad;
private bool disableNotifications, hideStreamOutputOnLoad, passthroughClientId;

public SettingsViewModel()
{
Expand Down Expand Up @@ -122,6 +121,18 @@ public bool HideStreamOutputOnLoad
}
}

public bool PassthroughClientId
{
get { return passthroughClientId; }
set
{
if (value == passthroughClientId) return;
passthroughClientId = value;
NotifyOfPropertyChange(() => PassthroughClientId);
NotifyOfPropertyChange(() => CanSave);
}
}

public bool CanSave
{
get
Expand All @@ -135,7 +146,8 @@ public bool CanSave
LivestreamerFullPath != settingsHandler.Settings.LivestreamerFullPath ||
MinimumEventViewers != settingsHandler.Settings.MinimumEventViewers ||
DisableNotifications != settingsHandler.Settings.DisableNotifications ||
HideStreamOutputOnLoad != settingsHandler.Settings.HideStreamOutputMessageBoxOnLoad;
HideStreamOutputOnLoad != settingsHandler.Settings.HideStreamOutputMessageBoxOnLoad ||
PassthroughClientId != settingsHandler.Settings.PassthroughClientId;
}
}

Expand Down Expand Up @@ -163,6 +175,7 @@ public void Save()
settingsHandler.Settings.MinimumEventViewers = MinimumEventViewers;
settingsHandler.Settings.DisableNotifications = DisableNotifications;
settingsHandler.Settings.HideStreamOutputMessageBoxOnLoad = HideStreamOutputOnLoad;
settingsHandler.Settings.PassthroughClientId = PassthroughClientId;
settingsHandler.SaveSettings();

settingsHandler.Settings.PropertyChanged += SettingsOnPropertyChanged;
Expand Down Expand Up @@ -223,6 +236,7 @@ protected override void OnActivate()
MinimumEventViewers = settingsHandler.Settings.MinimumEventViewers;
DisableNotifications = settingsHandler.Settings.DisableNotifications;
HideStreamOutputOnLoad = settingsHandler.Settings.HideStreamOutputMessageBoxOnLoad;
PassthroughClientId = settingsHandler.Settings.PassthroughClientId;

settingsHandler.Settings.PropertyChanged += SettingsOnPropertyChanged;
base.OnActivate();
Expand Down
2 changes: 2 additions & 0 deletions Livestream.Monitor/Views/SettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
ToolTip="When unchecked, will disable all notifications (including online notifications) from displaying" />
<CheckBox x:Name="HideStreamOutputOnLoad" Content="Hide Stream Output On Load"
ToolTip="When checked, the stream output box will be hidden upon successful stream load" />
<CheckBox x:Name="PassthroughClientId" Content="Bypass Livestreamer OAuth to twitch"
ToolTip="When checked, a client id for Livestream Monitor will provided to Livestreamer so an OAuth token for Livestreamer is not required to launch streams.&#x0a;This client id will appear in the stream output message box livestreamer args." />
</StackPanel>

<Button Grid.Row="1" x:Name="Save" Content="Save" Margin="20" />
Expand Down

0 comments on commit 54d4e7f

Please sign in to comment.