Crunchy-Downloader/CRD/Utils/Parser/Playlists/ParseAttribute.cs
Elwador 95cd06a523 Add - Added path reset buttons to Temp Folder Path, Download Folder, and Background Image settings
Add - Added background image option to the Appearance settings
Add - Background Image Settings - Added new options to control opacity and blur radius
Add - Added "Couldn't sync dubs" status if the syncing failed
Add - Added functionality to combine multiple episodes from the same season into a single entry in the calendar
Add - Added video resolution display next to dubs/subs in the downloads tab
Add - Added Cloudflare check to image loading
Add - Added hardsub selection if the current is not available
Add - Added part size setting to configure the size of parts downloaded at the same time
Add - Added quality override to history series
Add - Added history marker to search results to indicate if a series is already in the user's history
Add - Added seasons tab for seasonal releases (Spring, Summer, Fall, Winter)
Add - Added potential releases and release times for the current day and the next week to the custom calendar
Chg - Changed Calendar cards background color for improved visibility
Chg - Combined Appearance settings into a single section in the settings tab
Chg - Consolidated Debug settings into one settings expander for better organization
Chg - Changed time sync to now check both the start and end of the video
Chg - Changed encoding progress to be displayed by the progress bar
Chg - Updated the functionality for hiding dubs in the custom calendar
Chg - Adjusted Dub sync to improve accuracy, resolving issues where it failed for more episodes than expected
Chg - Subtitles and dubs are now sorted according to the order selected in the MKV file
Chg - Changed logout behavior to correctly log out if login fails when starting the downloader
Chg - Changed that all downloaded files are removed if an in-progress download is removed from the queue
Chg - Changed default profile image
Chg - Updated used packages to the newest version
Chg - Separated settings to separate tabs
Fix - Fixed some series didn't get added to the history
Fix - Fixed an issue with file path length that prevented some files from being accessed properly
Fix - Fixed an issue where file names exceeded the maximum allowable length, causing errors
Fix - Fixed an issue where refreshing a series could get stuck
Fix - Fixed a crash that could happen with the syncing
Fix - Fixed an issue where the download status showed "Done" while moving files from the temp folder
Fix - Fixed an issue where cookies were not being utilized correctly
Fix - Resolved issues with displaying dates in UTC format
Fix - Fixed an issue with incorrect calendar grouping
Fix - Fixed an issue with the previous week navigation in the calendar
Fix - Fixed an issue where the calendar would not display correctly when not logged in
Fix - Fixed incorrect FFmpeg check for other OS (Linux/macOS)
Fix - Fixed an issue where image loading used a different HTTP client
2024-12-19 19:01:50 +01:00

320 lines
No EOL
14 KiB
C#

using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Xml;
using CRD.Utils.Parser.Utils;
namespace CRD.Utils.Parser;
public class ParseAttribute{
public static Dictionary<string, Func<string, object>> ParsersDictionary = new Dictionary<string, Func<string, object>>{
{ "mediaPresentationDuration", MediaPresentationDuration },
{ "availabilityStartTime", AvailabilityStartTime },
{ "minimumUpdatePeriod", MinimumUpdatePeriod },
{ "suggestedPresentationDelay", SuggestedPresentationDelay },
{ "type", Type },
{ "timeShiftBufferDepth", TimeShiftBufferDepth },
{ "start", Start },
{ "width", Width },
{ "height", Height },
{ "bandwidth", Bandwidth },
{ "frameRate", FrameRate },
{ "startNumber", StartNumber },
{ "timescale", Timescale },
{ "presentationTimeOffset", PresentationTimeOffset },
{ "duration", Duration },
{ "d", D },
{ "t", T },
{ "r", R },
{ "presentationTime", PresentationTime },
{ "DEFAULT", DefaultParser }
};
public static object MediaPresentationDuration(string value) => DurationParser.ParseDuration(value);
public static object AvailabilityStartTime(string value) => DurationParser.ParseDate(value) / 1000;
public static object MinimumUpdatePeriod(string value) => DurationParser.ParseDuration(value);
public static object SuggestedPresentationDelay(string value) => DurationParser.ParseDuration(value);
public static object Type(string value) => value;
public static object TimeShiftBufferDepth(string value) => DurationParser.ParseDuration(value);
public static object Start(string value) => DurationParser.ParseDuration(value);
public static object Width(string value) => int.Parse(value);
public static object Height(string value) => int.Parse(value);
public static object Bandwidth(string value) => int.Parse(value);
public static object FrameRate(string value) => DivisionValueParser.ParseDivisionValue(value);
public static object StartNumber(string value) => int.Parse(value);
public static object Timescale(string value) => int.Parse(value);
public static object PresentationTimeOffset(string value) => int.Parse(value);
public static object Duration(string value){
if (int.TryParse(value, out int parsedValue)){
return parsedValue;
}
return DurationParser.ParseDuration(value);
}
public static object D(string value) => int.Parse(value);
public static object T(string value) => int.Parse(value);
public static object R(string value) => int.Parse(value);
public static object PresentationTime(string value) => int.Parse(value);
public static object DefaultParser(string value) => value;
// public static Dictionary<string, object> ParseAttributes(XmlNode el)
// {
// if (!(el != null && el.Attributes != null))
// {
// return new Dictionary<string, object>();
// }
//
// return el.Attributes.Cast<XmlAttribute>()
// .ToDictionary(attr => attr.Name, attr =>
// {
// Func<string, object> parseFn;
// if (ParsersDictionary.TryGetValue(attr.Name, out parseFn))
// {
// return parseFn(attr.Value);
// }
// return DefaultParser(attr.Value);
// });
// }
public static dynamic ParseAttributes(XmlNode el){
var expandoObj = new ExpandoObject() as IDictionary<string, object>;
if (el != null && el.Attributes != null){
foreach (XmlAttribute attr in el.Attributes){
Func<string, object> parseFn;
if (ParsersDictionary.TryGetValue(attr.Name, out parseFn)){
expandoObj[attr.Name] = parseFn(attr.Value);
} else{
expandoObj[attr.Name] = DefaultParser(attr.Value);
}
}
}
return expandoObj;
}
}
// public class ParsedAttributes{
// public double MediaPresentationDuration{ get; set; }
// public long AvailabilityStartTime{ get; set; }
// public double MinimumUpdatePeriod{ get; set; }
// public double SuggestedPresentationDelay{ get; set; }
// public string Type{ get; set; }
// public double TimeShiftBufferDepth{ get; set; }
// public double? Start{ get; set; }
// public int Width{ get; set; }
// public int Height{ get; set; }
// public int Bandwidth{ get; set; }
// public double FrameRate{ get; set; }
// public int StartNumber{ get; set; }
// public int Timescale{ get; set; }
// public int PresentationTimeOffset{ get; set; }
// public double? Duration{ get; set; }
// public int D{ get; set; }
// public int T{ get; set; }
// public int R{ get; set; }
// public int PresentationTime{ get; set; }
//
// public int clientOffset{ get; set; }
//
// public long NOW{ get; set; }
// public double sourceDuration{ get; set; }
// public List<string> locations{ get; set; }
// public string baseUrl{ get; set; }
// public string? serviceLocation{ get; set; }
//
// public ParsedAttributes(){
//
// }
//
// public ParsedAttributes(
// double mediaPresentationDuration,
// long availabilityStartTime,
// double minimumUpdatePeriod,
// double suggestedPresentationDelay,
// string type,
// double timeShiftBufferDepth,
// double? start,
// int width,
// int height,
// int bandwidth,
// double frameRate,
// int startNumber,
// int timescale,
// int presentationTimeOffset,
// double? duration,
// int d,
// int t,
// int r,
// int presentationTime){
// MediaPresentationDuration = mediaPresentationDuration;
// AvailabilityStartTime = availabilityStartTime;
// MinimumUpdatePeriod = minimumUpdatePeriod;
// SuggestedPresentationDelay = suggestedPresentationDelay;
// Type = type;
// TimeShiftBufferDepth = timeShiftBufferDepth;
// Start = start;
// Width = width;
// Height = height;
// Bandwidth = bandwidth;
// FrameRate = frameRate;
// StartNumber = startNumber;
// Timescale = timescale;
// PresentationTimeOffset = presentationTimeOffset;
// Duration = duration;
// D = d;
// T = t;
// R = r;
// PresentationTime = presentationTime;
// }
// }
//
// public class ParseAttribute{
// public static Dictionary<string, Func<string, object>> ParsersDictionary = new Dictionary<string, Func<string, object>>{
// { "mediaPresentationDuration", MediaPresentationDuration },
// { "availabilityStartTime", AvailabilityStartTime },
// { "minimumUpdatePeriod", MinimumUpdatePeriod },
// { "suggestedPresentationDelay", SuggestedPresentationDelay },
// { "type", Type },
// { "timeShiftBufferDepth", TimeShiftBufferDepth },
// { "start", Start },
// { "width", Width },
// { "height", Height },
// { "bandwidth", Bandwidth },
// { "frameRate", FrameRate },
// { "startNumber", StartNumber },
// { "timescale", Timescale },
// { "presentationTimeOffset", PresentationTimeOffset },
// { "duration", Duration },
// { "d", D },
// { "t", T },
// { "r", R },
// { "presentationTime", PresentationTime },
// { "DEFAULT", DefaultParser }
// };
//
// public static object MediaPresentationDuration(string value) => DurationParser.ParseDuration(value);
// public static object AvailabilityStartTime(string value) => DurationParser.ParseDate(value) / 1000;
// public static object MinimumUpdatePeriod(string value) => DurationParser.ParseDuration(value);
// public static object SuggestedPresentationDelay(string value) => DurationParser.ParseDuration(value);
// public static object Type(string value) => value;
// public static object TimeShiftBufferDepth(string value) => DurationParser.ParseDuration(value);
// public static object Start(string value) => DurationParser.ParseDuration(value);
// public static object Width(string value) => int.Parse(value);
// public static object Height(string value) => int.Parse(value);
// public static object Bandwidth(string value) => int.Parse(value);
// public static object FrameRate(string value) => DivisionValueParser.ParseDivisionValue(value);
// public static object StartNumber(string value) => int.Parse(value);
// public static object Timescale(string value) => int.Parse(value);
// public static object PresentationTimeOffset(string value) => int.Parse(value);
//
// public static object Duration(string value){
// if (int.TryParse(value, out int parsedValue)){
// return parsedValue;
// }
//
// return DurationParser.ParseDuration(value);
// }
//
// public static object D(string value) => int.Parse(value);
// public static object T(string value) => int.Parse(value);
// public static object R(string value) => int.Parse(value);
// public static object PresentationTime(string value) => int.Parse(value);
// public static object DefaultParser(string value) => value;
//
// public static ParsedAttributes ParseAttributes(XmlNode el){
// if (!(el != null && el.Attributes != null)){
// return new ParsedAttributes(0, 0, 0, 0, "", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
// }
// double mediaPresentationDuration = 0;
// long availabilityStartTime = 0;
// double minimumUpdatePeriod = 0;
// double suggestedPresentationDelay = 0;
// string type = "";
// double timeShiftBufferDepth = 0;
// double? start = null;
// int width = 0;
// int height = 0;
// int bandwidth = 0;
// double frameRate = 0;
// int startNumber = 0;
// int timescale = 0;
// int presentationTimeOffset = 0;
// double? duration = null;
// int d = 0;
// int t = 0;
// int r = 0;
// int presentationTime = 0;
//
// foreach (XmlAttribute attr in el.Attributes){
// Func<string, object> parseFn;
// if (ParsersDictionary.TryGetValue(attr.Name, out parseFn)){
// switch (attr.Name){
// case "mediaPresentationDuration":
// mediaPresentationDuration = (double)parseFn(attr.Value);
// break;
// case "availabilityStartTime":
// availabilityStartTime = (long)parseFn(attr.Value);
// break;
// case "minimumUpdatePeriod":
// minimumUpdatePeriod = (double)parseFn(attr.Value);
// break;
// case "suggestedPresentationDelay":
// suggestedPresentationDelay = (double)parseFn(attr.Value);
// break;
// case "type":
// type = (string)parseFn(attr.Value);
// break;
// case "timeShiftBufferDepth":
// timeShiftBufferDepth = (double)parseFn(attr.Value);
// break;
// case "start":
// start = (double)parseFn(attr.Value);
// break;
// case "width":
// width = (int)parseFn(attr.Value);
// break;
// case "height":
// height = (int)parseFn(attr.Value);
// break;
// case "bandwidth":
// bandwidth = (int)parseFn(attr.Value);
// break;
// case "frameRate":
// frameRate = (double)parseFn(attr.Value);
// break;
// case "startNumber":
// startNumber = (int)parseFn(attr.Value);
// break;
// case "timescale":
// timescale = (int)parseFn(attr.Value);
// break;
// case "presentationTimeOffset":
// presentationTimeOffset = (int)parseFn(attr.Value);
// break;
// case "duration":
// duration = (double)parseFn(attr.Value);
// break;
// case "d":
// d = (int)parseFn(attr.Value);
// break;
// case "t":
// t = (int)parseFn(attr.Value);
// break;
// case "r":
// r = (int)parseFn(attr.Value);
// break;
// case "presentationTime":
// presentationTime = (int)parseFn(attr.Value);
// break;
// // Add cases for other attributes
// }
// }
// }
//
// return new ParsedAttributes(mediaPresentationDuration, availabilityStartTime, minimumUpdatePeriod, suggestedPresentationDelay, type, timeShiftBufferDepth, start, width, height, bandwidth, frameRate, startNumber,
// timescale, presentationTimeOffset, duration, d, t, r, presentationTime);
// }
// }