├── .gitattributes
├── .gitignore
├── IDManTypeInfo.zip
├── LICENSE
├── OnedriveShareLinkParser.sln
├── OnedriveShareLinkParser
├── App.config
├── App.xaml
├── App.xaml.cs
├── AutoNumberValueConverter.cs
├── FodyWeavers.xml
├── FodyWeavers.xsd
├── MainWindow.xaml
├── MainWindow.xaml.cs
├── ODItem.cs
├── OnedriveShareLinkParser.csproj
├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
├── Util.cs
└── packages.config
└── README.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | project.fragment.lock.json
46 | artifacts/
47 |
48 | *_i.c
49 | *_p.c
50 | *_i.h
51 | *.ilk
52 | *.meta
53 | *.obj
54 | *.pch
55 | *.pdb
56 | *.pgc
57 | *.pgd
58 | *.rsp
59 | *.sbr
60 | *.tlb
61 | *.tli
62 | *.tlh
63 | *.tmp
64 | *.tmp_proj
65 | *.log
66 | *.vspscc
67 | *.vssscc
68 | .builds
69 | *.pidb
70 | *.svclog
71 | *.scc
72 |
73 | # Chutzpah Test files
74 | _Chutzpah*
75 |
76 | # Visual C++ cache files
77 | ipch/
78 | *.aps
79 | *.ncb
80 | *.opendb
81 | *.opensdf
82 | *.sdf
83 | *.cachefile
84 | *.VC.db
85 | *.VC.VC.opendb
86 |
87 | # Visual Studio profiler
88 | *.psess
89 | *.vsp
90 | *.vspx
91 | *.sap
92 |
93 | # TFS 2012 Local Workspace
94 | $tf/
95 |
96 | # Guidance Automation Toolkit
97 | *.gpState
98 |
99 | # ReSharper is a .NET coding add-in
100 | _ReSharper*/
101 | *.[Rr]e[Ss]harper
102 | *.DotSettings.user
103 |
104 | # JustCode is a .NET coding add-in
105 | .JustCode
106 |
107 | # TeamCity is a build add-in
108 | _TeamCity*
109 |
110 | # DotCover is a Code Coverage Tool
111 | *.dotCover
112 |
113 | # NCrunch
114 | _NCrunch_*
115 | .*crunch*.local.xml
116 | nCrunchTemp_*
117 |
118 | # MightyMoose
119 | *.mm.*
120 | AutoTest.Net/
121 |
122 | # Web workbench (sass)
123 | .sass-cache/
124 |
125 | # Installshield output folder
126 | [Ee]xpress/
127 |
128 | # DocProject is a documentation generator add-in
129 | DocProject/buildhelp/
130 | DocProject/Help/*.HxT
131 | DocProject/Help/*.HxC
132 | DocProject/Help/*.hhc
133 | DocProject/Help/*.hhk
134 | DocProject/Help/*.hhp
135 | DocProject/Help/Html2
136 | DocProject/Help/html
137 |
138 | # Click-Once directory
139 | publish/
140 |
141 | # Publish Web Output
142 | *.[Pp]ublish.xml
143 | *.azurePubxml
144 | # TODO: Comment the next line if you want to checkin your web deploy settings
145 | # but database connection strings (with potential passwords) will be unencrypted
146 | #*.pubxml
147 | *.publishproj
148 |
149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
150 | # checkin your Azure Web App publish settings, but sensitive information contained
151 | # in these scripts will be unencrypted
152 | PublishScripts/
153 |
154 | # NuGet Packages
155 | *.nupkg
156 | # The packages folder can be ignored because of Package Restore
157 | **/packages/*
158 | # except build/, which is used as an MSBuild target.
159 | !**/packages/build/
160 | # Uncomment if necessary however generally it will be regenerated when needed
161 | #!**/packages/repositories.config
162 | # NuGet v3's project.json files produces more ignoreable files
163 | *.nuget.props
164 | *.nuget.targets
165 |
166 | # Microsoft Azure Build Output
167 | csx/
168 | *.build.csdef
169 |
170 | # Microsoft Azure Emulator
171 | ecf/
172 | rcf/
173 |
174 | # Windows Store app package directories and files
175 | AppPackages/
176 | BundleArtifacts/
177 | Package.StoreAssociation.xml
178 | _pkginfo.txt
179 |
180 | # Visual Studio cache files
181 | # files ending in .cache can be ignored
182 | *.[Cc]ache
183 | # but keep track of directories ending in .cache
184 | !*.[Cc]ache/
185 |
186 | # Others
187 | ClientBin/
188 | ~$*
189 | *~
190 | *.dbmdl
191 | *.dbproj.schemaview
192 | *.jfm
193 | *.pfx
194 | *.publishsettings
195 | node_modules/
196 | orleans.codegen.cs
197 |
198 | # Since there are multiple workflows, uncomment next line to ignore bower_components
199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
200 | #bower_components/
201 |
202 | # RIA/Silverlight projects
203 | Generated_Code/
204 |
205 | # Backup & report files from converting an old project file
206 | # to a newer Visual Studio version. Backup files are not needed,
207 | # because we have git ;-)
208 | _UpgradeReport_Files/
209 | Backup*/
210 | UpgradeLog*.XML
211 | UpgradeLog*.htm
212 |
213 | # SQL Server files
214 | *.mdf
215 | *.ldf
216 |
217 | # Business Intelligence projects
218 | *.rdl.data
219 | *.bim.layout
220 | *.bim_*.settings
221 |
222 | # Microsoft Fakes
223 | FakesAssemblies/
224 |
225 | # GhostDoc plugin setting file
226 | *.GhostDoc.xml
227 |
228 | # Node.js Tools for Visual Studio
229 | .ntvs_analysis.dat
230 |
231 | # Visual Studio 6 build log
232 | *.plg
233 |
234 | # Visual Studio 6 workspace options file
235 | *.opt
236 |
237 | # Visual Studio LightSwitch build output
238 | **/*.HTMLClient/GeneratedArtifacts
239 | **/*.DesktopClient/GeneratedArtifacts
240 | **/*.DesktopClient/ModelManifest.xml
241 | **/*.Server/GeneratedArtifacts
242 | **/*.Server/ModelManifest.xml
243 | _Pvt_Extensions
244 |
245 | # Paket dependency manager
246 | .paket/paket.exe
247 | paket-files/
248 |
249 | # FAKE - F# Make
250 | .fake/
251 |
252 | # JetBrains Rider
253 | .idea/
254 | *.sln.iml
255 |
256 | # CodeRush
257 | .cr/
258 |
259 | # Python Tools for Visual Studio (PTVS)
260 | __pycache__/
261 | *.pyc
--------------------------------------------------------------------------------
/IDManTypeInfo.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nilaoda/OneDriveShareLinkParser/2efb46edfa42184f05cf87ecd32a147f761ca248/IDManTypeInfo.zip
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 nilaoda
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/OnedriveShareLinkParser.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.31515.178
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OnedriveShareLinkParser", "OnedriveShareLinkParser\OnedriveShareLinkParser.csproj", "{047CC374-B76F-4B6E-A9C4-87E16B1A693B}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {047CC374-B76F-4B6E-A9C4-87E16B1A693B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {047CC374-B76F-4B6E-A9C4-87E16B1A693B}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {047CC374-B76F-4B6E-A9C4-87E16B1A693B}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {047CC374-B76F-4B6E-A9C4-87E16B1A693B}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | GlobalSection(ExtensibilityGlobals) = postSolution
23 | SolutionGuid = {9E3A073E-7C3B-4036-9C4D-5580A587963B}
24 | EndGlobalSection
25 | EndGlobal
26 |
--------------------------------------------------------------------------------
/OnedriveShareLinkParser/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/OnedriveShareLinkParser/App.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/OnedriveShareLinkParser/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Configuration;
4 | using System.Data;
5 | using System.Linq;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 |
9 | namespace WpfApp1
10 | {
11 | ///
12 | /// App.xaml 的交互逻辑
13 | ///
14 | public partial class App : Application
15 | {
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/OnedriveShareLinkParser/AutoNumberValueConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows.Controls;
7 | using System.Windows.Data;
8 |
9 | namespace OnedriveShareLinkParser
10 | {
11 | //https://www.cnblogs.com/hoze/p/5103037.html
12 | class AutoNumberValueConverter : IMultiValueConverter
13 | {
14 | #region IMultiValueConverter 成员
15 |
16 | public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
17 | {
18 | var item = values[0];
19 | var items = values[1] as ItemCollection;
20 |
21 | var index = items.IndexOf(item);
22 | return (index + 1).ToString();
23 | }
24 |
25 | public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
26 | {
27 | return null;
28 | }
29 |
30 | #endregion
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/OnedriveShareLinkParser/FodyWeavers.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/OnedriveShareLinkParser/FodyWeavers.xsd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks
13 |
14 |
15 |
16 |
17 | A list of assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks.
18 |
19 |
20 |
21 |
22 | A list of unmanaged 32 bit assembly names to include, delimited with line breaks.
23 |
24 |
25 |
26 |
27 | A list of unmanaged 64 bit assembly names to include, delimited with line breaks.
28 |
29 |
30 |
31 |
32 | The order of preloaded assemblies, delimited with line breaks.
33 |
34 |
35 |
36 |
37 |
38 | This will copy embedded files to disk before loading them into memory. This is helpful for some scenarios that expected an assembly to be loaded from a physical file.
39 |
40 |
41 |
42 |
43 | Controls if .pdbs for reference assemblies are also embedded.
44 |
45 |
46 |
47 |
48 | Embedded assemblies are compressed by default, and uncompressed when they are loaded. You can turn compression off with this option.
49 |
50 |
51 |
52 |
53 | As part of Costura, embedded assemblies are no longer included as part of the build. This cleanup can be turned off.
54 |
55 |
56 |
57 |
58 | Costura by default will load as part of the module initialization. This flag disables that behavior. Make sure you call CosturaUtility.Initialize() somewhere in your code.
59 |
60 |
61 |
62 |
63 | Costura will by default use assemblies with a name like 'resources.dll' as a satellite resource and prepend the output path. This flag disables that behavior.
64 |
65 |
66 |
67 |
68 | A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with |
69 |
70 |
71 |
72 |
73 | A list of assembly names to include from the default action of "embed all Copy Local references", delimited with |.
74 |
75 |
76 |
77 |
78 | A list of unmanaged 32 bit assembly names to include, delimited with |.
79 |
80 |
81 |
82 |
83 | A list of unmanaged 64 bit assembly names to include, delimited with |.
84 |
85 |
86 |
87 |
88 | The order of preloaded assemblies, delimited with |.
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 | 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.
97 |
98 |
99 |
100 |
101 | A comma-separated list of error codes that can be safely ignored in assembly verification.
102 |
103 |
104 |
105 |
106 | 'false' to turn off automatic generation of the XML Schema file.
107 |
108 |
109 |
110 |
111 |
--------------------------------------------------------------------------------
/OnedriveShareLinkParser/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | 下载路径:
38 |
39 |
40 | 数量限制:
41 | 0
42 |
43 |
44 |
45 |
46 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/OnedriveShareLinkParser/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using Newtonsoft.Json.Linq;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Net;
7 | using System.Text;
8 | using System.Text.RegularExpressions;
9 | using System.Threading.Tasks;
10 | using System.Windows;
11 | using System.Windows.Controls;
12 | using System.Windows.Data;
13 | using System.Windows.Documents;
14 | using System.Windows.Forms;
15 | using System.Windows.Input;
16 | using System.Windows.Media;
17 | using System.Windows.Media.Imaging;
18 | using System.Windows.Navigation;
19 | using System.Windows.Shapes;
20 | using static OnedriveShareLinkParser.Util;
21 | using MessageBox = System.Windows.MessageBox;
22 |
23 | namespace OnedriveShareLinkParser
24 | {
25 | ///
26 | /// MainWindow.xaml 的交互逻辑
27 | ///
28 | public partial class MainWindow : Window
29 | {
30 | static string DemoLink = "https://gitaccuacnz2-my.sharepoint.com/:f:/g/personal/mail_finderacg_com/EheQwACFhe9JuGUn4hlg9esBsKyk5jp9-Iz69kqzLLF5Xw?e=FG7SHh";
31 | static int Limit = 0;
32 |
33 | CookieContainer cookieContainer = new CookieContainer();
34 | List onedriveItems = new List();
35 |
36 |
37 | public MainWindow()
38 | {
39 | InitializeComponent();
40 | Txt_Link.Text = DemoLink;
41 | Data_Output.ItemsSource = onedriveItems;
42 | Txt_SavePath.Text = Environment.CurrentDirectory;
43 | }
44 |
45 | private async void Btn_Parse_Click(object sender, RoutedEventArgs e)
46 | {
47 | Btn_Parse.IsEnabled = false;
48 | try
49 | {
50 | Limit = Convert.ToInt32(Txt_Limit.Text);
51 | onedriveItems.Clear();
52 | Data_Output.ItemsSource = onedriveItems;
53 | cookieContainer = new CookieContainer();
54 | var url = Txt_Link.Text;
55 | onedriveItems = await GetFilsAsync(url);
56 | if (Limit > 0 && onedriveItems.Count > Limit)
57 | {
58 | onedriveItems = onedriveItems.Take(Limit).ToList();
59 | }
60 | foreach (var item in onedriveItems)
61 | {
62 | Console.WriteLine(item);
63 | }
64 | Console.WriteLine(onedriveItems.Count);
65 | Txt_Cookie.Text = GetCookieString(url, cookieContainer);
66 | }
67 | catch (Exception ex)
68 | {
69 | MessageBox.Show(ex.Message);
70 | Btn_Parse.IsEnabled = true;
71 | }
72 | Data_Output.ItemsSource = onedriveItems;
73 | Btn_Parse.IsEnabled = true;
74 | }
75 |
76 | private string GetCookieString(string url, CookieContainer cookieContainer)
77 | {
78 | var uri = ParseUri(url);
79 | var cookies = new List();
80 | foreach (var cookie in cookieContainer.GetCookies(new Uri($"{uri.Scheme}://{uri.Host}")))
81 | {
82 | cookies.Add(cookie.ToString());
83 | }
84 | return string.Join(";", cookies);
85 | }
86 |
87 | async Task> GetFilsAsync(string url)
88 | {
89 | var list = new List();
90 | var jsonArray = new JArray();
91 | bool isSharepoint = false;
92 | if (!url.Contains("-my"))
93 | isSharepoint = true;
94 | var resp = await DoGetAsync(url, cookieContainer);
95 | if (resp.StatusCode == HttpStatusCode.Found || resp.StatusCode == HttpStatusCode.Moved)
96 | {
97 | url = resp.Headers.Location.AbsoluteUri;
98 | resp = await DoGetAsync(url, cookieContainer);
99 | }
100 | var respTxt = await resp.Content.ReadAsStringAsync();
101 | if (!respTxt.Contains(",\"FirstRow\""))
102 | throw new Exception("这个文件夹没有文件");
103 | var rootFolder = System.Web.HttpUtility.UrlDecode(GetQueryString("id", url));
104 | var redirectSplitURL = url.Split('/');
105 | var relativeFolder = "";
106 | var downloadPrefix = string.Join("/", redirectSplitURL.Take(redirectSplitURL.Length - 1)) + "/download.aspx?UniqueId=";
107 | if (isSharepoint)
108 | {
109 | var pat = Regex.Match(respTxt, "templateUrl\":\"(.*?)\"").Groups[1].Value;
110 | Console.WriteLine(pat);
111 | Console.ReadLine();
112 | var uri = ParseUri(url);
113 | var arr = $"{uri.Scheme}://{uri.Host}{uri.AbsolutePath}".Split('/');
114 | downloadPrefix = string.Join("/", arr.Take(arr.Length - 1)) + "/download.aspx?UniqueId=";
115 | }
116 | //获取相对路径
117 | foreach (var i in rootFolder.Split('/'))
118 | {
119 | if (isSharepoint)
120 | {
121 | if (i != "Shared Documents")
122 | {
123 | relativeFolder += i + "/";
124 | }
125 | else
126 | {
127 | relativeFolder += i;
128 | break;
129 | }
130 | }
131 | else
132 | {
133 | if (i != "Documents")
134 | {
135 | relativeFolder += i + "/";
136 | }
137 | else
138 | {
139 | relativeFolder += i;
140 | break;
141 | }
142 | }
143 | }
144 | var relativeUrl = System.Web.HttpUtility.UrlEncode(relativeFolder).Replace("_", "%5f").Replace("-", "%2d").ToUpper();
145 | var rootFolderUrl = System.Web.HttpUtility.UrlEncode(rootFolder).Replace("_", "%5f").Replace("-", "%2d").ToUpper();
146 | var graphql = "{\"query\":\"query (\n" +
147 | " $listServerRelativeUrl: String!,$renderListDataAsStreamParameters: RenderListDataAsStreamParameters!,$renderListDataAsStreamQueryString: String!\n" +
148 | " )\n" +
149 | " {\n" +
150 | " \n" +
151 | " legacy {\n" +
152 | " \n" +
153 | " renderListDataAsStream(\n" +
154 | " listServerRelativeUrl: $listServerRelativeUrl,\n" +
155 | " parameters: $renderListDataAsStreamParameters,\n" +
156 | " queryString: $renderListDataAsStreamQueryString\n" +
157 | " )\n" +
158 | " }\n" +
159 | " \n" +
160 | " \n" +
161 | " perf {\n" +
162 | " executionTime\n" +
163 | " overheadTime\n" +
164 | " parsingTime\n" +
165 | " queryCount\n" +
166 | " validationTime\n" +
167 | " resolvers {\n" +
168 | " name\n" +
169 | " queryCount\n" +
170 | " resolveTime\n" +
171 | " waitTime\n" +
172 | " }\n" +
173 | " }\n" +
174 | " }\",\"variables\":{\"listServerRelativeUrl\":\"" + relativeFolder + "\",\"renderListDataAsStreamParameters\":{\"renderOptions\":5707527,\"allowMultipleValueFilterForTaxonomyFields\":true,\"addRequiredFields\":true,\"folderServerRelativeUrl\":\"" + rootFolder + "\"},\"renderListDataAsStreamQueryString\":\"@a1=\'" + relativeUrl + "\'&RootFolder=" + rootFolderUrl + "&TryNewExperienceSingle=TRUE\"}}";
175 |
176 | var headers = new Dictionary()
177 | {
178 | ["referer"] = url,
179 | ["authority"] = ParseUri(url).Host,
180 | };
181 |
182 | var apiUrl = string.Join("/", redirectSplitURL.Take(redirectSplitURL.Length - 3)) + "/_api/v2.1/graphql";
183 | var graphqlRespTxt = await DoPostForStringAsync(apiUrl, cookieContainer, graphql, headers);
184 | var json = JObject.Parse(graphqlRespTxt);
185 | foreach (var item in json["data"]["legacy"]["renderListDataAsStream"]["ListData"]["Row"].Value())
186 | {
187 | jsonArray.Add(item);
188 | }
189 | //处理多页逻辑
190 | if (json["data"]["legacy"]["renderListDataAsStream"]["ListData"].Value().ContainsKey("NextHref"))
191 | {
192 | var nextHref = json["data"]["legacy"]["renderListDataAsStream"]["ListData"]["NextHref"].ToString()
193 | + $"&@a1=%27{relativeUrl}%27&TryNewExperienceSingle=TRUE";
194 | var listViewXml = json["data"]["legacy"]["renderListDataAsStream"]["ViewMetadata"]["ListViewXml"].ToString();
195 | var renderListDataAsStreamPara = "{\"parameters\":{\"__metadata\":{\"type\":\"SP.RenderListDataParameters\"},\"RenderOptions\":1216519,\"ViewXml\":\"" + listViewXml.Replace("\"", "\\\"") + "\",\"AllowMultipleValueFilterForTaxonomyFields\":true,\"AddRequiredFields\":true}}";
196 | apiUrl = string.Join("/", redirectSplitURL.Take(redirectSplitURL.Length - 3)) + "/_api/web/GetListUsingPath(DecodedUrl=@a1)/RenderListDataAsStream" + nextHref;
197 | graphqlRespTxt = await DoPostForStringAsync(apiUrl, cookieContainer, renderListDataAsStreamPara, headers);
198 | json = JObject.Parse(graphqlRespTxt);
199 | while (json["ListData"].Value().ContainsKey("NextHref"))
200 | {
201 | nextHref = json["ListData"]["NextHref"].ToString()
202 | + $"&@a1=%27{relativeUrl}%27&TryNewExperienceSingle=TRUE";
203 | foreach (var item in json["ListData"]["Row"].Value())
204 | {
205 | jsonArray.Add(item);
206 | }
207 | apiUrl = string.Join("/", redirectSplitURL.Take(redirectSplitURL.Length - 3)) + "/_api/web/GetListUsingPath(DecodedUrl=@a1)/RenderListDataAsStream" + nextHref;
208 | graphqlRespTxt = await DoPostForStringAsync(apiUrl, cookieContainer, renderListDataAsStreamPara, headers);
209 | json = JObject.Parse(graphqlRespTxt);
210 | }
211 | foreach (var item in json["ListData"]["Row"].Value())
212 | {
213 | jsonArray.Add(item);
214 | }
215 | }
216 |
217 | foreach (var item in jsonArray)
218 | {
219 | if (Limit > 0 && list.Count > Limit)
220 | {
221 | return list;
222 | }
223 | //进入文件夹
224 | if (item["FSObjType"].ToString() == "1")
225 | {
226 | var name = item["FileLeafRef"].ToString();
227 | var path = item["FileRef"].ToString();
228 | var id = item["UniqueId"].ToString();
229 | Console.WriteLine($"文件夹:{name}, ID:{id}");
230 | url = url.Replace(GetQueryString("id", url), System.Web.HttpUtility.UrlEncode(path).Replace("_", "%5f").Replace("-", "%2d"));
231 | list.AddRange(await GetFilsAsync(url));
232 | }
233 | else
234 | {
235 | var name = item["FileLeafRef"].ToString();
236 | var id = item["UniqueId"].ToString();
237 | var time = DateTime.Parse(item["Modified."].ToString());
238 | var size = Convert.ToInt64(item["SMTotalSize"].ToString());
239 | var path = item["FileRef"].ToString();
240 | var odItem = new ODItem()
241 | {
242 | Name = name,
243 | Id = id,
244 | Size = FormatFileSize(size),
245 | ModifiedTime = time.ToString("yyyy-MM-dd HH:mm:ss"),
246 | Path = System.IO.Path.GetDirectoryName(path.Substring(path.IndexOf("Documents/") + 10)),
247 | DownloadLink = downloadPrefix + id.TrimStart('{').TrimEnd('}')
248 | };
249 | if (!list.Contains(odItem))
250 | {
251 | list.Add(odItem);
252 | }
253 | }
254 | }
255 | return list;
256 | }
257 |
258 | private void Btn_SelectSavePath_Click(object sender, RoutedEventArgs e)
259 | {
260 | FolderBrowserDialog openFileDialog = new FolderBrowserDialog(); //选择文件夹
261 | openFileDialog.Description = "选择保存路径";
262 | if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
263 | {
264 | Txt_SavePath.Text = openFileDialog.SelectedPath;
265 | }
266 | }
267 |
268 | private void MenuItem_Click(object sender, RoutedEventArgs e)
269 | {
270 | var selected = Data_Output.SelectedItems;
271 | try
272 | {
273 | if (selected != null && selected.Count > 0)
274 | {
275 | MessageBoxResult confirm = MessageBox.Show($"确认要推送这[{selected.Count}]项吗?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
276 | if (confirm == MessageBoxResult.Yes)
277 | {
278 | foreach (var i in selected)
279 | {
280 | var item = (ODItem)i;
281 | PushToIDM(item.DownloadLink, item.Name, System.IO.Path.Combine(Txt_SavePath.Text, item.Path), Txt_Cookie.Text);
282 | }
283 | MessageBox.Show("完成!");
284 | }
285 | }
286 | }
287 | catch (Exception ex)
288 | {
289 | MessageBox.Show(ex.Message);
290 | }
291 | }
292 |
293 | private void MenuItem_Click_1(object sender, RoutedEventArgs e)
294 | {
295 | try
296 | {
297 | if (onedriveItems.Count > 0)
298 | {
299 | MessageBoxResult confirm = MessageBox.Show($"确认要推送这[{onedriveItems.Count}]项吗?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
300 | if (confirm == MessageBoxResult.Yes)
301 | {
302 | foreach (var item in onedriveItems)
303 | {
304 | PushToIDM(item.DownloadLink, item.Name, System.IO.Path.Combine(Txt_SavePath.Text, item.Path), Txt_Cookie.Text);
305 | }
306 | MessageBox.Show("完成!");
307 | }
308 | }
309 | }
310 | catch (Exception ex)
311 | {
312 | MessageBox.Show(ex.Message);
313 | }
314 | }
315 |
316 | private async void Btn_RenewCookie_Click(object sender, RoutedEventArgs e)
317 | {
318 | Btn_RenewCookie.IsEnabled = false;
319 | try
320 | {
321 | cookieContainer = new CookieContainer();
322 | await DoGetAsync(Txt_Link.Text, cookieContainer);
323 | Txt_Cookie.Text = GetCookieString(Txt_Link.Text, cookieContainer);
324 | }
325 | catch (Exception ex)
326 | {
327 | MessageBox.Show(ex.ToString());
328 | Btn_RenewCookie.IsEnabled = true;
329 | }
330 | Btn_RenewCookie.IsEnabled = true;
331 | }
332 | }
333 | }
334 |
--------------------------------------------------------------------------------
/OnedriveShareLinkParser/ODItem.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace OnedriveShareLinkParser
8 | {
9 | class ODItem
10 | {
11 | public string Name { get; set; }
12 | public string Id { get; set; }
13 | public string Size { get; set; }
14 | public string ModifiedTime { get; set; }
15 | public string Path { get; set; }
16 | public string DownloadLink { get; set; }
17 |
18 | public override bool Equals(object obj)
19 | {
20 | return obj is ODItem item &&
21 | Id == item.Id;
22 | }
23 |
24 | public override int GetHashCode()
25 | {
26 | return 2108858624 + EqualityComparer.Default.GetHashCode(Id);
27 | }
28 |
29 | public override string ToString()
30 | {
31 | return $"[Name: {Name}, ModifiedTime: {ModifiedTime}, Path: {Path}, DownloadLink: {DownloadLink}]";
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/OnedriveShareLinkParser/OnedriveShareLinkParser.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Debug
7 | AnyCPU
8 | {047CC374-B76F-4B6E-A9C4-87E16B1A693B}
9 | WinExe
10 | OnedriveShareLinkParser
11 | OnedriveShareLinkParser
12 | v4.7.2
13 | 512
14 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
15 | 4
16 | true
17 | true
18 |
19 |
20 |
21 |
22 | AnyCPU
23 | true
24 | full
25 | false
26 | bin\Debug\
27 | DEBUG;TRACE
28 | prompt
29 | 4
30 |
31 |
32 | AnyCPU
33 | pdbonly
34 | true
35 | bin\Release\
36 | TRACE
37 | prompt
38 | 4
39 |
40 |
41 |
42 |
43 |
44 |
45 | ..\packages\Costura.Fody.4.1.0\lib\net40\Costura.dll
46 |
47 |
48 | ..\IDManTypeInfo.dll
49 | False
50 |
51 |
52 | ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 | 4.0
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 | MSBuild:Compile
74 | Designer
75 |
76 |
77 |
78 |
79 |
80 | MSBuild:Compile
81 | Designer
82 |
83 |
84 | App.xaml
85 | Code
86 |
87 |
88 | MainWindow.xaml
89 | Code
90 |
91 |
92 |
93 |
94 | Code
95 |
96 |
97 | True
98 | True
99 | Resources.resx
100 |
101 |
102 | True
103 | Settings.settings
104 | True
105 |
106 |
107 | ResXFileCodeGenerator
108 | Resources.Designer.cs
109 |
110 |
111 |
112 | SettingsSingleFileGenerator
113 | Settings.Designer.cs
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 | 这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。
124 |
125 |
126 |
127 |
128 |
--------------------------------------------------------------------------------
/OnedriveShareLinkParser/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 |
7 | // 有关程序集的一般信息由以下
8 | // 控制。更改这些特性值可修改
9 | // 与程序集关联的信息。
10 | [assembly: AssemblyTitle("WpfApp1")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("")]
14 | [assembly: AssemblyProduct("WpfApp1")]
15 | [assembly: AssemblyCopyright("Copyright © 2022")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // 将 ComVisible 设置为 false 会使此程序集中的类型
20 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
21 | //请将此类型的 ComVisible 特性设置为 true。
22 | [assembly: ComVisible(false)]
23 |
24 | //若要开始生成可本地化的应用程序,请设置
25 | //.csproj 文件中的 CultureYouAreCodingWith
26 | //例如,如果您在源文件中使用的是美国英语,
27 | //使用的是美国英语,请将 设置为 en-US。 然后取消
28 | //对以下 NeutralResourceLanguage 特性的注释。 更新
29 | //以下行中的“en-US”以匹配项目文件中的 UICulture 设置。
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly: ThemeInfo(
35 | ResourceDictionaryLocation.None, //主题特定资源词典所处位置
36 | //(未在页面中找到资源时使用,
37 | //或应用程序资源字典中找到时使用)
38 | ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置
39 | //(未在页面中找到资源时使用,
40 | //、应用程序或任何主题专用资源字典中找到时使用)
41 | )]
42 |
43 |
44 | // 程序集的版本信息由下列四个值组成:
45 | //
46 | // 主版本
47 | // 次版本
48 | // 生成号
49 | // 修订号
50 | //
51 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
52 | //通过使用 "*",如下所示:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.0.0.0")]
55 | [assembly: AssemblyFileVersion("1.0.0.0")]
56 |
--------------------------------------------------------------------------------
/OnedriveShareLinkParser/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本:4.0.30319.42000
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将会丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace OnedriveShareLinkParser.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// 一个强类型的资源类,用于查找本地化的字符串等。
17 | ///
18 | // 此类是由 StronglyTypedResourceBuilder
19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
21 | // (以 /str 作为命令选项),或重新生成 VS 项目。
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// 返回此类使用的缓存的 ResourceManager 实例。
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("OnedriveShareLinkParser.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// 重写当前线程的 CurrentUICulture 属性,对
51 | /// 使用此强类型资源类的所有资源查找执行重写。
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/OnedriveShareLinkParser/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/OnedriveShareLinkParser/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本:4.0.30319.42000
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将会丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace OnedriveShareLinkParser.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/OnedriveShareLinkParser/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/OnedriveShareLinkParser/Util.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Net;
6 | using System.Net.Http;
7 | using System.Net.Http.Headers;
8 | using System.Text;
9 | using System.Text.RegularExpressions;
10 | using System.Threading.Tasks;
11 |
12 | namespace OnedriveShareLinkParser
13 | {
14 | class Util
15 | {
16 |
17 | public static async Task DoGetAsync(string url, CookieContainer cookieContainer, Dictionary headers = null)
18 | {
19 | HttpResponseMessage resp = null;
20 | try
21 | {
22 | using (HttpClient AppHttpClient = new HttpClient(new HttpClientHandler
23 | {
24 | AllowAutoRedirect = false,
25 | AutomaticDecompression = DecompressionMethods.GZip,
26 | CookieContainer = cookieContainer
27 | })
28 | {
29 | Timeout = TimeSpan.FromMinutes(5)
30 | })
31 | {
32 | using (var webRequest = new HttpRequestMessage(HttpMethod.Get, url))
33 | {
34 | webRequest.Headers.Add("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Safari/605.1.15");
35 | webRequest.Headers.Add("Accept-Encoding", "gzip, deflate");
36 | webRequest.Headers.CacheControl = CacheControlHeaderValue.Parse("no-cache");
37 | webRequest.Headers.Connection.Clear();
38 | if (headers != null)
39 | {
40 | foreach (var h in headers)
41 | {
42 | webRequest.Headers.TryAddWithoutValidation(h.Key, h.Value);
43 | }
44 | }
45 | resp = await AppHttpClient.SendAsync(webRequest, HttpCompletionOption.ResponseHeadersRead);
46 | //htmlCode = await webResponse.Content.ReadAsStringAsync();
47 | }
48 | }
49 | }
50 | catch (Exception)
51 | {
52 | ;
53 | }
54 | return resp;
55 | }
56 |
57 | public static async Task DoPostForStringAsync(string Url, CookieContainer cookieContainer, string postData, Dictionary headers = null)
58 | {
59 | Console.WriteLine(Url);
60 | string htmlCode = string.Empty;
61 | using (HttpClient AppHttpClient = new HttpClient(new HttpClientHandler
62 | {
63 | AllowAutoRedirect = false,
64 | AutomaticDecompression = DecompressionMethods.GZip,
65 | CookieContainer = cookieContainer
66 | })
67 | {
68 | Timeout = TimeSpan.FromMinutes(5)
69 | })
70 | {
71 | using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, Url))
72 | {
73 | request.Headers.TryAddWithoutValidation("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Safari/605.1.15");
74 | if (headers != null)
75 | {
76 | foreach (var h in headers)
77 | {
78 | request.Headers.TryAddWithoutValidation(h.Key, h.Value);
79 | }
80 | }
81 | request.Content = new ByteArrayContent(Encoding.UTF8.GetBytes(postData));
82 | //Add entity header
83 | request.Content.Headers.TryAddWithoutValidation("Content-Type", "application/json;odata=verbose");
84 | var webResponse = await AppHttpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
85 | Stream myRequestStream = await webResponse.Content.ReadAsStreamAsync();
86 | htmlCode = await webResponse.Content.ReadAsStringAsync();
87 | }
88 | }
89 | return htmlCode;
90 | }
91 |
92 | public static Uri ParseUri(string url)
93 | {
94 | if (Uri.TryCreate(url, UriKind.Absolute, out Uri uri))
95 | {
96 | return uri;
97 | }
98 | return null;
99 | }
100 |
101 | public static string FormatFileSize(double fileSize)
102 | {
103 | if (fileSize < 0)
104 | {
105 | throw new ArgumentOutOfRangeException("fileSize");
106 | }
107 | else if (fileSize >= 1024 * 1024 * 1024)
108 | {
109 | return string.Format("{0:########0.00} GB", ((double)fileSize) / (1024 * 1024 * 1024));
110 | }
111 | else if (fileSize >= 1024 * 1024)
112 | {
113 | return string.Format("{0:####0.00} MB", ((double)fileSize) / (1024 * 1024));
114 | }
115 | else if (fileSize >= 1024)
116 | {
117 | return string.Format("{0:####0.00} KB", ((double)fileSize) / 1024);
118 | }
119 | else
120 | {
121 | return string.Format("{0} bytes", fileSize);
122 | }
123 | }
124 |
125 | ///
126 | /// 获取url字符串参数,返回参数值字符串
127 | ///
128 | /// 参数名称
129 | /// url字符串
130 | ///
131 | public static string GetQueryString(string name, string url)
132 | {
133 | Regex re = new Regex(@"(^|&)?(\w+)=([^&]+)(&|$)?", System.Text.RegularExpressions.RegexOptions.Compiled);
134 | MatchCollection mc = re.Matches(url);
135 | foreach (Match m in mc)
136 | {
137 | if (m.Result("$2").Equals(name))
138 | {
139 | return m.Result("$3");
140 | }
141 | }
142 | return "";
143 | }
144 |
145 | public static void PushToIDM(string url, string name, string path, string cookie)
146 | {
147 | try
148 | {
149 | new IDManTypeInfo.CIDMLinkTransmitterClass().SendLinkToIDM2(
150 | url, //URL
151 | "", //Referer
152 | cookie, //Cookies
153 | "", //Data
154 | "", //Username
155 | "", //Userpassword
156 | path, //LocalPath
157 | name, //LocalFileName
158 | 2, //Flag
159 | "",
160 | null
161 | );
162 | }
163 | catch (Exception)
164 | {
165 | throw new Exception("IDM调用失败,请检查是否安装的IDM!");
166 | }
167 | }
168 | }
169 | }
170 |
--------------------------------------------------------------------------------
/OnedriveShareLinkParser/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # OneDriveShareLinkParser
2 | 从OneDrive分享链接获取并推送下载地址到IDM以进行批量下载. Push To IDM.
3 |
4 | ---
5 |
6 | [gaowanliang/OneDriveShareLinkPushAria2](https://github.com/gaowanliang/OneDriveShareLinkPushAria2) 的GUI+IDM实现
7 |
8 | 
9 |
--------------------------------------------------------------------------------