New feature for rating extension
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
// This extension writes a rating to the filename of rated videos when mpv.net shuts down.
|
// This extension writes a rating to the filename of rated videos when mpv.net shuts down.
|
||||||
|
|
||||||
// The input.conf defaults contain key bindings for this extension to set ratings.
|
// The input.conf defaults contain key bindings for this extension to set ratings.
|
||||||
@@ -6,9 +7,11 @@ using System;
|
|||||||
using System.ComponentModel.Composition;
|
using System.ComponentModel.Composition;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using Microsoft.VisualBasic.FileIO;
|
||||||
|
|
||||||
using mpvnet;
|
using mpvnet;
|
||||||
using static mpvnet.Core;
|
using static mpvnet.Core;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace RatingExtension // the assembly name must end with 'Extension'
|
namespace RatingExtension // the assembly name must end with 'Extension'
|
||||||
{
|
{
|
||||||
@@ -18,6 +21,9 @@ namespace RatingExtension // the assembly name must end with 'Extension'
|
|||||||
// dictionory to store the filename and the rating
|
// dictionory to store the filename and the rating
|
||||||
Dictionary<string, int> Dic = new Dictionary<string, int>();
|
Dictionary<string, int> Dic = new Dictionary<string, int>();
|
||||||
|
|
||||||
|
string FileToDelete;
|
||||||
|
DateTime DeleteTime;
|
||||||
|
|
||||||
public RatingExtension() // plugin initialization
|
public RatingExtension() // plugin initialization
|
||||||
{
|
{
|
||||||
core.ClientMessage += ClientMessage; //handles keys defined in input.conf
|
core.ClientMessage += ClientMessage; //handles keys defined in input.conf
|
||||||
@@ -31,8 +37,10 @@ namespace RatingExtension // the assembly name must end with 'Extension'
|
|||||||
{
|
{
|
||||||
string filepath = i.Key;
|
string filepath = i.Key;
|
||||||
int rating = i.Value;
|
int rating = i.Value;
|
||||||
|
|
||||||
if (String.IsNullOrEmpty(filepath) || !File.Exists(filepath))
|
if (String.IsNullOrEmpty(filepath) || !File.Exists(filepath))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string basename = Path.GetFileNameWithoutExtension(filepath);
|
string basename = Path.GetFileNameWithoutExtension(filepath);
|
||||||
|
|
||||||
for (int x = 0; x < 6; x++)
|
for (int x = 0; x < 6; x++)
|
||||||
@@ -40,9 +48,13 @@ namespace RatingExtension // the assembly name must end with 'Extension'
|
|||||||
basename = basename.Replace(" (" + x + "stars)", "");
|
basename = basename.Replace(" (" + x + "stars)", "");
|
||||||
|
|
||||||
basename += $" ({rating}stars)";
|
basename += $" ({rating}stars)";
|
||||||
string newPath = Path.Combine(Path.GetDirectoryName(filepath), basename + Path.GetExtension(filepath));
|
|
||||||
|
string newPath = Path.Combine(Path.GetDirectoryName(filepath),
|
||||||
|
basename + Path.GetExtension(filepath));
|
||||||
|
|
||||||
if (filepath.ToLower() != newPath.ToLower())
|
if (filepath.ToLower() != newPath.ToLower())
|
||||||
File.Move(filepath, newPath);
|
File.Move(filepath, newPath);
|
||||||
|
|
||||||
File.SetLastWriteTime(newPath, DateTime.Now);
|
File.SetLastWriteTime(newPath, DateTime.Now);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -50,17 +62,47 @@ namespace RatingExtension // the assembly name must end with 'Extension'
|
|||||||
//handles keys defined in input.conf
|
//handles keys defined in input.conf
|
||||||
void ClientMessage(string[] args)
|
void ClientMessage(string[] args)
|
||||||
{
|
{
|
||||||
if (args[0] != "rate-file") return;
|
if (args[0] != "rate-file")
|
||||||
|
return;
|
||||||
|
|
||||||
if (int.TryParse(args[1], out int rating))
|
if (int.TryParse(args[1], out int rating))
|
||||||
{
|
{
|
||||||
string path = core.get_property_string("path");
|
string path = core.get_property_string("path");
|
||||||
if (!File.Exists(path)) return;
|
|
||||||
|
if (!File.Exists(path))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (rating == 0 || rating == 1)
|
||||||
|
Delete(rating);
|
||||||
|
else
|
||||||
|
{
|
||||||
Dic[path] = rating;
|
Dic[path] = rating;
|
||||||
core.commandv("show-text", $"Rating: {rating}");
|
core.commandv("show-text", $"Rating: {rating}");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (args[1] == "about")
|
else if (args[1] == "about")
|
||||||
Msg.Show("Rating Extension", "This extension writes a rating to the filename of rated videos when mpv.net shuts down.\n\nThe input.conf defaults contain key bindings for this extension to set ratings.");
|
Msg.Show("Rating Extension", "This extension writes a rating to the filename of rated videos when mpv.net shuts down.\n\nThe input.conf defaults contain key bindings for this extension to set ratings.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Delete(int rating)
|
||||||
|
{
|
||||||
|
if (rating == 0)
|
||||||
|
{
|
||||||
|
FileToDelete = core.get_property_string("path");
|
||||||
|
DeleteTime = DateTime.Now;
|
||||||
|
core.commandv("show-text", "Press 1 to delete file", "5000");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TimeSpan ts = DateTime.Now - DeleteTime;
|
||||||
|
|
||||||
|
if (FileToDelete == core.get_property_string("path") && ts.TotalSeconds < 5)
|
||||||
|
{
|
||||||
|
core.command("playlist-remove current");
|
||||||
|
Thread.Sleep(2000);
|
||||||
|
FileSystem.DeleteFile(FileToDelete, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,7 @@
|
|||||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="Microsoft.VisualBasic" />
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.ComponentModel.Composition" />
|
<Reference Include="System.ComponentModel.Composition" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
|
|||||||
Reference in New Issue
Block a user