From ac430d454ae07964cafb735c61db5e0779ee734e Mon Sep 17 00:00:00 2001 From: YaR Date: Fri, 7 Jun 2019 17:12:58 +0300 Subject: [PATCH 1/2] default m3u video resolution in settings and `>>sharev`/`>>pl` parameters --- MailRuCloud/MailRuCloudApi/Base/File.cs | 11 ++--- MailRuCloud/MailRuCloudApi/CloudSettings.cs | 3 ++ .../Common/SharedVideoResolution.cs | 20 +++++++++ .../Extensions/EnumExtensions.cs | 44 +++++++++++++++++++ MailRuCloud/MailRuCloudApi/MailRuCloud.cs | 10 +++-- .../SpecialCommands/ShareCommand.cs | 13 ++++-- WDMRC.Console/Config.cs | 19 ++++++++ WDMRC.Console/Payload.cs | 3 +- WDMRC.Console/wdmrc.config | 12 +++++ readme.md | 15 ++++++- 10 files changed, 135 insertions(+), 15 deletions(-) create mode 100644 MailRuCloud/MailRuCloudApi/Common/SharedVideoResolution.cs create mode 100644 MailRuCloud/MailRuCloudApi/Extensions/EnumExtensions.cs diff --git a/MailRuCloud/MailRuCloudApi/Base/File.cs b/MailRuCloud/MailRuCloudApi/Base/File.cs index 5937bd61..24f62c4a 100644 --- a/MailRuCloud/MailRuCloudApi/Base/File.cs +++ b/MailRuCloud/MailRuCloudApi/Base/File.cs @@ -9,8 +9,9 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.Linq; using YaR.MailRuCloud.Api.Base.Requests.Types; +using YaR.MailRuCloud.Api.Common; +using YaR.MailRuCloud.Api.Extensions; namespace YaR.MailRuCloud.Api.Base { @@ -176,7 +177,7 @@ public CryptoKeyInfo EnsurePublicKey(MailRuCloud cloud) return ServiceInfo.CryptInfo.PublicKey; } - public PublishInfo ToPublishInfo(MailRuCloud cloud, bool generateDirectVideoLink) + public PublishInfo ToPublishInfo(MailRuCloud cloud, bool generateDirectVideoLink, SharedVideoResolution videoResolution) { var info = new PublishInfo(); @@ -192,7 +193,7 @@ public PublishInfo ToPublishInfo(MailRuCloud cloud, bool generateDirectVideoLink Url = ConstSettings.PublishFileLink + innerFile.PublicLink, PlaylistUrl = !isSplitted || cnt > 0 ? generateDirectVideoLink - ? ConvertToVideoLink(cloud, innerFile.PublicLink) + ? ConvertToVideoLink(cloud, innerFile.PublicLink, videoResolution) : null : null }); @@ -202,10 +203,10 @@ public PublishInfo ToPublishInfo(MailRuCloud cloud, bool generateDirectVideoLink return info; } - private string ConvertToVideoLink(MailRuCloud cloud, string publicLink) + private string ConvertToVideoLink(MailRuCloud cloud, string publicLink, SharedVideoResolution videoResolution) { return cloud.Account.RequestRepo.GetShardInfo(ShardType.WeblinkVideo).Result.Url + - "0p/" + + videoResolution.ToEnumMemberValue() + "/" + //"0p/" + Base64Encode(publicLink.TrimStart('/')) + ".m3u8?double_encode=1"; } diff --git a/MailRuCloud/MailRuCloudApi/CloudSettings.cs b/MailRuCloud/MailRuCloudApi/CloudSettings.cs index 4605f125..3909060b 100644 --- a/MailRuCloud/MailRuCloudApi/CloudSettings.cs +++ b/MailRuCloud/MailRuCloudApi/CloudSettings.cs @@ -1,4 +1,5 @@ using YaR.MailRuCloud.Api.Base; +using YaR.MailRuCloud.Api.Common; namespace YaR.MailRuCloud.Api { @@ -20,5 +21,7 @@ public int ListDepth public string SpecialCommandPrefix { get; set; } = ">>"; public string AdditionalSpecialCommandPrefix { get; set; } = ">>"; + + public SharedVideoResolution DefaultSharedVideoResolution { get; set; } = SharedVideoResolution.All; } } \ No newline at end of file diff --git a/MailRuCloud/MailRuCloudApi/Common/SharedVideoResolution.cs b/MailRuCloud/MailRuCloudApi/Common/SharedVideoResolution.cs new file mode 100644 index 00000000..ef0e8d99 --- /dev/null +++ b/MailRuCloud/MailRuCloudApi/Common/SharedVideoResolution.cs @@ -0,0 +1,20 @@ +using System.Runtime.Serialization; + +namespace YaR.MailRuCloud.Api.Common +{ + public enum SharedVideoResolution + { + [EnumMember(Value = "0p")] + All, + [EnumMember(Value = "240p")] + R240, + [EnumMember(Value = "360p")] + R360, + [EnumMember(Value = "480p")] + R480, + [EnumMember(Value = "720p")] + R720, + [EnumMember(Value = "1080p")] + R1080 + } +} \ No newline at end of file diff --git a/MailRuCloud/MailRuCloudApi/Extensions/EnumExtensions.cs b/MailRuCloud/MailRuCloudApi/Extensions/EnumExtensions.cs new file mode 100644 index 00000000..e8af19a4 --- /dev/null +++ b/MailRuCloud/MailRuCloudApi/Extensions/EnumExtensions.cs @@ -0,0 +1,44 @@ +using System; +using System.Linq; +using System.Reflection; +using System.Runtime.Serialization; + +namespace YaR.MailRuCloud.Api.Extensions +{ + public static class EnumExtensions + { + public static T ParseEnumMemberValue(string stringValue, bool ignoreCase = true) + where T: Enum + { + T output = default; + string enumStringValue = null; + + var type = typeof(T); + foreach (FieldInfo fi in type.GetFields()) + { + if (fi.GetCustomAttributes(typeof (EnumMemberAttribute), false) is EnumMemberAttribute[] attrs && attrs.Length > 0) + enumStringValue = attrs[0].Value; + + if (string.Compare(enumStringValue, stringValue, ignoreCase) == 0) + { + output = (T)Enum.Parse(type, fi.Name); + break; + } + } + + return output; + } + + public static string ToEnumMemberValue(this Enum @enum) + { + var attr = @enum.GetType() + .GetMember(@enum.ToString()).FirstOrDefault()? + .GetCustomAttributes(false) + .OfType(). + FirstOrDefault(); + if (attr == null) + return @enum.ToString(); + return attr.Value; + } + } +} diff --git a/MailRuCloud/MailRuCloudApi/MailRuCloud.cs b/MailRuCloud/MailRuCloudApi/MailRuCloud.cs index 2a53e713..9cc54442 100644 --- a/MailRuCloud/MailRuCloudApi/MailRuCloud.cs +++ b/MailRuCloud/MailRuCloudApi/MailRuCloud.cs @@ -252,7 +252,8 @@ private async Task Publish(string fullPath) return res.Url; } - public async Task Publish(File file, bool makeShareFile = true, bool generateDirectVideoLink = false, bool makeM3UFile = false) + public async Task Publish(File file, bool makeShareFile = true, + bool generateDirectVideoLink = false, bool makeM3UFile = false, SharedVideoResolution videoResolution = SharedVideoResolution.All) { if (file.Files.Count > 1 && (generateDirectVideoLink || makeM3UFile)) throw new ArgumentException($"Cannot generate direct video link for splitted file {file.FullPath}"); @@ -262,7 +263,7 @@ public async Task Publish(File file, bool makeShareFile = true, boo var url = await Publish(innerFile.FullPath); innerFile.PublicLink = url; } - var info = file.ToPublishInfo(this, generateDirectVideoLink); + var info = file.ToPublishInfo(this, generateDirectVideoLink, videoResolution); if (makeShareFile) { @@ -307,12 +308,13 @@ public async Task Publish(Folder folder, bool makeShareFile = true) return info; } - public async Task Publish(IEntry entry, bool makeShareFile = true, bool generateDirectVideoLink = false, bool makeM3UFile = false) + public async Task Publish(IEntry entry, bool makeShareFile = true, + bool generateDirectVideoLink = false, bool makeM3UFile = false, SharedVideoResolution videoResolution = SharedVideoResolution.All) { if (null == entry) throw new ArgumentNullException(nameof(entry)); if (entry is File file) - return await Publish(file, makeShareFile, generateDirectVideoLink, makeM3UFile); + return await Publish(file, makeShareFile, generateDirectVideoLink, makeM3UFile, videoResolution); if (entry is Folder folder) return await Publish(folder, makeShareFile); diff --git a/MailRuCloud/MailRuCloudApi/SpecialCommands/ShareCommand.cs b/MailRuCloud/MailRuCloudApi/SpecialCommands/ShareCommand.cs index 2ba67f9d..789a9505 100644 --- a/MailRuCloud/MailRuCloudApi/SpecialCommands/ShareCommand.cs +++ b/MailRuCloud/MailRuCloudApi/SpecialCommands/ShareCommand.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.Threading.Tasks; using YaR.MailRuCloud.Api.Base; +using YaR.MailRuCloud.Api.Common; +using YaR.MailRuCloud.Api.Extensions; namespace YaR.MailRuCloud.Api.SpecialCommands { @@ -18,12 +20,17 @@ public ShareCommand(MailRuCloud cloud, string path, bool generateDirectVideoLink private readonly bool _generateDirectVideoLink; private readonly bool _makeM3UFile; - protected override MinMax MinMaxParamsCount { get; } = new MinMax(0, 1); + protected override MinMax MinMaxParamsCount { get; } = new MinMax(0, 2); public override async Task Execute() { string path; - string param = Parames.Count == 0 ? string.Empty : Parames[0].Replace("\\", WebDavPath.Separator); + string param = Parames.Count == 0 + ? string.Empty + : Parames[0].Replace("\\", WebDavPath.Separator); + SharedVideoResolution videoResolution = Parames.Count < 2 + ? Cloud.Settings.DefaultSharedVideoResolution + : EnumExtensions.ParseEnumMemberValue(Parames[1]); if (Parames.Count == 0) path = Path; @@ -38,7 +45,7 @@ public override async Task Execute() try { - await Cloud.Publish(entry, true, _generateDirectVideoLink, _makeM3UFile); + await Cloud.Publish(entry, true, _generateDirectVideoLink, _makeM3UFile, videoResolution); } catch (Exception e) { diff --git a/WDMRC.Console/Config.cs b/WDMRC.Console/Config.cs index 3d13a13d..55371a1e 100644 --- a/WDMRC.Console/Config.cs +++ b/WDMRC.Console/Config.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.IO; using System.Xml; +using YaR.MailRuCloud.Api.Common; +using YaR.MailRuCloud.Api.Extensions; using YaR.WebDavMailRu.CloudStore; namespace YaR.CloudMailRu.Console @@ -60,5 +62,22 @@ public static string AdditionalSpecialCommandPrefix } } + + public static SharedVideoResolution DefaultSharedVideoResolution + { + get + { + try + { + string evalue = Document.SelectSingleNode("/config/DefaultSharedVideoResolution").InnerText; + var res = EnumExtensions.ParseEnumMemberValue(evalue); + return (SharedVideoResolution)res; + } + catch (Exception) + { + return SharedVideoResolution.All; + } + } + } } } \ No newline at end of file diff --git a/WDMRC.Console/Payload.cs b/WDMRC.Console/Payload.cs index 5a52ed64..c2c718be 100644 --- a/WDMRC.Console/Payload.cs +++ b/WDMRC.Console/Payload.cs @@ -45,7 +45,8 @@ public static void Run(CommandLineOptions options) UserAgent = options.UserAgent, CacheListingSec = options.CacheListingSec, ListDepth = options.CacheListingDepth, - AdditionalSpecialCommandPrefix = Config.AdditionalSpecialCommandPrefix + AdditionalSpecialCommandPrefix = Config.AdditionalSpecialCommandPrefix, + DefaultSharedVideoResolution = Config.DefaultSharedVideoResolution }; ShowInfo(options); diff --git a/WDMRC.Console/wdmrc.config b/WDMRC.Console/wdmrc.config index 8a693d14..55e62e0d 100644 --- a/WDMRC.Console/wdmrc.config +++ b/WDMRC.Console/wdmrc.config @@ -51,5 +51,17 @@ .,. + + + 0p \ No newline at end of file diff --git a/readme.md b/readme.md index 32630a91..f4cd0a3b 100644 --- a/readme.md +++ b/readme.md @@ -61,9 +61,11 @@ Parameters with spaces must be screened by quotes. * `>>del [[/]path]` Fast delete (if your client makes recursive deletions of inner items) * `>>share [[/]path]` Make file/folder public
- and create `.share.wdmrc` file with links -* `>>sharev [[/]path]` Make media file public
+* `>>sharev [[/]path] [resolution]` Make media file public
+ - `resolution` = `0p` (all), `240p`, `360p`, `480p`, `720p`, `1080p` - and create `.share.wdmrc` file with public and direct play links -* `>>pl [[/]path]` Make media file public
+* `>>pl [[/]path] [resolution]` Make media file public
+ - `resolution` = `0p` (all), `240p`, `360p`, `480p`, `720p`, `1080p` - and create `.share.wdmrc` file with public and direct play links
- and create `.m3u8` playlist file * `>>crypt init` Mark current folder as encrypted @@ -73,6 +75,15 @@ Parameters with spaces must be screened by quotes. * Logging
``
It's standart [Apache log4net](https://logging.apache.org/log4net/) configurations, take a look for [examples](https://logging.apache.org/log4net/release/config-examples.html) +* Default video resolution for generated m3u playlists + ``
+ Values: + `0p` auto, m3u contains links to all availiable resolutions + `240p` ~ 352 x 240 + `360p` ~ 480 x 360 + `480p` ~ 858 x 480 + `720p` ~ 1280 x 720 + `1080p` ~ 1920 x 1080 * Special command prefix
``
custom special command prefix instead of `>>`. Make possible to use special commands if client doesn't allow `>>`. From 798ade0d7a40ac66c4910845186e37357937c8da Mon Sep 17 00:00:00 2001 From: YaR Date: Fri, 7 Jun 2019 17:15:17 +0300 Subject: [PATCH 2/2] version bump 1.10.7.0 --- MailRuCloud/MailRuCloudApi/MailRuCloudApi.csproj | 4 ++-- WDMRC.Console/WDMRC.Console.csproj | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/MailRuCloud/MailRuCloudApi/MailRuCloudApi.csproj b/MailRuCloud/MailRuCloudApi/MailRuCloudApi.csproj index 525af4fd..9fc27ec0 100644 --- a/MailRuCloud/MailRuCloudApi/MailRuCloudApi.csproj +++ b/MailRuCloud/MailRuCloudApi/MailRuCloudApi.csproj @@ -5,8 +5,8 @@ netcoreapp2.2;net461 YaR.MailRuCloud.Api MailRuCloud.Api - 1.10.6.0 - 1.10.6.0 + 1.10.7.0 + 1.10.7.0 diff --git a/WDMRC.Console/WDMRC.Console.csproj b/WDMRC.Console/WDMRC.Console.csproj index 5173c8d7..e8aee266 100644 --- a/WDMRC.Console/WDMRC.Console.csproj +++ b/WDMRC.Console/WDMRC.Console.csproj @@ -11,8 +11,8 @@ yar229@yandex.ru WebDAV emulator for Cloud.mail.ru WebDAVCloudMailRu - 1.10.6.0 - 1.10.6.0 + 1.10.7.0 + 1.10.7.0 wdmrc YaR.CloudMailRu.Console