Skip to content

Commit

Permalink
Merge branch 'develop2'
Browse files Browse the repository at this point in the history
  • Loading branch information
yar229 committed Jun 7, 2019
2 parents 94cf0d3 + 798ade0 commit af8e630
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 19 deletions.
11 changes: 6 additions & 5 deletions MailRuCloud/MailRuCloudApi/Base/File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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();

Expand All @@ -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
});
Expand All @@ -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";
}
Expand Down
3 changes: 3 additions & 0 deletions MailRuCloud/MailRuCloudApi/CloudSettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using YaR.MailRuCloud.Api.Base;
using YaR.MailRuCloud.Api.Common;

namespace YaR.MailRuCloud.Api
{
Expand All @@ -20,5 +21,7 @@ public int ListDepth

public string SpecialCommandPrefix { get; set; } = ">>";
public string AdditionalSpecialCommandPrefix { get; set; } = ">>";

public SharedVideoResolution DefaultSharedVideoResolution { get; set; } = SharedVideoResolution.All;
}
}
20 changes: 20 additions & 0 deletions MailRuCloud/MailRuCloudApi/Common/SharedVideoResolution.cs
Original file line number Diff line number Diff line change
@@ -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
}
}
44 changes: 44 additions & 0 deletions MailRuCloud/MailRuCloudApi/Extensions/EnumExtensions.cs
Original file line number Diff line number Diff line change
@@ -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<T>(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<EnumMemberAttribute>().
FirstOrDefault();
if (attr == null)
return @enum.ToString();
return attr.Value;
}
}
}
10 changes: 6 additions & 4 deletions MailRuCloud/MailRuCloudApi/MailRuCloud.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ private async Task<string> Publish(string fullPath)
return res.Url;
}

public async Task<PublishInfo> Publish(File file, bool makeShareFile = true, bool generateDirectVideoLink = false, bool makeM3UFile = false)
public async Task<PublishInfo> 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}");
Expand All @@ -262,7 +263,7 @@ public async Task<PublishInfo> 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)
{
Expand Down Expand Up @@ -307,12 +308,13 @@ public async Task<PublishInfo> Publish(Folder folder, bool makeShareFile = true)
return info;
}

public async Task<PublishInfo> Publish(IEntry entry, bool makeShareFile = true, bool generateDirectVideoLink = false, bool makeM3UFile = false)
public async Task<PublishInfo> 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);

Expand Down
4 changes: 2 additions & 2 deletions MailRuCloud/MailRuCloudApi/MailRuCloudApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<TargetFrameworks>netcoreapp2.2;net461</TargetFrameworks>
<RootNamespace>YaR.MailRuCloud.Api</RootNamespace>
<AssemblyName>MailRuCloud.Api</AssemblyName>
<AssemblyVersion>1.10.6.0</AssemblyVersion>
<FileVersion>1.10.6.0</FileVersion>
<AssemblyVersion>1.10.7.0</AssemblyVersion>
<FileVersion>1.10.7.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
13 changes: 10 additions & 3 deletions MailRuCloud/MailRuCloudApi/SpecialCommands/ShareCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -18,12 +20,17 @@ public ShareCommand(MailRuCloud cloud, string path, bool generateDirectVideoLink
private readonly bool _generateDirectVideoLink;
private readonly bool _makeM3UFile;

protected override MinMax<int> MinMaxParamsCount { get; } = new MinMax<int>(0, 1);
protected override MinMax<int> MinMaxParamsCount { get; } = new MinMax<int>(0, 2);

public override async Task<SpecialCommandResult> 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<SharedVideoResolution>(Parames[1]);

if (Parames.Count == 0)
path = Path;
Expand All @@ -38,7 +45,7 @@ public override async Task<SpecialCommandResult> Execute()

try
{
await Cloud.Publish(entry, true, _generateDirectVideoLink, _makeM3UFile);
await Cloud.Publish(entry, true, _generateDirectVideoLink, _makeM3UFile, videoResolution);
}
catch (Exception e)
{
Expand Down
19 changes: 19 additions & 0 deletions WDMRC.Console/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<SharedVideoResolution>(evalue);
return (SharedVideoResolution)res;
}
catch (Exception)
{
return SharedVideoResolution.All;
}
}
}
}
}
3 changes: 2 additions & 1 deletion WDMRC.Console/Payload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions WDMRC.Console/WDMRC.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<Copyright>[email protected]</Copyright>
<Description>WebDAV emulator for Cloud.mail.ru</Description>
<PackageId>WebDAVCloudMailRu</PackageId>
<AssemblyVersion>1.10.6.0</AssemblyVersion>
<FileVersion>1.10.6.0</FileVersion>
<AssemblyVersion>1.10.7.0</AssemblyVersion>
<FileVersion>1.10.7.0</FileVersion>
<AssemblyName>wdmrc</AssemblyName>
<RootNamespace>YaR.CloudMailRu.Console</RootNamespace>
<StartupObject></StartupObject>
Expand Down
12 changes: 12 additions & 0 deletions WDMRC.Console/wdmrc.config
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,17 @@
</TwoFactorAuthHandler>

<AdditionalSpecialCommandPrefix serializeAs="String">.,.</AdditionalSpecialCommandPrefix>

<!--
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
-->
<DefaultSharedVideoResolution serializeAs="String">0p</DefaultSharedVideoResolution>

</config>
15 changes: 13 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <br/>
- and create `.share.wdmrc` file with links
* `>>sharev [[/]path]` Make media file public <br/>
* `>>sharev [[/]path] [resolution]` Make media file public <br/>
- `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 <br/>
* `>>pl [[/]path] [resolution]` Make media file public <br/>
- `resolution` = `0p` (all), `240p`, `360p`, `480p`, `720p`, `1080p`
- and create `.share.wdmrc` file with public and direct play links <br/>
- and create `.m3u8` playlist file
* `>>crypt init` Mark current folder as encrypted
Expand All @@ -73,6 +75,15 @@ Parameters with spaces must be screened by quotes.
* Logging <br/>
`<config><log4net>` <br/>
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
`<config><DefaultSharedVideoResolution>` <br/>
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 <br/>
`<config><AdditionalSpecialCommandPrefix>` <br/>
custom special command prefix instead of `>>`. Make possible to use special commands if client doesn't allow `>>`.
Expand Down

0 comments on commit af8e630

Please sign in to comment.