Compare commits
2 Commits
57c42bcc41
...
MassTorren
| Author | SHA1 | Date | |
|---|---|---|---|
| 80dc743835 | |||
| 5a0ffdad1e |
@@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.11.35303.130
|
VisualStudioVersion = 17.11.35303.130
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AnimeAnnouncer", "AnimeAnnouncer\AnimeAnnouncer.csproj", "{B6D808BF-954E-48C8-A37E-62A8AA4E06C0}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AnimeAnnouncer", "AnimeAnnouncer\AnimeAnnouncer.csproj", "{B6D808BF-954E-48C8-A37E-62A8AA4E06C0}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MassTorrentAdd", "MassTorrentAdd\MassTorrentAdd.csproj", "{AE94FFAE-8D5B-46EF-BC7C-48510F0F7F04}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@@ -15,6 +17,10 @@ Global
|
|||||||
{B6D808BF-954E-48C8-A37E-62A8AA4E06C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{B6D808BF-954E-48C8-A37E-62A8AA4E06C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{B6D808BF-954E-48C8-A37E-62A8AA4E06C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{B6D808BF-954E-48C8-A37E-62A8AA4E06C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{B6D808BF-954E-48C8-A37E-62A8AA4E06C0}.Release|Any CPU.Build.0 = Release|Any CPU
|
{B6D808BF-954E-48C8-A37E-62A8AA4E06C0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{AE94FFAE-8D5B-46EF-BC7C-48510F0F7F04}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{AE94FFAE-8D5B-46EF-BC7C-48510F0F7F04}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{AE94FFAE-8D5B-46EF-BC7C-48510F0F7F04}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{AE94FFAE-8D5B-46EF-BC7C-48510F0F7F04}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ namespace AnimeAnnouncer.Cache
|
|||||||
|
|
||||||
public int LatestSeasonNumber { get; set; }
|
public int LatestSeasonNumber { get; set; }
|
||||||
public int LastEpisodeNumber { get; set; }
|
public int LastEpisodeNumber { get; set; }
|
||||||
public string? PosterPath { get; set; }
|
public string? PosterPath { get; internal set; }
|
||||||
public string? BackdropPath { get; set; }
|
public string? BackdropPath { get; internal set; }
|
||||||
public string? LatestSeasonPosterPath { get; set; }
|
public string? LatestSeasonPosterPath { get; internal set; }
|
||||||
public string? LatestSeasonOverview { get; set; }
|
public string? LatestSeasonOverview { get; internal set; }
|
||||||
public double VoteAverage { get; set; }
|
public double VoteAverage { get; internal set; }
|
||||||
public string? Overview { get; set; }
|
public string? Overview { get; internal set; }
|
||||||
public int? LatestOrdinalEpisodeNumber { get; set; }
|
public int? LatestOrdinalEpisodeNumber { get; internal set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,6 @@ using Mastonet;
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using TMDbLib.Client;
|
using TMDbLib.Client;
|
||||||
using TMDbLib.Objects.Authentication;
|
|
||||||
|
|
||||||
namespace AnimeAnnouncer
|
namespace AnimeAnnouncer
|
||||||
{
|
{
|
||||||
@@ -145,24 +144,9 @@ namespace AnimeAnnouncer
|
|||||||
|
|
||||||
latestEpisodeNumber = latestSeason.EpisodeCount;
|
latestEpisodeNumber = latestSeason.EpisodeCount;
|
||||||
|
|
||||||
//if nearing the end of a season, confirm it's marked with season finale
|
|
||||||
|
|
||||||
if(int.Parse(episode) >= (latestEpisodeNumber - 2))
|
|
||||||
{
|
|
||||||
var latestSeasonDetail = await tmdbClient.GetTvSeasonAsync(supposedShowId, latestSeasonNumber);
|
|
||||||
|
|
||||||
var seasonFinale = latestSeasonDetail.Episodes.LastOrDefault(e => e.EpisodeType.Equals("finale", StringComparison.InvariantCultureIgnoreCase));
|
|
||||||
|
|
||||||
if(seasonFinale != null && seasonFinale.EpisodeNumber != latestEpisodeNumber)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Overriding previous finale choice of {latestEpisodeNumber} due to season detail response where it's {seasonFinale.EpisodeNumber}");
|
|
||||||
latestEpisodeNumber = seasonFinale.EpisodeNumber;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(showResult.Seasons.Count > 1)
|
if(showResult.Seasons.Count > 1)
|
||||||
{
|
{
|
||||||
latestOrdinalEpisodeNumber = showResult.Seasons.Where(s => s.SeasonNumber != 0).Sum(s => s.EpisodeCount);
|
latestOrdinalEpisodeNumber = showResult.Seasons.Sum(s => s.EpisodeCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tmdbCache != null && searchResults != null)
|
if(tmdbCache != null && searchResults != null)
|
||||||
@@ -180,8 +164,8 @@ namespace AnimeAnnouncer
|
|||||||
Overview = showResult.Overview,
|
Overview = showResult.Overview,
|
||||||
VoteAverage = showResult.VoteAverage,
|
VoteAverage = showResult.VoteAverage,
|
||||||
ShowID = supposedShowId,
|
ShowID = supposedShowId,
|
||||||
LatestSeasonNumber = latestSeasonNumber,
|
LatestSeasonNumber = latestSeason.SeasonNumber,
|
||||||
LastEpisodeNumber = latestEpisodeNumber
|
LastEpisodeNumber = latestSeason.EpisodeCount
|
||||||
};
|
};
|
||||||
_ = tmdbCache.SetCacheItem($"ShowCache-{title}", cachedShow);
|
_ = tmdbCache.SetCacheItem($"ShowCache-{title}", cachedShow);
|
||||||
Console.WriteLine($"{title} Added to cache");
|
Console.WriteLine($"{title} Added to cache");
|
||||||
@@ -209,12 +193,6 @@ namespace AnimeAnnouncer
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Sometimes TMDB metadata hasn't been filled in yet
|
|
||||||
if(latestEpisodeNumber < 3)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Skipping announcement due to a low episode number");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Announce if unique
|
// Announce if unique
|
||||||
if(await tmdbCache.KeyExists($"ShowAnnounced-{supposedShowId}"))
|
if(await tmdbCache.KeyExists($"ShowAnnounced-{supposedShowId}"))
|
||||||
|
|||||||
28
MassTorrentAdd/Dockerfile
Normal file
28
MassTorrentAdd/Dockerfile
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
||||||
|
|
||||||
|
# This stage is used when running from VS in fast mode (Default for Debug configuration)
|
||||||
|
FROM mcr.microsoft.com/dotnet/runtime:8.0 AS base
|
||||||
|
USER app
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
|
||||||
|
# This stage is used to build the service project
|
||||||
|
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||||
|
ARG BUILD_CONFIGURATION=Release
|
||||||
|
WORKDIR /src
|
||||||
|
COPY ["MassTorrentAdd/MassTorrentAdd.csproj", "MassTorrentAdd/"]
|
||||||
|
RUN dotnet restore "./MassTorrentAdd/MassTorrentAdd.csproj"
|
||||||
|
COPY . .
|
||||||
|
WORKDIR "/src/MassTorrentAdd"
|
||||||
|
RUN dotnet build "./MassTorrentAdd.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||||
|
|
||||||
|
# This stage is used to publish the service project to be copied to the final stage
|
||||||
|
FROM build AS publish
|
||||||
|
ARG BUILD_CONFIGURATION=Release
|
||||||
|
RUN dotnet publish "./MassTorrentAdd.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
||||||
|
|
||||||
|
# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
|
||||||
|
FROM base AS final
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=publish /app/publish .
|
||||||
|
ENTRYPOINT ["dotnet", "MassTorrentAdd.dll"]
|
||||||
28
MassTorrentAdd/MassTorrentAdd.csproj
Normal file
28
MassTorrentAdd/MassTorrentAdd.csproj
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.1" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
|
||||||
|
<PackageReference Include="Transmission.API.RPC" Version="2.1.2" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="appSettings.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
101
MassTorrentAdd/Program.cs
Normal file
101
MassTorrentAdd/Program.cs
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
using Transmission.API.RPC;
|
||||||
|
|
||||||
|
namespace MassTorrentAdd
|
||||||
|
{
|
||||||
|
internal class Program
|
||||||
|
{
|
||||||
|
static String watchFolder, transmissionHost, transmissionUsername, transmissionPassword, transmissionDownloadFolder, destinationFolder;
|
||||||
|
static Transmission.API.RPC.Client transmissionClient;
|
||||||
|
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
if(args.Length == 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Please provide the nyaa URL to target for download.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String url = args[0];
|
||||||
|
if (!url.Contains("rss"))
|
||||||
|
url = url + "&page=rss";
|
||||||
|
|
||||||
|
var builder = new ConfigurationBuilder()
|
||||||
|
.SetBasePath(Directory.GetCurrentDirectory())
|
||||||
|
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
|
||||||
|
|
||||||
|
IConfigurationRoot configuration = builder.Build();
|
||||||
|
transmissionHost = configuration.GetValue<String>("transmissionURI");
|
||||||
|
transmissionUsername = configuration.GetValue<String>("transmissionUsername");
|
||||||
|
transmissionPassword = configuration.GetValue<String>("transmissionPassword");
|
||||||
|
destinationFolder = configuration.GetValue<String>("destinationFolder");
|
||||||
|
|
||||||
|
Console.WriteLine($"Using transmission server {transmissionHost}");
|
||||||
|
transmissionClient = new Transmission.API.RPC.Client(transmissionHost, null, transmissionUsername, transmissionPassword);
|
||||||
|
var sessionInformation = transmissionClient.GetSessionInformation();
|
||||||
|
if (sessionInformation == null || String.IsNullOrEmpty(sessionInformation.Version))
|
||||||
|
{
|
||||||
|
Console.WriteLine("An error occurred while receiving session information from the rpc server");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
HttpClient httpClient = new HttpClient();
|
||||||
|
var response = httpClient.GetStringAsync(url).Result;
|
||||||
|
if(response == null)
|
||||||
|
{
|
||||||
|
Console.WriteLine("An error occurred while contacting Nyaa for a response");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
XDocument doc = XDocument.Parse(response);
|
||||||
|
XNamespace nyaaNS = doc.Root.GetNamespaceOfPrefix("nyaa");
|
||||||
|
var items = from item in doc.Descendants("channel").Elements("item")
|
||||||
|
select new
|
||||||
|
{
|
||||||
|
Title = item.Element("title").Value,
|
||||||
|
Published = item.Element("pubDate").Value,
|
||||||
|
Category = item.Element(nyaaNS + "category").Value,
|
||||||
|
CategoryID = item.Element(nyaaNS + "categoryId").Value,
|
||||||
|
Size = item.Element(nyaaNS + "size").Value,
|
||||||
|
Link = item.Element("link").Value,
|
||||||
|
Description = item.Element("description").Value,
|
||||||
|
PostID = item.Element("guid").Value,
|
||||||
|
};
|
||||||
|
Console.WriteLine("Downloading ..");
|
||||||
|
foreach ( var item in items )
|
||||||
|
{
|
||||||
|
Console.WriteLine($"{item.Title}");
|
||||||
|
}
|
||||||
|
String transmissionDirectoryName = items.First().Title.Trim();
|
||||||
|
transmissionDirectoryName = System.Text.RegularExpressions.Regex.Replace(transmissionDirectoryName, @"E\d{2,3}.*?(\d{3,4}p)", " $1");
|
||||||
|
transmissionDirectoryName = System.Text.RegularExpressions.Regex.Replace(transmissionDirectoryName, @"\s\(.*?\)$", "");
|
||||||
|
transmissionDirectoryName = destinationFolder + (destinationFolder.EndsWith("/") ? String.Empty : "/") + transmissionDirectoryName.Replace(" ", ".");
|
||||||
|
Console.WriteLine("to " + transmissionDirectoryName);
|
||||||
|
|
||||||
|
Console.WriteLine("Continue?");
|
||||||
|
if(Console.ReadKey().KeyChar != 'y')
|
||||||
|
{
|
||||||
|
Console.WriteLine("Exiting");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
foreach (var item in items)
|
||||||
|
{
|
||||||
|
var torrentData = httpClient.GetByteArrayAsync(item.Link).Result;
|
||||||
|
AddNewTorrentFileToServer(torrentData, transmissionDirectoryName);
|
||||||
|
}
|
||||||
|
Console.WriteLine("Completed");
|
||||||
|
}
|
||||||
|
private static void AddNewTorrentFileToServer(byte[] torrentFileData, String saveLocation)
|
||||||
|
{
|
||||||
|
Transmission.API.RPC.Entity.NewTorrent newTorrent = new()
|
||||||
|
{
|
||||||
|
DownloadDirectory = saveLocation,
|
||||||
|
Paused = true,
|
||||||
|
Metainfo = Convert.ToBase64String(torrentFileData)
|
||||||
|
};
|
||||||
|
var torrentInfo = transmissionClient.TorrentAdd(newTorrent);
|
||||||
|
//transmissionClient.TorrentVerify(new object[] { torrentInfo.ID });
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
MassTorrentAdd/Properties/launchSettings.json
Normal file
11
MassTorrentAdd/Properties/launchSettings.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"profiles": {
|
||||||
|
"MassTorrentAdd": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"commandLineArgs": "https://nyaa.si/?f=0&c=1_0&q=The+Fable+VARYG"
|
||||||
|
},
|
||||||
|
"Container (Dockerfile)": {
|
||||||
|
"commandName": "Docker"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
8
MassTorrentAdd/appSettings.json
Normal file
8
MassTorrentAdd/appSettings.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"transmissionUserName": "transmission",
|
||||||
|
"transmissionPassword": "",
|
||||||
|
"transmissionURI": "",
|
||||||
|
//"watchFolder": "X:\\MP3\\Upload\\current",
|
||||||
|
"destinationFolder": "/pool/torrents/Animation",
|
||||||
|
"transmissionDownloadFolder": "/mnt/download/Upload"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user