Skip to content

Commit

Permalink
1.0.6 version with 4.8 emby fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ekleop committed Oct 24, 2023
1 parent 3616651 commit 45e4b9f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 47 deletions.
7 changes: 4 additions & 3 deletions Simkl-Emby/Configuration/configPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ <h2>Scrobbling options:</h2>

var SimklAPI = {
getCode: function () {
var uri = "/Simkl/oauth/pin";
var uri = "/Simkl/oauth/pin?api_key=" + ApiClient.accessToken();
var request = new XMLHttpRequest();
request.open("GET", uri, false);
request.send();
Expand All @@ -211,7 +211,7 @@ <h2>Scrobbling options:</h2>
}
},
checkCode : function (user_code) {
var uri = "/Simkl/oauth/pin/" + user_code;
var uri = "/Simkl/oauth/pin/" + user_code + "?api_key=" + ApiClient.accessToken();
var request = new XMLHttpRequest();
request.open("GET", uri, false);
request.send();
Expand All @@ -225,7 +225,7 @@ <h2>Scrobbling options:</h2>
}
},
getUserSettings: function (secret) {
var uri = "/Simkl/users/settings/" + secret;
var uri = "/Simkl/users/settings/" + secret + "?api_key=" + ApiClient.accessToken();
var request = new XMLHttpRequest();
request.open("GET", uri, false);
request.send();
Expand All @@ -245,6 +245,7 @@ <h2>Scrobbling options:</h2>
ApiClient.getUsers().then(SimklConfig.populateUsers),
ApiClient.getPluginConfiguration(SimklConfig.guid).then(SimklConfig.loadConfig.bind(SimklConfig, ApiClient.getCurrentUserId()))]);
Dashboard.hideLoadingMsg();

});

$("#SimklConfigurationForm").on("submit", function(e) {
Expand Down
95 changes: 55 additions & 40 deletions Simkl-Emby/Services/Scrobbler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,51 +83,66 @@ public static bool canBeScrobbled(UserConfig config, SessionInfo session) {

private async void embyPlaybackProgress(object sessions, PlaybackProgressEventArgs e)
{
string sid = e.PlaySessionId, uid = e.Session.UserId, npid = e.Session.NowPlayingItem.Id;
try {
if (DateTime.UtcNow < nextTry) return;
nextTry = DateTime.UtcNow.AddSeconds(30);

UserConfig userConfig = Plugin.Instance.PluginConfiguration.getByGuid(uid);
if (userConfig == null || userConfig.userToken == "")
try{
string sid = e.PlaySessionId, uid = e.Session.UserId, npid = e.Session.NowPlayingItem.Id;
try
{
_logger.Error("Can't scrobble: User " + e.Session.UserName + " not logged in (" + (userConfig == null) + ")");
return;
if (DateTime.UtcNow < nextTry) return;
nextTry = DateTime.UtcNow.AddSeconds(30);

UserConfig userConfig = Plugin.Instance.PluginConfiguration.getByGuid(uid);
if (userConfig == null || userConfig.userToken == "")
{
_logger.Error("Can't scrobble: User " + e.Session.UserName + " not logged in (" + (userConfig == null) + ")");
return;
}

if (!canBeScrobbled(userConfig, e.Session)) return;

if (lastScrobbled.ContainsKey(sid) && lastScrobbled[sid] == npid)
{
_logger.Debug("Already scrobbled {0} for {1}", e.Session.NowPlayingItem.Name, e.Session.UserName);
return;
}

_logger.Debug(_json.SerializeToString(e.Session.NowPlayingItem));
_logger.Info("Trying to scrobble {0} ({1}) for {2} ({3}) - {4} on {5}",
e.Session.NowPlayingItem.Name, npid,
e.Session.UserName, uid,
e.Session.NowPlayingItem.Path, sid);

_logger.Debug("Item: " + _json.SerializeToString(e.MediaInfo));
var response = await _api.markAsWatched(e.MediaInfo, userConfig.userToken);
if (response.success)
{
_logger.Debug("Scrobbled without errors");
lastScrobbled[sid] = npid;

/* if (canSendNotification(response.item)) {
await _notifications.SendNotification(
SimklNotificationsFactory.GetNotificationRequest(response.item, e.Session.UserInternalId),
e.Session.FullNowPlayingItem, CancellationToken.None);
}*/
}
}

if (!canBeScrobbled(userConfig, e.Session)) return;

if (lastScrobbled.ContainsKey(sid) && lastScrobbled[sid] == npid) {
_logger.Debug("Alredy scrobbled {0} for {1}", e.Session.NowPlayingItem.Name, e.Session.UserName);
return;
catch (InvalidTokenException)
{
_logger.Info("Deleted user token");
}

_logger.Debug(_json.SerializeToString(e.Session.NowPlayingItem));
_logger.Info("Trying to scrobble {0} ({1}) for {2} ({3}) - {4} on {5}",
e.Session.NowPlayingItem.Name, npid,
e.Session.UserName, uid,
e.Session.NowPlayingItem.Path, sid);

_logger.Debug("Item: " + _json.SerializeToString(e.MediaInfo));
var response = await _api.markAsWatched(e.MediaInfo, userConfig.userToken);
if(response.success) {
_logger.Debug("Scrobbled without errors");
catch (InvalidDataException ex)
{
_logger.Error("Couldn't scrobble: " + ex.Message);
lastScrobbled[sid] = npid;

/* if (canSendNotification(response.item)) {
await _notifications.SendNotification(
SimklNotificationsFactory.GetNotificationRequest(response.item, e.Session.UserInternalId),
e.Session.FullNowPlayingItem, CancellationToken.None);
}*/
}
} catch (InvalidTokenException) {
_logger.Info("Deleted user token");
} catch (InvalidDataException ex) {
_logger.Error("Couldn't scrobble: " + ex.Message);
lastScrobbled[sid] = npid;
} catch (Exception ex) {
_logger.Error("Caught unknown exception while trying to scrobble: " + ex.Message);
_logger.Error(ex.StackTrace);
catch (Exception ex)
{
_logger.Error("Caught unknown exception while trying to scrobble: " + ex.Message);
_logger.Error(ex.StackTrace);
}
}
catch (Exception expt){
_logger.Error("No object: " + expt.Message);
_logger.Error(expt.StackTrace);
}
}

Expand Down
8 changes: 4 additions & 4 deletions Simkl-Emby/Simkl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyVersion>1.0.4.0</AssemblyVersion>
<FileVersion>1.0.4.0</FileVersion>
<AssemblyVersion>1.0.6.0</AssemblyVersion>
<FileVersion>1.0.6.0</FileVersion>
<Authors>David Davó</Authors>
<Company>Simkl</Company>
<Version>0.1.4</Version>
<Version>0.1.6</Version>
<NeutralLanguage>en-GB</NeutralLanguage>
<RepositoryUrl>https://github.com/SIMKL/Emby</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand All @@ -17,7 +17,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MediaBrowser.Server.Core" Version="4.7.9" />
<PackageReference Include="MediaBrowser.Server.Core" Version="4.7.7" />
<PackageReference Include="System.Memory" Version="4.5.5" />
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.7.0" />
</ItemGroup>
Expand Down

0 comments on commit 45e4b9f

Please sign in to comment.