├── m2strm
├── Program.ico
├── Properties
│ └── AssemblyInfo.cs
├── m2strm.csproj
└── Program.cs
├── m2strm.sln
├── _example.m3u8
├── .gitignore
├── README.md
└── LICENSE
/m2strm/Program.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trix7777/m2strm/HEAD/m2strm/Program.ico
--------------------------------------------------------------------------------
/m2strm.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.30621.155
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "m2strm", "m2strm\m2strm.csproj", "{429D1E4D-31B3-4C8B-8F5B-BA984AF784B4}"
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 | {429D1E4D-31B3-4C8B-8F5B-BA984AF784B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {429D1E4D-31B3-4C8B-8F5B-BA984AF784B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {429D1E4D-31B3-4C8B-8F5B-BA984AF784B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {429D1E4D-31B3-4C8B-8F5B-BA984AF784B4}.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 = {84DC9006-DE8A-4CBE-9639-9865EA45D119}
24 | EndGlobalSection
25 | EndGlobal
26 |
--------------------------------------------------------------------------------
/m2strm/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Resources;
2 | using System.Reflection;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 |
6 | // General Information about an assembly is controlled through the following
7 | // set of attributes. Change these attribute values to modify the information
8 | // associated with an assembly.
9 | [assembly: AssemblyTitle("m2strm")]
10 | [assembly: AssemblyDescription("Creates STRM-files from M3U8-file.")]
11 | [assembly: AssemblyConfiguration("")]
12 | [assembly: AssemblyCompany("trix77")]
13 | [assembly: AssemblyProduct("m2strm")]
14 | [assembly: AssemblyCopyright("© 2020-2023 trix77. All rights reserved.")]
15 | [assembly: AssemblyTrademark("")]
16 | [assembly: AssemblyCulture("")]
17 |
18 | // Setting ComVisible to false makes the types in this assembly not visible
19 | // to COM components. If you need to access a type in this assembly from
20 | // COM, set the ComVisible attribute to true on that type.
21 | [assembly: ComVisible(false)]
22 |
23 | // The following GUID is for the ID of the typelib if this project is exposed to COM
24 | [assembly: Guid("66249fdb-ad4d-4d41-856b-7a82cb1106e2")]
25 |
26 | // Version information for an assembly consists of the following four values:
27 | //
28 | // Major Version
29 | // Minor Version
30 | // Build Number
31 | // Revision
32 | //
33 | // You can specify all the values or you can default the Build and Revision Numbers
34 | // by using the '*' as shown below:
35 | // [assembly: AssemblyVersion("1.0.*")]
36 | [assembly: AssemblyVersion("3.0.2.6")]
37 | [assembly: AssemblyFileVersion("3.0.2.6")]
38 |
--------------------------------------------------------------------------------
/_example.m3u8:
--------------------------------------------------------------------------------
1 | #EXTM3U
2 | #EXTINF:-1 tvg-ID="" tvg-name="-= Sweden =-" tvg-logo="http://ip.tv/sdr35.png" group-title="Sweden",-= Sweden =-
3 | http://ip.tv:8080/ABCDEFGHIJ/0123456789/2467
4 | #EXTINF:-1 tvg-ID="svt1.se" tvg-name="SVT1 FHD SE" tvg-logo="http://ip.tv/23rsdfds.png" group-title="Sweden",SVT1 FHD SE
5 | http://ip.tv:8080/ABCDEFGHIJ/0123456789/38472
6 | #EXTINF:-1 tvg-ID="" tvg-name="-= Music =-" tvg-logo="http://ip.tv/ljhl234.png" group-title="*-* Music Package *-*",-= Music =-
7 | http://ip.tv:8080/ABCDEFGHIJ/0123456789/9384
8 | #EXTINF:-1 tvg-ID="" tvg-name="Music Choice - Alternative HD" tvg-logo="" group-title="*-* Music Package *-*",Music Choice - Alternative HD
9 | http://ip.tv:8080/ABCDEFGHIJ/0123456789/84758
10 | #EXTINF:-1 tvg-ID="" tvg-name="Alien 2: Aliens [1986]" tvg-logo="http://ip.tv/werewf3234.jpg" group-title="VOD: Alien",Alien 2: Aliens [1986]
11 | http://ip.tv:8080/movie/ABCDEFGHIJ/0123456789/18294.mkv
12 | #EXTINF:-1 tvg-ID="" tvg-name="Alien [1979]" tvg-logo="http://ip.tv/4345sdfsdf.jpg" group-title="VOD: Alien",Alien [1979]
13 | http://ip.tv:8080/movie/ABCDEFGHIJ/0123456789/19453.mkv
14 | #EXTINF:-1 tvg-ID="" tvg-name="The Epic Tales of Captain Underpants S01 The Epic Tales Of Captain Underpants S01E01" tvg-logo="http://ip.tv/xcvwerwe4.jpg" group-title="Series: Barn",The Epic Tales of Captain Underpants S01 The Epic Tales Of Captain Underpants S01E01
15 | http://ip.tv:8080/series/ABCDEFGHIJ/0123456789/98374.mkv
16 | #EXTINF:-1 tvg-ID="" tvg-name="The Epic Tales of Captain Underpants S01 The Epic Tales Of Captain Underpants S01E02" tvg-logo="http://ip.tv/234asfdfs.jpg" group-title="Series: Barn",The Epic Tales of Captain Underpants S01 The Epic Tales Of Captain Underpants S01E02
17 | http://ip.tv:8080/series/ABCDEFGHIJ/0123456789/47583.mkv
18 |
--------------------------------------------------------------------------------
/m2strm/m2strm.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | {429D1E4D-31B3-4C8B-8F5B-BA984AF784B4}
7 | Exe
8 |
9 |
10 | m2strm
11 | m2strm
12 | 512
13 | Console
14 | v4.7.2
15 | false
16 | true
17 | false
18 |
19 |
20 | publish\
21 | true
22 | Disk
23 | false
24 | Foreground
25 | 7
26 | Days
27 | false
28 | false
29 | true
30 | 0
31 | 1.0.0.%2a
32 | false
33 | true
34 |
35 |
36 | AnyCPU
37 | true
38 | full
39 | true
40 | true
41 | bin\Debug\
42 |
43 |
44 | 660,661
45 | Off
46 | false
47 |
48 |
49 | AnyCPU
50 | pdbonly
51 | false
52 | true
53 | true
54 | bin\Release\
55 | m2strm.xml
56 | 660,661
57 | false
58 |
59 |
60 | On
61 |
62 |
63 | Binary
64 |
65 |
66 | Off
67 |
68 |
69 | On
70 |
71 |
72 | Program.ico
73 |
74 |
75 |
76 | OnBuildSuccess
77 |
78 |
79 | true
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 | False
102 | Microsoft .NET Framework 4.7.2 %28x86 and x64%29
103 | true
104 |
105 |
106 | False
107 | .NET Framework 3.5 SP1
108 | false
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Ww][Ii][Nn]32/
27 | [Aa][Rr][Mm]/
28 | [Aa][Rr][Mm]64/
29 | bld/
30 | [Bb]in/
31 | [Oo]bj/
32 | [Ll]og/
33 | [Ll]ogs/
34 |
35 | # Visual Studio 2015/2017 cache/options directory
36 | .vs/
37 | # Uncomment if you have tasks that create the project's static files in wwwroot
38 | #wwwroot/
39 |
40 | # Visual Studio 2017 auto generated files
41 | Generated\ Files/
42 |
43 | # MSTest test Results
44 | [Tt]est[Rr]esult*/
45 | [Bb]uild[Ll]og.*
46 |
47 | # NUnit
48 | *.VisualState.xml
49 | TestResult.xml
50 | nunit-*.xml
51 |
52 | # Build Results of an ATL Project
53 | [Dd]ebugPS/
54 | [Rr]eleasePS/
55 | dlldata.c
56 |
57 | # Benchmark Results
58 | BenchmarkDotNet.Artifacts/
59 |
60 | # .NET Core
61 | project.lock.json
62 | project.fragment.lock.json
63 | artifacts/
64 |
65 | # ASP.NET Scaffolding
66 | ScaffoldingReadMe.txt
67 |
68 | # StyleCop
69 | StyleCopReport.xml
70 |
71 | # Files built by Visual Studio
72 | *_i.c
73 | *_p.c
74 | *_h.h
75 | *.ilk
76 | *.meta
77 | *.obj
78 | *.iobj
79 | *.pch
80 | *.pdb
81 | *.ipdb
82 | *.pgc
83 | *.pgd
84 | *.rsp
85 | *.sbr
86 | *.tlb
87 | *.tli
88 | *.tlh
89 | *.tmp
90 | *.tmp_proj
91 | *_wpftmp.csproj
92 | *.log
93 | *.tlog
94 | *.vspscc
95 | *.vssscc
96 | .builds
97 | *.pidb
98 | *.svclog
99 | *.scc
100 |
101 | # Chutzpah Test files
102 | _Chutzpah*
103 |
104 | # Visual C++ cache files
105 | ipch/
106 | *.aps
107 | *.ncb
108 | *.opendb
109 | *.opensdf
110 | *.sdf
111 | *.cachefile
112 | *.VC.db
113 | *.VC.VC.opendb
114 |
115 | # Visual Studio profiler
116 | *.psess
117 | *.vsp
118 | *.vspx
119 | *.sap
120 |
121 | # Visual Studio Trace Files
122 | *.e2e
123 |
124 | # TFS 2012 Local Workspace
125 | $tf/
126 |
127 | # Guidance Automation Toolkit
128 | *.gpState
129 |
130 | # ReSharper is a .NET coding add-in
131 | _ReSharper*/
132 | *.[Rr]e[Ss]harper
133 | *.DotSettings.user
134 |
135 | # TeamCity is a build add-in
136 | _TeamCity*
137 |
138 | # DotCover is a Code Coverage Tool
139 | *.dotCover
140 |
141 | # AxoCover is a Code Coverage Tool
142 | .axoCover/*
143 | !.axoCover/settings.json
144 |
145 | # Coverlet is a free, cross platform Code Coverage Tool
146 | coverage*.json
147 | coverage*.xml
148 | coverage*.info
149 |
150 | # Visual Studio code coverage results
151 | *.coverage
152 | *.coveragexml
153 |
154 | # NCrunch
155 | _NCrunch_*
156 | .*crunch*.local.xml
157 | nCrunchTemp_*
158 |
159 | # MightyMoose
160 | *.mm.*
161 | AutoTest.Net/
162 |
163 | # Web workbench (sass)
164 | .sass-cache/
165 |
166 | # Installshield output folder
167 | [Ee]xpress/
168 |
169 | # DocProject is a documentation generator add-in
170 | DocProject/buildhelp/
171 | DocProject/Help/*.HxT
172 | DocProject/Help/*.HxC
173 | DocProject/Help/*.hhc
174 | DocProject/Help/*.hhk
175 | DocProject/Help/*.hhp
176 | DocProject/Help/Html2
177 | DocProject/Help/html
178 |
179 | # Click-Once directory
180 | publish/
181 |
182 | # Publish Web Output
183 | *.[Pp]ublish.xml
184 | *.azurePubxml
185 | # Note: Comment the next line if you want to checkin your web deploy settings,
186 | # but database connection strings (with potential passwords) will be unencrypted
187 | *.pubxml
188 | *.publishproj
189 |
190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
191 | # checkin your Azure Web App publish settings, but sensitive information contained
192 | # in these scripts will be unencrypted
193 | PublishScripts/
194 |
195 | # NuGet Packages
196 | *.nupkg
197 | # NuGet Symbol Packages
198 | *.snupkg
199 | # The packages folder can be ignored because of Package Restore
200 | **/[Pp]ackages/*
201 | # except build/, which is used as an MSBuild target.
202 | !**/[Pp]ackages/build/
203 | # Uncomment if necessary however generally it will be regenerated when needed
204 | #!**/[Pp]ackages/repositories.config
205 | # NuGet v3's project.json files produces more ignorable files
206 | *.nuget.props
207 | *.nuget.targets
208 |
209 | # Microsoft Azure Build Output
210 | csx/
211 | *.build.csdef
212 |
213 | # Microsoft Azure Emulator
214 | ecf/
215 | rcf/
216 |
217 | # Windows Store app package directories and files
218 | AppPackages/
219 | BundleArtifacts/
220 | Package.StoreAssociation.xml
221 | _pkginfo.txt
222 | *.appx
223 | *.appxbundle
224 | *.appxupload
225 |
226 | # Visual Studio cache files
227 | # files ending in .cache can be ignored
228 | *.[Cc]ache
229 | # but keep track of directories ending in .cache
230 | !?*.[Cc]ache/
231 |
232 | # Others
233 | ClientBin/
234 | ~$*
235 | *~
236 | *.dbmdl
237 | *.dbproj.schemaview
238 | *.jfm
239 | *.pfx
240 | *.publishsettings
241 | orleans.codegen.cs
242 |
243 | # Including strong name files can present a security risk
244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
245 | #*.snk
246 |
247 | # Since there are multiple workflows, uncomment next line to ignore bower_components
248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
249 | #bower_components/
250 |
251 | # RIA/Silverlight projects
252 | Generated_Code/
253 |
254 | # Backup & report files from converting an old project file
255 | # to a newer Visual Studio version. Backup files are not needed,
256 | # because we have git ;-)
257 | _UpgradeReport_Files/
258 | Backup*/
259 | UpgradeLog*.XML
260 | UpgradeLog*.htm
261 | ServiceFabricBackup/
262 | *.rptproj.bak
263 |
264 | # SQL Server files
265 | *.mdf
266 | *.ldf
267 | *.ndf
268 |
269 | # Business Intelligence projects
270 | *.rdl.data
271 | *.bim.layout
272 | *.bim_*.settings
273 | *.rptproj.rsuser
274 | *- [Bb]ackup.rdl
275 | *- [Bb]ackup ([0-9]).rdl
276 | *- [Bb]ackup ([0-9][0-9]).rdl
277 |
278 | # Microsoft Fakes
279 | FakesAssemblies/
280 |
281 | # GhostDoc plugin setting file
282 | *.GhostDoc.xml
283 |
284 | # Node.js Tools for Visual Studio
285 | .ntvs_analysis.dat
286 | node_modules/
287 |
288 | # Visual Studio 6 build log
289 | *.plg
290 |
291 | # Visual Studio 6 workspace options file
292 | *.opt
293 |
294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
295 | *.vbw
296 |
297 | # Visual Studio 6 auto-generated project file (contains which files were open etc.)
298 | *.vbp
299 |
300 | # Visual Studio 6 workspace and project file (working project files containing files to include in project)
301 | *.dsw
302 | *.dsp
303 |
304 | # Visual Studio 6 technical files
305 | *.ncb
306 | *.aps
307 |
308 | # Visual Studio LightSwitch build output
309 | **/*.HTMLClient/GeneratedArtifacts
310 | **/*.DesktopClient/GeneratedArtifacts
311 | **/*.DesktopClient/ModelManifest.xml
312 | **/*.Server/GeneratedArtifacts
313 | **/*.Server/ModelManifest.xml
314 | _Pvt_Extensions
315 |
316 | # Paket dependency manager
317 | .paket/paket.exe
318 | paket-files/
319 |
320 | # FAKE - F# Make
321 | .fake/
322 |
323 | # CodeRush personal settings
324 | .cr/personal
325 |
326 | # Python Tools for Visual Studio (PTVS)
327 | __pycache__/
328 | *.pyc
329 |
330 | # Cake - Uncomment if you are using it
331 | # tools/**
332 | # !tools/packages.config
333 |
334 | # Tabs Studio
335 | *.tss
336 |
337 | # Telerik's JustMock configuration file
338 | *.jmconfig
339 |
340 | # BizTalk build output
341 | *.btp.cs
342 | *.btm.cs
343 | *.odx.cs
344 | *.xsd.cs
345 |
346 | # OpenCover UI analysis results
347 | OpenCover/
348 |
349 | # Azure Stream Analytics local run output
350 | ASALocalRun/
351 |
352 | # MSBuild Binary and Structured Log
353 | *.binlog
354 |
355 | # NVidia Nsight GPU debugger configuration file
356 | *.nvuser
357 |
358 | # MFractors (Xamarin productivity tool) working folder
359 | .mfractor/
360 |
361 | # Local History for Visual Studio
362 | .localhistory/
363 |
364 | # Visual Studio History (VSHistory) files
365 | .vshistory/
366 |
367 | # BeatPulse healthcheck temp database
368 | healthchecksdb
369 |
370 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
371 | MigrationBackup/
372 |
373 | # Ionide (cross platform F# VS Code tools) working folder
374 | .ionide/
375 |
376 | # Fody - auto-generated XML schema
377 | FodyWeavers.xsd
378 |
379 | # VS Code files for those working on multiple tools
380 | .vscode/*
381 | !.vscode/settings.json
382 | !.vscode/tasks.json
383 | !.vscode/launch.json
384 | !.vscode/extensions.json
385 | *.code-workspace
386 |
387 | # Local History for Visual Studio Code
388 | .history/
389 |
390 | # Windows Installer files from build outputs
391 | *.cab
392 | *.msi
393 | *.msix
394 | *.msm
395 | *.msp
396 |
397 | # JetBrains Rider
398 | *.sln.iml
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## m2strm
2 |
3 | Creates STRM-files from M3U8-file.
4 |
5 | Download latest release [here](https://github.com/trix7777/m2strm/releases)
6 |
7 | #### New in version 3.0:
8 | - *Configuration file*: You can now use a configuration file for all user settings.
9 | - *Unwanted groups file*: this file contains groups you do not want to process.
10 | - Program log enable/disable.
11 | - Download M3U8-file: downloads your m3u8 directly from your IPTV-provider and then processes it in one go.
12 | - Fully Mono compatible = runs on Linux with Mono installed - see [here](https://www.mono-project.com/download/stable/#download-lin)
13 | - Dupe checking: only output the first of dupes found.
14 | - Updates content: if URL for an item changed, the strm-file will be updated accordingly.
15 | - Purging of old strm-files and empty directories.
16 | - New groups log: a file containing new groups since configuration last changed.
17 | - Even more... still working on it. Please don't hesitate to come forward with ideas or feature requests, under [Discussions](https://github.com/trix7777/m2strm/discussions)
18 | - Found a bug? Please report it under [Issues](https://github.com/trix7777/m2strm/issues) with details on how to replicate it.
19 |
20 | #### Tested with IPTV-providers:
21 | - N1
22 |
23 | #### How to use
24 | ```
25 | m2strm.exe /?
26 |
27 | Creates STRM-files from M3U8-file.
28 |
29 | m2strm.exe [OPTIONS] [drive:][path][filename]
30 |
31 | filename The source M3U8-file to be processed.
32 |
33 | /C Create default configuration file. Warning: resets existing settings.
34 | /U [filename] Create the unwanted groups file with a list of all groups from filename.
35 | /D Delete previously created directories and then quit.
36 | /M Download M3U8-file and then quit. Uses config set information.
37 | /G Show a guide to help you get started quickly.
38 | /V Version information.
39 | /? or /H This help.
40 |
41 | Configuration file found: X:\m2strm\m2strm.exe.config
42 | Unwanted groups file found: X:\m2strm\uwgroups.cfg
43 |
44 | Example usage:
45 | m2strm.exe original.m3u8
46 | ```
47 |
48 | #### Configuration file
49 | Create configuration with `m2strm.exe /C` and then edit the configuration for your needs.
50 |
51 | `BaseDirectory`: Where the process is working and where the config files are.
52 | - Default value is: "" (which translates to the directory where m2strm.exe is running from).
53 | - Example values: `"X:\myapp\m2strm\"`, `"/home/trix77/m2strm/"`, `""`
54 | - Mandatory: No (uses default value).
55 |
56 | `OutDirectory`: Where the processed content should be output to.
57 | - Default value is: "" (which translates to the directory where m2strm.exe is running from).
58 | - Example values: `"X:\videos\strm\"`, `"\\server\videos\strm\"`, `"strm"`
59 | - Mandatory: No (uses default value).
60 |
61 | `m3u8File`: Where your M3U8-file is/will be located.
62 | - Default value is: ""
63 | - Example values: `"X:\myotherapp\original.m3u8"`, `"original.m3u8"`, `""`
64 | - Mandatory: No (needs be set if not specified when arg `/U` or when `DownloadM3U8Enabled` is `False`).
65 |
66 | `MoviesSubDir`, `SeriesSubDir`, `TVSubDir`: Sub-directory names for your movies, series and tv content.
67 | - Default values are respectively: `"VOD Movies"`, `"VOD Series"`, `"TV Channels"`.
68 | - Mandatory: No (uses default values).
69 |
70 | `DeletePreviousDirEnabled`
71 | - Default value is: `"False"` -- previously created directories will not be deleted before processing starts.
72 | - Accepted values are: "" (same as default above), `"True"` (Enabled), `"False"` (Disabled).
73 | - Mandatory: No (uses default value).
74 |
75 | `UnwantedCFGEnabled`
76 | - Default value is: `"True"` -- will use the unwanted groups file if found.
77 | - Accepted values are: "" (same as default above), `"True"` (Enabled), `"False"` (Disabled).
78 | - Mandatory: No (uses default value).
79 |
80 | `VerboseConsoleOutputEnabled`
81 | - Default value is: `"False"` -- will not output found items to console.
82 | - Accepted values are: "" (same as default above), `"True"` (Enabled), `"False"` (Disabled).
83 | - Mandatory: No (uses default value).
84 |
85 | `ProgramLogEnabled`
86 | - Default value is: `"True"` -- will create the program log (`m2strm.log`) in a subdirectory `/log` of the program file. Will also create a couple of other logs (see below).
87 | - Accepted values are: "" (same as default above), `"True"` (Enabled), `"False"` (Disabled).
88 | - Mandatory: No (uses default value).
89 | `allgroups.log`: contains all groups found in source just like `m2strm.exe /U` does but outputs to allgroups.log instead, during each parse.
90 | `dupes.log`: contains duplicate items found. Read more about dupes below.
91 | `new.log`: contains new items found.
92 | `purged.log`: contains items that was purged (if `PurgeFilesEnabled` is set to `True`).
93 | `uwgroups.log`: contains the groups not in or commented out in `uwgroups.cfg`.
94 | `newgroups.log`: contains new groups found since the unwanted groups file (see below) was edited.
95 |
96 | `PurgeFilesEnabled`
97 | - Default value is: `"True"` -- will purge (delete) files no longer found in the source. If, after purge, found an empty directory, will also be deleted.
98 | - Accepted values are: "" (same as default above), `"True"` (Enabled), `"False"` (Disabled).
99 | - Mandatory: No (uses default value).
100 |
101 | `MovieGroupSubdirEnabled`
102 | - Default value is: `"False"` -- will not create a movie group subdir if the movie belongs to a group.
103 | - Accepted values are: "" (same as default above), `"True"` (Enabled), `"False"` (Disabled).
104 | - Mandatory: No (uses default value).
105 |
106 | `DownloadM3U8Enabled`
107 | - Default value is: `"False"` -- will not try to download a M3U8-file.
108 | - Accepted values are: "" (same as default above), `"True"` (Enabled), `"False"` (Disabled).
109 | - Mandatory: No (uses default value).
110 |
111 | `UserURL`, `UserPort`, `UserName`, `UserPass`: The information you have gotten from your IPTV-provider.
112 | - Default value for all of them are: "".
113 | - Mandatory: Yes (if `DownloadM3U8Enabled` is `True`).
114 | - Look at the link you've got from your IPTV-provider, something like this:
115 | `http://ip.tv:8080/get.php?username=ABCDEFGHIJ&password=0123456789&type=m3u_plus&output=ts`
116 | You can get all the information you need from it, look carefully, the above ampersands `&` for instance, are not part of either the username nor the password.
117 | `UserURL`: `"http://ip.tv"`
118 | `UserPort`: `"8080"`
119 | `UserName`: `"ABCDEFGHIJ"`
120 | `UserPass`: `"0123456789"`
121 |
122 | #### Unwanted groups file
123 | Create a fully populated unwanted groups file with `m2strm.exe /U` and then edit this file and "comment out" groups you **want** to process.
124 | - Everything **not** commented out will be ignored while processing.
125 | - Comment out a line by putting `//` before the group name.
126 | - To make use of the unwanted groups file, `UnwantedCFGEnabled` must be set to `True` (default).
127 | - The _NOGROUP group is a group for titles not in a group (thanks to IPTV-provider bug).
128 |
129 | Example content, with both wanted (`//`) and not wanted groups:
130 | ```
131 | //_NOGROUP
132 | Sweden
133 | Norway
134 | Denmark
135 | Finland
136 | //Series: English [Multi-Sub]
137 | //VOD: Premiere Cinemas [Multi-Sub]
138 | ```
139 | In this example we tell the program that we want to process the following groups: *_NOGROUP*, *Series: English [Multi-Sub]* and *VOD: Premiere Cinemas [Multi-Sub]*. The rest: *Sweden*, *Norway*, *Denmark* and *Finland* will be ignored.
140 | **It is important that there is no space before or after // on each line and that no groups are removed, or the "new groups" function will not work.**
141 |
142 | #### Using this program with Mono
143 | You need to install Mono to use this program under Linux OS. In Debian that could be:
144 | `$ sudo apt-get install mono-devel mono-vbnc`
145 | Then run the program with:
146 | `$ mono m2strm.exe`
147 |
148 | #### Notes about differences running under a Windows or a Linux environment:
149 | - UNC network paths:
150 | Windows: Network paths like `"\\myserver\somepath"` can be used.
151 | Linux: Use a local or a mounted network location path instead.
152 | - Case sensitivity:
153 | Windows: NTFS does not normally differentiate between upper or lower case letters in filenames, so when this program encounters two titles, the first one named `"This Title"` and the second one named `"This title"`, it will se them both as the same title and only create output from the first one it finds in the source file, the second one will be seen as a duplicate.
154 | Linux: This is resolved by dupe-checking in lowercase (see below under dupes); running on Linux will most likely produce the same output as if running on Windows.
155 | - Illegal printable file characters, names and path length:
156 | This program will try its best to make the output more or less the same no matter which platform it is running from. This might however set unnecessary restrictions to Linux filesystems. One example is the file path + filename length which in some cases in Windows, is no more than 260 characters.
157 |
158 | #### Notes about dupes:
159 | - So what is a dupe according to this program?
160 | All titles found in the source are "filtered" though a special process, some characters are removed, some are replaced. Also all "tags" (everything in the title name that are within brackets, but the year\*, are considered to be a tag) are removed from the title.
161 |
162 | \* New from version 3.0.2.6: 4K-tags are also kept but converted to UHD-tags. Read more about in in [Releases] (https://github.com/trix7777/m2strm/releases)
163 |
164 | This process can in it self, as a side effect, create dupes. An example would be these two titles: `"The Title [PRE] [2020]"` and `"The Title [2020]"`, which both through this filter will become the same `"The Title (2020)"`.
165 | - Version 3.0.0.5 introduces dupe-checking: Comparing lowercase title with an array of already found lowercase titles, if match; discard. This also resolves the problem with different output depending on OS case-sensitivity.
166 | - If there are dupes: Only the first found in the source will be considered, the rest will be discarded.
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/m2strm/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Text.RegularExpressions;
6 | using System.Configuration;
7 | using System.Reflection;
8 | using System.Net;
9 |
10 | namespace m2strm
11 | {
12 | public class Program
13 | {
14 | public static void Main(string[] args)
15 | {
16 | try
17 | {
18 | //set various
19 | string creator = "trix77 ©2023";
20 | string location = Convert.ToString(Environment.GetCommandLineArgs()[0]);
21 | string programFileName = Path.GetFileName(location);
22 | string programName = "m2strm";
23 | string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
24 | string configFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
25 | string configFileOld = $"{configFile}.old";
26 | var userConfigFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
27 | var userSettings = userConfigFile.AppSettings.Settings;
28 |
29 | //default settings, can be overridden in config
30 | string BaseDirectory = AppDomain.CurrentDomain.BaseDirectory;
31 | string OutDirectory = BaseDirectory;
32 | string m3u8File = ""; //can also be overridden in args
33 | string MoviesSubDir = "VOD Movies";
34 | string SeriesSubDir = "VOD Series";
35 | string TVSubDir = "TV Channels";
36 | string UserURL = "";
37 | string UserPort = "";
38 | string UserName = "";
39 | string UserPass = "";
40 | bool DeletePreviousDirEnabled = false;
41 | bool UnwantedCFGEnabled = true;
42 | bool VerboseConsoleOutputEnabled = false;
43 | bool ProgramLogEnabled = true;
44 | bool PurgeFilesEnabled = true;
45 | bool SeriesGroupSubdirEnabled = false;
46 | bool MovieGroupSubdirEnabled = false;
47 | bool DownloadM3U8Enabled = false;
48 |
49 | //get settings from external config
50 | if (ConfigurationManager.AppSettings.Get("BaseDirectory") != null && ConfigurationManager.AppSettings.Get("BaseDirectory") != "")
51 | BaseDirectory = ConfigurationManager.AppSettings.Get("BaseDirectory");
52 |
53 | if (ConfigurationManager.AppSettings.Get("OutDirectory") != null && ConfigurationManager.AppSettings.Get("OutDirectory") != "")
54 | OutDirectory = ConfigurationManager.AppSettings.Get("OutDirectory");
55 |
56 | if (ConfigurationManager.AppSettings.Get("MoviesSubDir") != null && ConfigurationManager.AppSettings.Get("MoviesSubDir") != "")
57 | MoviesSubDir = ConfigurationManager.AppSettings.Get("MoviesSubDir");
58 |
59 | if (ConfigurationManager.AppSettings.Get("SeriesSubDir") != null && ConfigurationManager.AppSettings.Get("SeriesSubDir") != "")
60 | SeriesSubDir = ConfigurationManager.AppSettings.Get("SeriesSubDir");
61 |
62 | if (ConfigurationManager.AppSettings.Get("TVSubDir") != null && ConfigurationManager.AppSettings.Get("TVSubDir") != "")
63 | TVSubDir = ConfigurationManager.AppSettings.Get("TVSubDir");
64 |
65 | if (ConfigurationManager.AppSettings.Get("DeletePreviousDirEnabled") != null && ConfigurationManager.AppSettings.Get("DeletePreviousDirEnabled") != "")
66 | DeletePreviousDirEnabled = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("DeletePreviousDirEnabled"));
67 |
68 | if (ConfigurationManager.AppSettings.Get("UnwantedCFGEnabled") != null && ConfigurationManager.AppSettings.Get("UnwantedCFGEnabled") != "")
69 | UnwantedCFGEnabled = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("UnwantedCFGEnabled"));
70 |
71 | if (ConfigurationManager.AppSettings.Get("VerboseConsoleOutputEnabled") != null && ConfigurationManager.AppSettings.Get("VerboseConsoleOutputEnabled") != "")
72 | VerboseConsoleOutputEnabled = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("VerboseConsoleOutputEnabled"));
73 |
74 | if (ConfigurationManager.AppSettings.Get("ProgramLogEnabled") != null && ConfigurationManager.AppSettings.Get("ProgramLogEnabled") != "")
75 | ProgramLogEnabled = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("ProgramLogEnabled"));
76 |
77 | if (ConfigurationManager.AppSettings.Get("PurgeFilesEnabled") != null && ConfigurationManager.AppSettings.Get("PurgeFilesEnabled") != "")
78 | PurgeFilesEnabled = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("PurgeFilesEnabled"));
79 |
80 | if (ConfigurationManager.AppSettings.Get("SeriesGroupSubdirEnabled") != null && ConfigurationManager.AppSettings.Get("SeriesGroupSubdirEnabled") != "")
81 | SeriesGroupSubdirEnabled = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("SeriesGroupSubdirEnabled"));
82 |
83 | if (ConfigurationManager.AppSettings.Get("MovieGroupSubdirEnabled") != null && ConfigurationManager.AppSettings.Get("MovieGroupSubdirEnabled") != "")
84 | MovieGroupSubdirEnabled = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("MovieGroupSubdirEnabled"));
85 |
86 | if (ConfigurationManager.AppSettings.Get("DownloadM3U8Enabled") != null && ConfigurationManager.AppSettings.Get("DownloadM3U8Enabled") != "")
87 | DownloadM3U8Enabled = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("DownloadM3U8Enabled"));
88 |
89 | if (ConfigurationManager.AppSettings.Get("UserURL") != null && ConfigurationManager.AppSettings.Get("UserURL") != "")
90 | UserURL = ConfigurationManager.AppSettings.Get("UserURL");
91 |
92 | if (ConfigurationManager.AppSettings.Get("UserPort") != null && ConfigurationManager.AppSettings.Get("UserPort") != "")
93 | UserPort = ConfigurationManager.AppSettings.Get("UserPort");
94 |
95 | if (ConfigurationManager.AppSettings.Get("UserName") != null && ConfigurationManager.AppSettings.Get("UserName") != "")
96 | UserName = ConfigurationManager.AppSettings.Get("UserName");
97 |
98 | if (ConfigurationManager.AppSettings.Get("UserPass") != null && ConfigurationManager.AppSettings.Get("UserPass") != "")
99 | UserPass = ConfigurationManager.AppSettings.Get("UserPass");
100 |
101 | //set streamwriter for programLog
102 | StreamWriter programLog = null;
103 |
104 | //set webclient for source download
105 | WebClient webClient = new WebClient();
106 |
107 | //user agent for webclient
108 | string m2strmVer = $"{programName}/{version}";
109 | webClient.Headers.Add("user-agent", m2strmVer);
110 |
111 | //combine output dirs
112 | string MoviesDir = Path.Combine(OutDirectory, MoviesSubDir);
113 | string SeriesDir = Path.Combine(OutDirectory, SeriesSubDir);
114 | string TVDir = Path.Combine(OutDirectory, TVSubDir);
115 |
116 | //date formats
117 | string longDate = (DateTime.Now.ToString("yyyyMMddHHmm")); //corrected for 24-hour format
118 | string shortDate = (DateTime.Now.ToString("yyyyMMdd"));
119 |
120 | //log files locations and names
121 | string logSubDir = $"log{Path.DirectorySeparatorChar}";
122 | string logDir = Path.Combine(BaseDirectory, logSubDir);
123 | string programLogFile = $"{logDir}{programName}_{shortDate}.log";
124 | string allGroupsFile = $"{logDir}allgroups.log"; //groups found during each parse
125 | string uwgLogFile = $"{logDir}uwgroups.log"; //groups that filters out through uwgCfgFile
126 | string newGroupsFile = $"{logDir}newgroups.log"; //groups not found at all in uwgCfgFile
127 | string dupeLogFile = $"{logDir}dupes.log";
128 | string newLogFile = $"{logDir}new_{longDate}.log";
129 | string newLogFileOld = $"{newLogFile}.old";
130 | string purgeLogFile = $"{logDir}purged_{longDate}.log";
131 |
132 | //init string arrays
133 | string[] allGroupsArray = { }; //all groups found
134 | string[] uwgLogArray = { }; //logs unwanted groups
135 | string[] newGroupArray = { }; //groups not found at all in uwgCfgFile
136 | string[] dupeArray = { }; //dupes found
137 | string[] filesOnDiskArray = { }; //files found on disk
138 | string[] foundArray = { }; //titles found in source
139 | string[] newArray = { }; //new titles this run
140 | string[] outArray = { }; //strm-files written to disk
141 | string[] purgeArray = { }; //files to purge from disk
142 | string[] uwgCfgArray = { }; //unwanted groups config
143 | string[] sourceTextLines = { }; //lines from the source file
144 |
145 | //init bool
146 | bool fileNotFound = false; //file is not found
147 |
148 | //other file locations and names
149 | string uwgCfgFile = $"{BaseDirectory}uwgroups.cfg";
150 | string uwgCfgFileOld = $"{uwgCfgFile}.old";
151 | string userM3u8File = $"{BaseDirectory}original.m3u8"; //this will be the filename of the user downloaded m3u8-file
152 | string userM3u8FileTemp = $"{BaseDirectory}_temp.m3u8"; //temporary m3u8 when downloading
153 | string userM3u8FileNotValid = $"{BaseDirectory}notvalid.m3u8"; //filename of a downloaded not valid m3u8
154 |
155 | //misc strings
156 | string newLine = ("\n");
157 | string getNameAndGroupREGEX = @"^#EXTINF:.* \btvg-name=""([^""]+|)"".* \bgroup-title=""([^""]+|)"",.*$";
158 | string programLogStartLine = $"{DateTime.Now}: *** Log begin, {programFileName}, {version}";
159 | string UserURLCombined = $"{UserURL}:{UserPort}/get.php?username={UserName}&password={UserPass}&type=m3u_plus&output=ts";
160 | string strmEXT = ".strm"; //this is the file extension added to output files
161 | string contentM3u8 = "#EXTM3U"; //program-downloaded m3u8 must contain this to be accepted as valid
162 |
163 | //init strings
164 | string GROUP = "";
165 | string NAME = "";
166 | string URL = ""; //url of the strm
167 | string lowerNAME = ""; //NAME converted to lowercase
168 | string seriesNAME = ""; //name of the series without sxxexx
169 | string NameStrm = ""; //name with strmEXT added
170 | string contentType = ""; //tv, movie or series
171 | string sourceText = ""; //source text
172 | string sourceTextLine1 = "";
173 | string sourceTextLine2 = "";
174 | string outText = ""; //used by console and log output
175 | string strmContentOld = ""; //strm-content currently on a disk file
176 | string combinedTypeDir = ""; //combines series/movies/tv-dirs with seriesName or GROUP
177 | string combinedTypeNameStrm = ""; //combines combinedTypeDir, NAME, and strmEXT
178 |
179 | //init counters
180 | int cMovies = 0;
181 | int cMoviesUpdate = 0;
182 | int cSkippedMovies;
183 | int cMoviesDupe = 0;
184 | int cMoviesPurge = 0;
185 | int cMoviesActual = 0;
186 | int cSeries = 0;
187 | int cSeriesUpdate = 0;
188 | int cSkippedSeries;
189 | int cSeriesDupe = 0;
190 | int cSeriesPurge = 0;
191 | int cSeriesActual = 0;
192 | int cTV = 0;
193 | int cTVUpdate = 0;
194 | int cSkippedTV;
195 | int cTVDupe = 0;
196 | int cTVPurge = 0;
197 | int cTVActual = 0;
198 |
199 | //check if args is given
200 | if (args.Length > 0)
201 | {
202 | if (args[0] == "/?" || args[0] == "-?" || args[0].ToLower() == "/h" || args[0].ToLower() == "-h" || args[0].ToLower() == "/help" || args[0].ToLower() == "-help" || args[0].ToLower() == "--help")
203 | {
204 | //help section
205 | Console.WriteLine("Creates STRM-files from M3U8-file.\n");
206 | Console.WriteLine($"{programFileName} [OPTIONS] [drive:][path][filename]\n");
207 | Console.WriteLine(" filename The source M3U8-file to be processed.\n");
208 | Console.WriteLine(" /C Create default configuration file. Warning: resets existing settings.");
209 | Console.WriteLine(" /U [filename] Create the unwanted groups file with a list of all groups from filename.");
210 | Console.WriteLine(" /D Delete previously created directories and then quit.");
211 | Console.WriteLine(" /M Download M3U8-file and then quit. Uses config set information.");
212 | Console.WriteLine(" /G Show a guide to help you get started quickly.");
213 | Console.WriteLine(" /V Version information.");
214 | Console.WriteLine(" /? or /H This help.\n");
215 | if (File.Exists(configFile))
216 | Console.WriteLine($"Configuration file found: {configFile}");
217 | if (!File.Exists(configFile))
218 | {
219 | Console.WriteLine("Configuration file not found.");
220 | }
221 | if (File.Exists(uwgCfgFile))
222 | Console.WriteLine($"Unwanted groups file found: {uwgCfgFile}");
223 | if (!File.Exists(uwgCfgFile))
224 | {
225 | Console.WriteLine("Unwanted groups file not found.");
226 | }
227 | Console.WriteLine("\nExample usage:");
228 | Console.WriteLine($"{programFileName} original.m3u8");
229 | return;
230 | }
231 |
232 | else if (args[0].ToLower() == "/m")
233 | {
234 | Console.WriteLine($"*** Downloading M3U8-file to: {userM3u8File}");
235 | webClient.DownloadFile(new Uri(UserURLCombined), userM3u8FileTemp);
236 | if (File.Exists(userM3u8File))
237 | File.Delete(userM3u8File);
238 | File.Move(userM3u8FileTemp, userM3u8File);
239 | return;
240 | }
241 |
242 | else if (args[0].ToLower() == "/v")
243 | {
244 | Console.WriteLine(creator);
245 | Console.WriteLine($"{programFileName} version {version}");
246 | return;
247 | }
248 |
249 | else if (args[0].ToLower() == "/c")
250 | {
251 | //backup old configFile if exist
252 | if (File.Exists(configFile))
253 | {
254 | if (File.Exists(configFileOld))
255 | File.Delete(configFileOld);
256 | File.Move(configFile, configFileOld);
257 | Console.WriteLine($"*** WARNING: Configuration file existed and has been moved to: {configFileOld}.");
258 | //starts another process in background that loads default values before writing new config
259 | Process.Start(Environment.GetCommandLineArgs()[0], Environment.GetCommandLineArgs().Length > 1 ? string.Join(" ", Environment.GetCommandLineArgs().Skip(1)) : null);
260 | return;
261 | }
262 |
263 | //remove user set config values
264 | userSettings.Add("BaseDirectory", "");
265 | userSettings.Add("OutDirectory", "");
266 | userSettings.Add("m3u8File", "");
267 | userSettings.Add("MoviesSubDir", "");
268 | userSettings.Add("SeriesSubDir", "");
269 | userSettings.Add("TVSubDir", "");
270 | userSettings.Add("DeletePreviousDirEnabled", "");
271 | userSettings.Add("UnwantedCFGEnabled", "");
272 | userSettings.Add("VerboseConsoleOutputEnabled", "");
273 | userSettings.Add("ProgramLogEnabled", "");
274 | userSettings.Add("PurgeFilesEnabled", "");
275 | userSettings.Add("SeriesGroupSubdirEnabled", "");
276 | userSettings.Add("MovieGroupSubdirEnabled", "");
277 | userSettings.Add("DownloadM3U8Enabled", "");
278 | userSettings.Add("UserURL", "");
279 | userSettings.Add("UserPort", "");
280 | userSettings.Add("UserName", "");
281 | userSettings.Add("UserPass", "");
282 |
283 | //set default user config values
284 | userSettings["BaseDirectory"].Value = BaseDirectory;
285 | userSettings["OutDirectory"].Value = OutDirectory;
286 | userSettings["m3u8File"].Value = m3u8File;
287 | userSettings["MoviesSubDir"].Value = MoviesSubDir;
288 | userSettings["SeriesSubDir"].Value = SeriesSubDir;
289 | userSettings["TVSubDir"].Value = TVSubDir;
290 | userSettings["DeletePreviousDirEnabled"].Value = Convert.ToString(DeletePreviousDirEnabled);
291 | userSettings["UnwantedCFGEnabled"].Value = Convert.ToString(UnwantedCFGEnabled);
292 | userSettings["VerboseConsoleOutputEnabled"].Value = Convert.ToString(VerboseConsoleOutputEnabled);
293 | userSettings["ProgramLogEnabled"].Value = Convert.ToString(ProgramLogEnabled);
294 | userSettings["PurgeFilesEnabled"].Value = Convert.ToString(PurgeFilesEnabled);
295 | userSettings["SeriesGroupSubdirEnabled"].Value = Convert.ToString(SeriesGroupSubdirEnabled);
296 | userSettings["MovieGroupSubdirEnabled"].Value = Convert.ToString(MovieGroupSubdirEnabled);
297 | userSettings["DownloadM3U8Enabled"].Value = Convert.ToString(DownloadM3U8Enabled);
298 | userSettings["UserURL"].Value = UserURL;
299 | userSettings["UserPort"].Value = UserPort;
300 | userSettings["UserName"].Value = UserName;
301 | userSettings["UserPass"].Value = UserPass;
302 | userConfigFile.Save(ConfigurationSaveMode.Modified);
303 | Console.WriteLine($"*** Configuration file created: {configFile}");
304 | return;
305 | }
306 |
307 | else if (args[0].ToLower() == "/g")
308 | {
309 | Console.WriteLine("\nQuick guide:\n");
310 | Console.WriteLine($"1. Create the configuration file: {programFileName} /C");
311 | Console.WriteLine("2. Edit the configuration file and set at least the following:");
312 | Console.WriteLine(" - m3u8File value: /where/you/want/to/download/original.m3u8");
313 | Console.WriteLine(" - DownloadM3U8Enabled value: True");
314 | Console.WriteLine(" - Also fill in your UserURL, UserPort, UserName and UserPass.");
315 | Console.WriteLine($"3. Download your M3U8-file using the configuration file settings: {programFileName} /M");
316 | Console.WriteLine($"4. Create the unwanted groups file: {programFileName} /U");
317 | Console.WriteLine("5. Edit the unwanted groups file and comment out the groups you want to keep with //.");
318 | Console.WriteLine($"6. You're all done. From now on you can run {programFileName} without any arguments and the program will be using your configuration.\n");
319 | return;
320 | }
321 |
322 | else if (args[0].ToLower() == "/d")
323 | {
324 | Console.WriteLine("*** Deleting previously created directories.");
325 | if (Directory.Exists(MoviesDir))
326 | Directory.Delete(MoviesDir, true);
327 | if (Directory.Exists(SeriesDir))
328 | Directory.Delete(SeriesDir, true);
329 | if (Directory.Exists(TVDir))
330 | Directory.Delete(TVDir, true);
331 | return;
332 | }
333 |
334 | else if (args[0].ToLower() == "/u")
335 | {
336 | //download m3u8 section
337 | if (args.Length > 1)
338 | {
339 | //arg 1 converted to m8u8File
340 | m3u8File = args[1];
341 | if (File.Exists(m3u8File))
342 | {
343 | if (ConfigurationManager.AppSettings.Get("m3u8File") != null && ConfigurationManager.AppSettings.Get("m3u8File") != "")
344 | Console.WriteLine($"*** Using arg specified M3U8-file: {m3u8File} (overriding config).");
345 | else Console.WriteLine($"*** Using arg specified M3U8-file: {m3u8File} (not set in config).");
346 | }
347 | else
348 | {
349 | fileNotFound = true;
350 | Console.WriteLine($"File not found - {m3u8File}");
351 | return;
352 | }
353 | }
354 | else
355 | {
356 | if (ConfigurationManager.AppSettings.Get("m3u8File") != null && ConfigurationManager.AppSettings.Get("m3u8File") != "")
357 | m3u8File = ConfigurationManager.AppSettings.Get("m3u8File");
358 | if (File.Exists(m3u8File))
359 | Console.WriteLine($"*** Using config set M3U8-file: {m3u8File}");
360 | else
361 | {
362 | fileNotFound = true;
363 | Console.WriteLine($"File not found - {m3u8File}");
364 | return;
365 | }
366 | }
367 |
368 | //used for warning message later
369 | bool uwgCfgExisted = false;
370 |
371 | //backup old uwgCfgFile
372 | if (File.Exists(uwgCfgFile))
373 | {
374 | if (File.Exists(uwgCfgFileOld))
375 | File.Delete(uwgCfgFileOld);
376 | File.Copy(uwgCfgFile, uwgCfgFileOld, true);
377 | uwgCfgExisted = true;
378 | }
379 |
380 | //set the content of the m3u8File to sourceText
381 | sourceText = File.ReadAllText(m3u8File);
382 |
383 | //normalize linefeed
384 | sourceText = sourceText
385 | .Replace("\r\n", "\n")
386 | .Replace("\r", "\n");
387 |
388 | //there is a title not in a group, used for setting the _NOGROUP
389 | bool ngExist = false;
390 |
391 | //empty old contents of uwgCfgFile
392 | File.WriteAllText(uwgCfgFile, string.Empty);
393 |
394 | //create a uwgCfgFile with a list of all groups
395 | sourceTextLines = sourceText.Split(newLine.ToCharArray());
396 | for (var index = 1; index <= sourceTextLines.Length - 1; index++)
397 | {
398 | sourceTextLine1 = sourceTextLines[(int)index];
399 | //find a line that starts with #EXTINF:
400 | if (sourceTextLine1.ToLower().StartsWith("#extinf:"))
401 | {
402 | //reset GROUP
403 | GROUP = "";
404 |
405 | //get NAME and GROUP using regex pattern and capture groups (only using GROUP here)
406 | Match match = Regex.Match(sourceTextLine1, getNameAndGroupREGEX, RegexOptions.IgnoreCase);
407 | GROUP = match.Groups[2].Value;
408 |
409 | //check if noname group
410 | if (GROUP == "")
411 | {
412 | ngExist = true;
413 | GROUP = "_NOGROUP";
414 | }
415 |
416 | //less output by not letting same output twice
417 | if (uwgCfgArray.Contains(GROUP) == false)
418 | {
419 | Console.WriteLine($"Found group: {GROUP}");
420 | //add the group to the array
421 | Array.Resize(ref uwgCfgArray, uwgCfgArray.Length + 1);
422 | uwgCfgArray[uwgCfgArray.Length - 1] = GROUP;
423 | }
424 | }
425 | }
426 |
427 | //tidy up in the uwgCfgArray and write to uwgCfgFile
428 | //remove blank lines
429 | //uwgCfgArray = uwgCfgArray.Where(x => !string.IsNullOrEmpty(x)).ToArray();
430 | //sort the lines alphabetically ascending
431 | Array.Sort(uwgCfgArray);
432 | //remove duplicates
433 | //File.WriteAllLines(uwgCfgFile, uwgCfgArray.Distinct().ToArray());
434 | File.WriteAllLines(uwgCfgFile, uwgCfgArray);
435 | if (uwgCfgExisted == true)
436 | Console.WriteLine($"\n*** WARNING: Unwanted groups file existed and has been moved to: {uwgCfgFileOld}");
437 | else
438 | Console.WriteLine("");
439 | Console.WriteLine($"*** Unwanted groups file created: {uwgCfgFile}");
440 | if (ngExist == true)
441 | Console.WriteLine("*** Note: We've found titles not in groups, they will be processed as _NOGROUP.");
442 | return;
443 | }
444 |
445 | else if (args[0].StartsWith("/"))
446 | {
447 | Console.WriteLine($"Invalid switch - {args[0]}");
448 | Console.WriteLine("Type /? for help");
449 | return;
450 | }
451 | else
452 | {
453 | //if we've come here, the user has given an arg not starting with /
454 | //which we now believe is a local m3u8-file
455 | m3u8File = args[0];
456 | if (File.Exists(m3u8File))
457 | {
458 | //start logging (1/3)
459 | if (ProgramLogEnabled == true)
460 | {
461 | //Create log directory if not exist
462 | if (!Directory.Exists(logDir))
463 | Directory.CreateDirectory(logDir);
464 | programLog = File.AppendText(programLogFile);
465 | programLog.WriteLine(programLogStartLine);
466 | }
467 | else
468 | {
469 | outText = $"{DateTime.Now}: INFO: Program logging is disabled in config.";
470 | Console.WriteLine(outText);
471 | }
472 |
473 | if (ConfigurationManager.AppSettings.Get("m3u8File") != null && ConfigurationManager.AppSettings.Get("m3u8File") != "")
474 | {
475 | outText = $"{DateTime.Now}: *** Using arg specified M3U8-file: {m3u8File} (overriding config).";
476 | Console.WriteLine(outText);
477 | if (ProgramLogEnabled == true) programLog.WriteLine(outText);
478 | }
479 | else
480 | {
481 | outText = $"{DateTime.Now}: Using arg specified M3U8-file: {m3u8File} (not set in config).";
482 | Console.WriteLine(outText);
483 | if (ProgramLogEnabled == true) programLog.WriteLine(outText);
484 | }
485 | }
486 | else
487 | //we did not find the file given in arg
488 | fileNotFound = true;
489 | }
490 | }
491 | else
492 | {
493 | //we end up here if arg is not given, trying to set the m3u8File with config set location
494 | if (ConfigurationManager.AppSettings.Get("m3u8File") != null && ConfigurationManager.AppSettings.Get("m3u8File") != "")
495 | m3u8File = ConfigurationManager.AppSettings.Get("m3u8File");
496 |
497 | if (File.Exists(m3u8File) && (DownloadM3U8Enabled != true))
498 | {
499 | //start logging (2/3)
500 | if (ProgramLogEnabled == true)
501 | {
502 | //create log directory if not exist
503 | if (!Directory.Exists(logDir))
504 | Directory.CreateDirectory(logDir);
505 | programLog = File.AppendText(programLogFile);
506 | programLog.WriteLine(programLogStartLine);
507 | }
508 | else
509 | {
510 | outText = $"{DateTime.Now}: INFO: Program logging is disabled in config.";
511 | Console.WriteLine(outText);
512 | }
513 | outText = $"{DateTime.Now}: *** Using config set M3U8-file: {m3u8File}";
514 | Console.WriteLine(outText);
515 | if (ProgramLogEnabled == true) programLog.WriteLine(outText);
516 | }
517 | else
518 | {
519 | //if we did not find the config set m3u8-file
520 | if (!File.Exists(m3u8File))
521 | fileNotFound = true;
522 | }
523 | }
524 |
525 | //output to log and console, pause
526 | //outText = $"{DateTime.Now}: Stuff here {stringhere}";
527 | //Console.WriteLine(outText);
528 | //if (ProgramLogEnabled == true) programLog.WriteLine(outText);
529 | //Console.ReadKey();
530 |
531 | //check if user wants to download m3u8 before parsing
532 | if (DownloadM3U8Enabled == true)
533 | {
534 | //start logging (3/3)
535 | if (ProgramLogEnabled == true)
536 | {
537 | //create log directory if not exist
538 | if (!Directory.Exists(logDir))
539 | Directory.CreateDirectory(logDir);
540 | programLog = File.AppendText(programLogFile);
541 | programLog.WriteLine(programLogStartLine);
542 | }
543 | else
544 | {
545 | outText = $"{DateTime.Now}: INFO: Program logging is disabled in config.";
546 | Console.WriteLine(outText);
547 | }
548 | outText = $"{DateTime.Now}: *** Downloading M3U8-file to: {userM3u8File}";
549 | Console.WriteLine(outText);
550 | if (ProgramLogEnabled == true) programLog.WriteLine(outText);
551 |
552 | //download the m3u8-file
553 | webClient.DownloadFile(new Uri(UserURLCombined), userM3u8FileTemp);
554 |
555 | //check validity of m3u8-file
556 | string content = File.ReadAllText(userM3u8FileTemp);
557 | if (content.IndexOf(contentM3u8) > -1)
558 | {
559 | if (File.Exists(userM3u8File))
560 | File.Delete(userM3u8File);
561 | File.Move(userM3u8FileTemp, userM3u8File);
562 | outText = $"{DateTime.Now}: *** M3U8-file validation: Success";
563 | Console.WriteLine(outText);
564 | if (ProgramLogEnabled == true) programLog.WriteLine(outText);
565 | }
566 | else
567 | {
568 | if (File.Exists(userM3u8FileNotValid))
569 | File.Delete(userM3u8FileNotValid);
570 | File.Move(userM3u8FileTemp, userM3u8FileNotValid);
571 | Console.WriteLine($"M3U8-file validation: Failed - {userM3u8FileNotValid}");
572 | return;
573 | }
574 |
575 | if (m3u8File != null || m3u8File != "")
576 | {
577 | outText = $"{DateTime.Now}: *** Using downloaded M3U8-file: {userM3u8File} (overrides config/args).";
578 | Console.WriteLine(outText);
579 | if (ProgramLogEnabled == true) programLog.WriteLine(outText);
580 | }
581 | else
582 | {
583 | outText = $"{DateTime.Now}: *** Using downloaded M3U8-file: {userM3u8File}";
584 | Console.WriteLine(outText);
585 | if (ProgramLogEnabled == true) programLog.WriteLine(outText);
586 | }
587 | //set m3u8File to userM3u8File
588 | m3u8File = userM3u8File;
589 | }
590 |
591 | //start stopwatch, this late because we are not interested in how long it might take to download m3u8
592 | var stopWatch = Stopwatch.StartNew();
593 |
594 | //if m3u8File exist continue, or set fileNotFound true
595 | if (File.Exists(m3u8File))
596 | {
597 | outText = $"{DateTime.Now}: *** BaseDirectory: {BaseDirectory}";
598 | Console.WriteLine(outText);
599 | if (ProgramLogEnabled == true) programLog.WriteLine(outText);
600 |
601 | outText = $"{DateTime.Now}: *** OutDirectory: {OutDirectory}";
602 | Console.WriteLine(outText);
603 | if (ProgramLogEnabled == true) programLog.WriteLine(outText);
604 |
605 | outText = $"{DateTime.Now}: *** Movie subfolder: {MoviesSubDir}";
606 | Console.WriteLine(outText);
607 | if (ProgramLogEnabled == true) programLog.WriteLine(outText);
608 |
609 | outText = $"{DateTime.Now}: *** Series subfolder: {SeriesSubDir}";
610 | Console.WriteLine(outText);
611 | if (ProgramLogEnabled == true) programLog.WriteLine(outText);
612 |
613 | outText = $"{DateTime.Now}: *** TV subfolder: {TVSubDir}";
614 | Console.WriteLine(outText);
615 | if (ProgramLogEnabled == true) programLog.WriteLine(outText);
616 |
617 | //check if config exists
618 | if (File.Exists(configFile))
619 | {
620 | outText = $"{DateTime.Now}: *** Configuration file in use: {configFile}";
621 | Console.WriteLine(outText);
622 | if (ProgramLogEnabled == true) programLog.WriteLine(outText);
623 | }
624 |
625 | //set uwgCfgFile if wanted and exists
626 | if (File.Exists(uwgCfgFile) && UnwantedCFGEnabled == true)
627 | {
628 | outText = $"{DateTime.Now}: *** Unwanted groups file in use: {uwgCfgFile}";
629 | Console.WriteLine(outText);
630 | if (ProgramLogEnabled == true) programLog.WriteLine(outText);
631 | uwgCfgArray = File.ReadAllLines(uwgCfgFile);
632 | }
633 | else if (UnwantedCFGEnabled == false)
634 | {
635 | outText = $"{DateTime.Now}: *** Unwanted groups file not in use.";
636 | Console.WriteLine(outText);
637 | if (ProgramLogEnabled == true) programLog.WriteLine(outText);
638 | }
639 |
640 | //empty old contents of uwgLogFile
641 | if (ProgramLogEnabled == true) File.WriteAllText(uwgLogFile, string.Empty);
642 |
643 | //empty old contents of allGroupsFile
644 | if (ProgramLogEnabled == true) File.WriteAllText(allGroupsFile, string.Empty);
645 |
646 | //empty old contents of dupeLogFile
647 | if (ProgramLogEnabled == true) File.WriteAllText(dupeLogFile, string.Empty);
648 |
649 | //empty old contents of newGroupsFile
650 | if (ProgramLogEnabled == true) File.WriteAllText(newGroupsFile, string.Empty);
651 |
652 | //in the odd instance newLogFile would exist with the same name from previous run, add .old to the old one
653 | if (File.Exists(newLogFile))
654 | {
655 | if (File.Exists(newLogFileOld))
656 | File.Delete(newLogFileOld);
657 | File.Move(newLogFile, newLogFileOld);
658 | }
659 |
660 | //delete previously created directories
661 | if (DeletePreviousDirEnabled == true)
662 | {
663 | outText = $"{DateTime.Now}: *** Deleting previously created directories (set in config).";
664 | Console.WriteLine(outText);
665 | if (ProgramLogEnabled == true) programLog.WriteLine(outText);
666 |
667 | //Delete directories
668 | if (Directory.Exists(MoviesDir))
669 | Directory.Delete(MoviesDir, true);
670 | if (Directory.Exists(SeriesDir))
671 | Directory.Delete(SeriesDir, true);
672 | if (Directory.Exists(TVDir))
673 | Directory.Delete(TVDir, true);
674 | }
675 | else
676 | {
677 | outText = $"{DateTime.Now}: *** Not deleting previously created directories.";
678 | if (ProgramLogEnabled == true) programLog.WriteLine(outText);
679 | }
680 |
681 | //tell user we are using series-group subfolders if set
682 | if (SeriesGroupSubdirEnabled == true)
683 | {
684 | outText = $"{DateTime.Now}: *** Creating series-group subfolders (set in config).";
685 | Console.WriteLine(outText);
686 | if (ProgramLogEnabled == true) programLog.WriteLine(outText);
687 | }
688 |
689 | //tell user we are using movie-group subfolders if set
690 | if (MovieGroupSubdirEnabled == true)
691 | {
692 | outText = $"{DateTime.Now}: *** Creating movie-group subfolders (set in config).";
693 | Console.WriteLine(outText);
694 | if (ProgramLogEnabled == true) programLog.WriteLine(outText);
695 | }
696 |
697 | //################################### parse start ###################################
698 | //now we finally start to parse the m3u8-file
699 | outText = $"{DateTime.Now}: *** Processing {m3u8File}";
700 | Console.WriteLine(outText);
701 | if (ProgramLogEnabled == true) programLog.WriteLine(outText);
702 |
703 | //set sourceText to the content of m3u8File
704 | sourceText = File.ReadAllText(m3u8File);
705 |
706 | //normalize linefeed
707 | sourceText = sourceText
708 | .Replace("\r\n", "\n")
709 | .Replace("\r", "\n");
710 |
711 | //split each line into array
712 | sourceTextLines = sourceText.Split(newLine.ToCharArray());
713 | for (var index = 1; index <= sourceTextLines.Length - 1; index++)
714 | {
715 | sourceTextLine1 = sourceTextLines[(int)index];
716 | //find a line that starts with #EXTINF:
717 | if (sourceTextLine1.ToLower().StartsWith("#extinf:"))
718 | {
719 | //sourceTextLine2 will be the URL
720 | sourceTextLine2 = sourceTextLines[index + 1];
721 |
722 | //reset
723 | NAME = "";
724 | GROUP = "";
725 | URL = "";
726 | bool isUnwanted = false; //is unwanted
727 |
728 | //get NAME and GROUP using regex pattern and capture groups
729 | Match match = Regex.Match(sourceTextLine1, getNameAndGroupREGEX, RegexOptions.IgnoreCase);
730 | NAME = match.Groups[1].Value;
731 | GROUP = match.Groups[2].Value;
732 |
733 | //all items found that are not in a group will get the new NOGROUP value
734 | if (GROUP == "")
735 | {
736 | GROUP = "_NOGROUP";
737 | }
738 |
739 | if (ProgramLogEnabled == true)
740 | {
741 | if (allGroupsArray.Contains(GROUP) == false)
742 | {
743 | //add to array
744 | Array.Resize(ref allGroupsArray, allGroupsArray.Length + 1);
745 | allGroupsArray[allGroupsArray.Length - 1] = GROUP;
746 | }
747 | }
748 |
749 | foreach (string uwgCfgLine in uwgCfgArray)
750 | {
751 | if (GROUP == uwgCfgLine)
752 | {
753 | if (uwgLogArray.Contains(GROUP) == false && ProgramLogEnabled == true)
754 | {
755 | outText = $"{DateTime.Now}: Unwanted group: '{GROUP}' match in: '{uwgCfgLine}'";
756 | programLog.WriteLine(outText);
757 | //add to array
758 | Array.Resize(ref uwgLogArray, uwgLogArray.Length + 1);
759 | uwgLogArray[uwgLogArray.Length - 1] = GROUP;
760 | }
761 | //set isUnwanted to true
762 | isUnwanted = true;
763 | }
764 | continue;
765 | }
766 |
767 | if (isUnwanted == false)
768 | {
769 | //replace linefeed and carriage return with nothing
770 | URL = sourceTextLine2
771 | .Replace("\r\n", "")
772 | .Replace("\n", "")
773 | .Replace("\r", "")
774 | .Replace("\n", "");
775 |
776 | //run NAME and GROUP through special char filters
777 | NAME = NAMEFilterFileNameChars(NAME);
778 | GROUP = GROUPFilterFileNameChars(GROUP);
779 |
780 | //set contentType (movie or series) from URL
781 | if (URL.ToLower().Contains("/series"))
782 | contentType = "series";
783 | else if (URL.ToLower().Contains("/movie"))
784 | contentType = "movie";
785 | else
786 | contentType = "tv";
787 |
788 | //set stuff depending on contentType set
789 | if (contentType == "series")
790 | {
791 | //strip out SxxExx from NAME
792 | //needs .Trim('.', ' ') here again because we now strip SxxExx from NAME and seriesNAME might end with period or space
793 | seriesNAME = Regex.Replace(NAME, "s(\\d+)e(\\d+)", "", RegexOptions.IgnoreCase).Trim('.', ' ');
794 |
795 | //combine path for series
796 | if (SeriesGroupSubdirEnabled == true)
797 | combinedTypeDir = Path.Combine(SeriesDir, GROUP, seriesNAME); //with GROUP subdir
798 | else
799 | combinedTypeDir = Path.Combine(SeriesDir, seriesNAME);
800 |
801 | if (VerboseConsoleOutputEnabled == true)
802 | {
803 | outText = $"{DateTime.Now}: TV Show episode: {NAME} found";
804 | Console.WriteLine(outText);
805 | if (ProgramLogEnabled == true) programLog.WriteLine(outText);
806 | }
807 | cSeries++;
808 | }
809 | if (contentType == "movie")
810 | {
811 | //combine path for movies
812 | if (MovieGroupSubdirEnabled == true)
813 | combinedTypeDir = Path.Combine(MoviesDir, GROUP); //with GROUP subdir
814 | else
815 | combinedTypeDir = MoviesDir; //without GROUP subdir
816 |
817 | if (VerboseConsoleOutputEnabled == true)
818 | {
819 | outText = $"{DateTime.Now}: Movie: {NAME} found";
820 | Console.WriteLine(outText);
821 | if (ProgramLogEnabled == true) programLog.WriteLine(outText);
822 | }
823 | cMovies++;
824 | }
825 | if (contentType == "tv")
826 | {
827 | //combine path for tv
828 | combinedTypeDir = Path.Combine(TVDir, GROUP);
829 |
830 | //prepend a tv channel number to NAME
831 | NAME = $"{cTV} {NAME}";
832 |
833 | if (VerboseConsoleOutputEnabled == true)
834 | {
835 | outText = $"{DateTime.Now}: TV Channel: {NAME} found";
836 | Console.WriteLine(outText);
837 | if (ProgramLogEnabled == true) programLog.WriteLine(outText);
838 | }
839 | cTV++;
840 | }
841 |
842 | //create directory if not exist
843 | if (!Directory.Exists(combinedTypeDir))
844 | Directory.CreateDirectory(combinedTypeDir);
845 |
846 | //append strmEXT to the file name
847 | NameStrm = $"{NAME}{strmEXT}";
848 |
849 | //and combine the path with it
850 | combinedTypeNameStrm = Path.Combine(combinedTypeDir, NameStrm);
851 |
852 | //convert NAME to lowercase to get the same result on all OS
853 | lowerNAME = NAME.ToLower();
854 |
855 | //is a dupe
856 | bool isDupe = false;
857 |
858 | //compare with outArray, if already exist in array set isDupe = true
859 | if (outArray.Contains(lowerNAME))
860 | {
861 | //counter dupe up
862 | if (contentType == "movie")
863 | cMoviesDupe++;
864 | if (contentType == "series")
865 | cSeriesDupe++;
866 | if (contentType == "tv")
867 | cTVDupe++;
868 |
869 | //set isDupe to true
870 | isDupe = true;
871 | if (ProgramLogEnabled == true)
872 | {
873 | outText = $"{DateTime.Now}: Dupe found: {NAME}";
874 | programLog.WriteLine(outText);
875 | //add to dupeArray
876 | Array.Resize(ref dupeArray, dupeArray.Length + 1);
877 | dupeArray[dupeArray.Length - 1] = NAME;
878 | }
879 | }
880 |
881 | //add the to outArray
882 | Array.Resize(ref outArray, outArray.Length + 1);
883 | outArray[outArray.Length - 1] = lowerNAME;
884 |
885 | //add the title to foundArray only if not dupe
886 | if (isDupe == false)
887 | {
888 | Array.Resize(ref foundArray, foundArray.Length + 1);
889 | foundArray[foundArray.Length - 1] = (combinedTypeNameStrm);
890 | }
891 |
892 | //create output file if not exist on disk and not already in the outArray (dupe)
893 | if (!File.Exists(combinedTypeNameStrm) && isDupe == false)
894 | {
895 | //check if the filename plus path is too long for Windows filesystem
896 | int combinedTypeNameStrmLength = combinedTypeNameStrm.Length;
897 | if (combinedTypeNameStrmLength >= 260)
898 | {
899 | outText = $"WARNING: Destination path too long\nThe file name could be too long ({combinedTypeNameStrmLength} chars) for the destination directory.\n'{combinedTypeNameStrm}'";
900 | Console.WriteLine(outText);
901 | if (ProgramLogEnabled == true) programLog.WriteLine(outText);
902 | }
903 |
904 | //counter actual up
905 | if (contentType == "movie")
906 | cMoviesActual++;
907 | if (contentType == "series")
908 | cSeriesActual++;
909 | if (contentType == "tv")
910 | cTVActual++;
911 |
912 | //and finally, here we create the output file
913 | File.WriteAllText(combinedTypeNameStrm, URL);
914 |
915 | //write the same path and filename to newArray if ProgramLogEnabled true
916 | if (ProgramLogEnabled == true)
917 | {
918 | Array.Resize(ref newArray, newArray.Length + 1);
919 | newArray[newArray.Length - 1] = combinedTypeNameStrm;
920 | }
921 | }
922 |
923 | //if file exist and is not a dupe; check if new content, if so; update file with new content
924 | else if (File.Exists(combinedTypeNameStrm) && isDupe == false)
925 | {
926 | //compare old with new content
927 | strmContentOld = File.ReadAllText(combinedTypeNameStrm);
928 |
929 | //if old content not same as new then
930 | if (strmContentOld != URL)
931 | {
932 | //counter update up
933 | if (contentType == "movie")
934 | cMoviesUpdate++;
935 | if (contentType == "series")
936 | cSeriesUpdate++;
937 | if (contentType == "tv")
938 | cTVUpdate++;
939 |
940 | //overwrite old outdated content in output file
941 | File.WriteAllText(combinedTypeNameStrm, URL);
942 |
943 | outText = $"{DateTime.Now}: Updated content in: '{combinedTypeNameStrm}'";
944 | if (ProgramLogEnabled == true) programLog.WriteLine(outText);
945 | {
946 | //add the same path and filename to newArray
947 | Array.Resize(ref newArray, newArray.Length + 1);
948 | newArray[newArray.Length - 1] = combinedTypeNameStrm;
949 | }
950 | }
951 | else
952 | {
953 | //enable/disable logFileExists
954 | bool logFileExists = false;
955 |
956 | if (ProgramLogEnabled == true && logFileExists == true)
957 | {
958 | outText = $"{DateTime.Now}: File exists: {combinedTypeNameStrm}";
959 | programLog.WriteLine(outText);
960 | }
961 | }
962 | }
963 | }
964 | }
965 | }
966 |
967 | if (ProgramLogEnabled == true)
968 | {
969 | //tidy up the newArray and write to newLogFile
970 | if (newArray.Length > 0)
971 | {
972 | //sort the lines alphabetically ascending
973 | Array.Sort(newArray);
974 | //write to disk
975 | File.WriteAllLines(newLogFile, newArray);
976 | }
977 |
978 | //tidy up the uwgLogArray and write to uwgLogFile
979 | if (uwgLogArray.Length > 0)
980 | {
981 | //remove blank lines
982 | //uwgCfgArray = uwgCfgArray.Where(x => !string.IsNullOrEmpty(x)).ToArray();
983 | //sort the lines alphabetically ascending
984 | Array.Sort(uwgLogArray);
985 | //write to disk
986 | File.WriteAllLines(uwgLogFile, uwgLogArray);
987 | }
988 |
989 | //tidy up the allGroupsArray and write to allGroupsFile
990 | if (allGroupsArray.Length > 0)
991 | {
992 | //sort the lines alphabetically ascending
993 | Array.Sort(allGroupsArray);
994 | //write to disk
995 | File.WriteAllLines(allGroupsFile, allGroupsArray);
996 | }
997 |
998 | //tidy up the dupeArray and write to dupeLogFile
999 | if (dupeArray.Length > 0)
1000 | {
1001 | //sort the lines alphabetically ascending
1002 | Array.Sort(dupeArray);
1003 | //remove duplicates and write to disk
1004 | File.WriteAllLines(dupeLogFile, dupeArray.Distinct());
1005 | }
1006 |
1007 | //test newGroupArray
1008 | //first remove all comments // from uwgCfgArray
1009 | //this works but only changes the first occurance
1010 | //uwgCfgArray = uwgCfgArray.ToList().Select(x => Regex.Replace(x, @"^//", "")).ToArray();
1011 | //works -- but I would rather use regex to get the starts with ^
1012 | uwgCfgArray = uwgCfgArray.Select(x => x.Replace(@"//", "")).ToArray();
1013 |
1014 | //then remove uwgCfgArray from allGroupsArray
1015 | newGroupArray = allGroupsArray.Except(uwgCfgArray).ToArray();
1016 |
1017 | //File.WriteAllLines("_1.log", uwgCfgArray);
1018 |
1019 | //sort the lines alphabetically ascending
1020 | Array.Sort(newGroupArray);
1021 | //write to disk
1022 | File.WriteAllLines(newGroupsFile, newGroupArray);
1023 | }
1024 |
1025 | //purging old strm-files and deleting empty directories
1026 | if (PurgeFilesEnabled == true)
1027 | {
1028 | outText = $"{DateTime.Now}: *** Purging files in: {OutDirectory}";
1029 | Console.WriteLine(outText);
1030 | if (ProgramLogEnabled == true) programLog.WriteLine(outText);
1031 |
1032 | //get all strm-files on disk into array
1033 | filesOnDiskArray = Directory.GetFiles(OutDirectory, $"*{strmEXT}", SearchOption.AllDirectories);
1034 |
1035 | //remove content of foundArray from filesOnDiskArray -- left will be titles no longer in m3u8-file
1036 | purgeArray = filesOnDiskArray.Except(foundArray).ToArray();
1037 |
1038 | //set false as long as nothing was purged
1039 | bool hasPurged = false;
1040 |
1041 | //tidy up the purgeArray and write to purgeLogFile
1042 | if (purgeArray.Length > 0)
1043 | {
1044 | Array.Sort(purgeArray);
1045 | File.WriteAllLines(purgeLogFile, purgeArray);
1046 |
1047 | //purgeArray will now contain items to delete, here we split each array into string
1048 | foreach (string purgeItem in purgeArray)
1049 | {
1050 | //if file found
1051 | if (File.Exists(purgeItem))
1052 | {
1053 | //delete file
1054 | File.Delete(purgeItem);
1055 | outText = $"{DateTime.Now}: Purged file: {purgeItem}";
1056 | if (ProgramLogEnabled == true) programLog.WriteLine(outText);
1057 |
1058 | //set contentType
1059 | if (purgeItem.Contains(MoviesSubDir))
1060 | contentType = "movie";
1061 | else if (purgeItem.Contains(SeriesSubDir))
1062 | contentType = "series";
1063 | else
1064 | contentType = "tv";
1065 |
1066 | //counter purge up
1067 | if (contentType == "movie")
1068 | cMoviesPurge++;
1069 | if (contentType == "series")
1070 | cSeriesPurge++;
1071 | if (contentType == "tv")
1072 | cTVPurge++;
1073 |
1074 | //something was purged
1075 | hasPurged = true;
1076 | }
1077 | }
1078 | }
1079 |
1080 | //only run directory cleanup if something was purged
1081 | if (hasPurged == true)
1082 | {
1083 | //delete empty directories which can be a left over after a purge
1084 | foreach (var directory in Directory.GetDirectories(OutDirectory, "*", SearchOption.AllDirectories))
1085 | {
1086 | if (Directory.GetFiles(directory, "*", SearchOption.AllDirectories).Length == 0)
1087 | {
1088 | Directory.Delete(directory, true);
1089 | outText = $"{DateTime.Now}: Deleted empty directory: {directory}";
1090 | if (ProgramLogEnabled == true) programLog.WriteLine(outText);
1091 | }
1092 | }
1093 | }
1094 | }
1095 |
1096 | //subtract actual written from found = skipped
1097 | cSkippedMovies = cMovies - cMoviesActual;
1098 | cSkippedSeries = cSeries - cSeriesActual;
1099 | cSkippedTV = cTV - cTVActual;
1100 |
1101 | //set counters output strings
1102 | string newMovies = "0 new";
1103 | string updateMovies = "";
1104 | string skipMovies = "";
1105 | string dupeMovies = "";
1106 | string purgeMovies = "";
1107 | string totalMovies = "";
1108 | string newSeries = "0 new";
1109 | string updateSeries = "";
1110 | string skipSeries = "";
1111 | string dupeSeries = "";
1112 | string purgeSeries = "";
1113 | string totalSeries = "";
1114 | string newTV = "0 new";
1115 | string updateTV = "";
1116 | string skipTV = "";
1117 | string dupeTV = "";
1118 | string purgeTV = "";
1119 | string totalTV = "";
1120 |
1121 | //set counters output
1122 | if (cMoviesActual > 0) newMovies = $"{Convert.ToString(cMoviesActual)} new";
1123 | if (cMoviesUpdate > 0) updateMovies = $", {Convert.ToString(cMoviesUpdate)} updated";
1124 | if (cSkippedMovies > 0) skipMovies = $", {Convert.ToString(cSkippedMovies)} skipped";
1125 | if (cMoviesDupe > 0) dupeMovies = $" (whereof {Convert.ToString(cMoviesDupe)} dupes)";
1126 | if (cMoviesPurge > 0) purgeMovies = $", {Convert.ToString(cMoviesPurge)} purged";
1127 | if (cMovies > 0) totalMovies = $", {Convert.ToString(cMovies)} in total";
1128 |
1129 | if (cSeriesActual > 0) newSeries = $"{Convert.ToString(cSeriesActual)} new";
1130 | if (cSeriesUpdate > 0) updateSeries = $", {Convert.ToString(cSeriesUpdate)} updated";
1131 | if (cSkippedSeries > 0) skipSeries = $", {Convert.ToString(cSkippedSeries)} skipped";
1132 | if (cSeriesDupe > 0) dupeSeries = $" (whereof {Convert.ToString(cSeriesDupe)} dupes)";
1133 | if (cSeriesPurge > 0) purgeSeries = $", {Convert.ToString(cSeriesPurge)} purged";
1134 | if (cSeries > 0) totalSeries = $", {Convert.ToString(cSeries)} in total";
1135 |
1136 | if (cTVActual > 0) newTV = $"{Convert.ToString(cTVActual)} new";
1137 | if (cTVUpdate > 0) updateTV = $", {Convert.ToString(cTVUpdate)} updated";
1138 | if (cSkippedTV > 0) skipTV = $", {Convert.ToString(cSkippedTV)} skipped";
1139 | if (cTVDupe > 0) dupeTV = $" (whereof {Convert.ToString(cTVDupe)} dupes)";
1140 | if (cTVPurge > 0) purgeTV = $", {Convert.ToString(cTVPurge)} purged";
1141 | if (cTV > 0) totalTV = $", {Convert.ToString(cTV)} in total";
1142 |
1143 | //write summary to console (and log if enabled)
1144 | outText = $"{DateTime.Now}: *** Movies summary: {newMovies}{updateMovies}{skipMovies}{dupeMovies}{purgeMovies}{totalMovies}";
1145 | Console.WriteLine(outText);
1146 | if (ProgramLogEnabled == true) programLog.WriteLine(outText);
1147 |
1148 | outText = $"{DateTime.Now}: *** Episodes summary: {newSeries}{updateSeries}{skipSeries}{dupeSeries}{purgeSeries}{totalSeries}";
1149 | Console.WriteLine(outText);
1150 | if (ProgramLogEnabled == true) programLog.WriteLine(outText);
1151 |
1152 | outText = $"{DateTime.Now}: *** TV-channels summary: {newTV}{updateTV}{skipTV}{dupeTV}{purgeTV}{totalTV}";
1153 | Console.WriteLine(outText);
1154 | if (ProgramLogEnabled == true) programLog.WriteLine(outText);
1155 | }
1156 | else
1157 | {
1158 | if (fileNotFound == true)
1159 | {
1160 | //we will end up here if the file given either as arg or in config was not found
1161 | Console.WriteLine($"File not found - {m3u8File}");
1162 |
1163 | //also check and tell if config or uwg was not found
1164 | if (!File.Exists(configFile))
1165 | Console.WriteLine("Configuration file not found.");
1166 | if (!File.Exists(uwgCfgFile))
1167 | Console.WriteLine("Unwanted groups file not found.");
1168 | Console.WriteLine("Type /? for help.");
1169 | }
1170 |
1171 | //if no arg for m3u8-file was given or not specified in conf
1172 | else Console.WriteLine("No file to process.\nType /? for help.");
1173 | return;
1174 | }
1175 |
1176 | //stop stopwatch, calculate and then print the result to both console and log
1177 | stopWatch.Stop();
1178 | TimeSpan ts = stopWatch.Elapsed;
1179 | string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
1180 | ts.Hours, ts.Minutes, ts.Seconds,
1181 | ts.Milliseconds / 10);
1182 | outText = $"{DateTime.Now}: *** Processing time: {elapsedTime}";
1183 | Console.WriteLine(outText);
1184 | if (ProgramLogEnabled == true) programLog.WriteLine(outText);
1185 |
1186 | if (ProgramLogEnabled == true)
1187 | {
1188 | //logging ends here
1189 | programLog.WriteLine($"{DateTime.Now}: *** Log end, {programFileName}, {version}");
1190 | programLog.Flush();
1191 | programLog.Close();
1192 | }
1193 | }
1194 |
1195 | //error codes
1196 | catch (Exception ex)
1197 | {
1198 | string ErrorLogFile = $"{AppDomain.CurrentDomain.BaseDirectory}error.log";
1199 | StreamWriter ErrorLog = File.AppendText(ErrorLogFile);
1200 | string outText = "";
1201 |
1202 | outText = $"{DateTime.Now}: ERROR: {ex.Message}";
1203 | Console.WriteLine(outText);
1204 | ErrorLog.WriteLine(outText);
1205 |
1206 | outText = $"{DateTime.Now}: ERROR: {ex.StackTrace}";
1207 | ErrorLog.WriteLine(outText);
1208 |
1209 | ErrorLog.Flush();
1210 | ErrorLog.Close();
1211 |
1212 | //outText = ("Press any key to quit...");
1213 | //Console.WriteLine(outText);
1214 | //Console.ReadLine();
1215 | }
1216 | }
1217 |
1218 | //removes illegal file name characters
1219 | public static string NAMEFilterFileNameChars(string fileName)
1220 | {
1221 | //decode html-encoded chars
1222 | fileName = WebUtility.HtmlDecode(fileName);
1223 |
1224 | //req by laurent734
1225 | fileName = Regex.Replace(fileName, @"^(\s|)\|(\s|)(AP|AR|DE|DUB|ES|FR|N|R21(\s2021|)|VM(-4K|)|SUB(AR|)|TR|TV|VO)(\s|)(\||)(\s|-|)", "", RegexOptions.IgnoreCase);
1226 | //VOST-FR,VOSTFR,| VOST,(VOST),VOSTF
1227 | fileName = Regex.Replace(fileName, @"(\||\(|)(\s|)VOST(-|\)|)(FR|F|)", "", RegexOptions.IgnoreCase);
1228 | //MULTI after )
1229 | fileName = Regex.Replace(fileName, @"(\))multi(\s|)$", "$1$2", RegexOptions.IgnoreCase);
1230 | //MULTI Before Sxx
1231 | fileName = Regex.Replace(fileName, @"(-|\((SD\s|)|)multi(\)|)\s", "", RegexOptions.IgnoreCase);
1232 | //MULTI,MULTI SUB,-MULTI,-MULTI SUB,.MULTI,(MULTI),Multi-Audio,Multi Audio
1233 | fileName = Regex.Replace(fileName, @"(\s\||-|)(\s|)(\(|-|\.|\s|)multi(\ssub|(-|)audio|)(\)|\s|)$", "", RegexOptions.IgnoreCase);
1234 | //_sub,sub_ar
1235 | fileName = Regex.Replace(fileName, @"_sub(_AR|)$", "", RegexOptions.IgnoreCase);
1236 | fileName = Regex.Replace(fileName, @"sub_AR$", "", RegexOptions.IgnoreCase);
1237 |
1238 | //remove VOD: from beginning of names (keeping IgnoreCase because Albania uses Vod: in filenames)
1239 | fileName = Regex.Replace(fileName, @"^VOD:\s", "", RegexOptions.IgnoreCase);
1240 | //replace O with 0 in eg SO1E01
1241 | fileName = Regex.Replace(fileName, @"\sSO(\d)", " S0$1", RegexOptions.IgnoreCase);
1242 | //replace erroneous ExxExx with SxxExx
1243 | fileName = Regex.Replace(fileName, @"E(\d+)E(\d+)", "S$1E$2", RegexOptions.IgnoreCase);
1244 | //replace erroneous SxxSxx with SxxExx
1245 | fileName = Regex.Replace(fileName, @"S(\d+)S(\d+)", "S$1E$2", RegexOptions.IgnoreCase);
1246 | //replace Sxx EPxx with SxxExx
1247 | fileName = Regex.Replace(fileName, @"\sS(\d+)\sEP(\d+)", " S$1E$2", RegexOptions.IgnoreCase);
1248 | //add missing space after comma
1249 | fileName = Regex.Replace(fileName, @",(\w)", ", $1");
1250 | //remove and replace chars -- this is done because GetInvalidFileNameChars behaves differently depending on OS
1251 | //here we do it on all OS to make the output more alike no matter OS
1252 | fileName = fileName
1253 | .Replace("/", "-")
1254 | .Replace("\\", "-")
1255 | .Replace("*", "-")
1256 | .Replace(":", "-")
1257 | .Replace("|", "-")
1258 | .Replace("\"", "-")
1259 | .Replace(";", "-")
1260 | .Replace("=", "-")
1261 | .Replace("–", "-")
1262 | .Replace("·", "-")
1263 | .Replace("{", "[")
1264 | .Replace("}", "]")
1265 | .Replace("’", "'")
1266 | .Replace("‘", "'")
1267 | .Replace("´", "'")
1268 | .Replace("`", "'")
1269 | .Replace("…", "...")
1270 | .Replace("“", "'")
1271 | .Replace("➔", "-")
1272 | .Replace("³", "3")
1273 | .Replace("²", "2")
1274 | .Replace("?", "").Trim()
1275 | .Replace("<", "").Trim()
1276 | .Replace(">", "").Trim()
1277 | .Replace(",", "").Trim()
1278 | .Replace("°", "").Trim();
1279 |
1280 | //normal filter, which behaves differently depending on OS
1281 | fileName = Path.GetInvalidFileNameChars().Aggregate(fileName, (current, c) => current.Replace(c.ToString(), "")).Trim();
1282 |
1283 | //add spaces between ) or ] and ( or [ (this is to conform)
1284 | fileName = Regex.Replace(fileName, @"(\)|\])(\(|\[)", "$1 $2");
1285 |
1286 | //correct year with more than 4 digits (example "Valley Girl [201920]" to "Valley Girl [2020]"
1287 | fileName = Regex.Replace(fileName, @"\[(\d{2})\d{2}(\d{2})]", "[$1$2]");
1288 |
1289 | //add missing end bracket (for example "The Hunt [2020" to "The Hunt [2020]")
1290 | fileName = Regex.Replace(fileName, @"\[(?!.*\])([\w]+)", "[$1]");
1291 |
1292 | //align misaligned bracket (example "The Last Scout ]2017]" to "The Last Scout [2017]")
1293 | fileName = Regex.Replace(fileName, @"\](\w+)]", "[$1]");
1294 |
1295 | //add missing bracket (for example "Spotlight [IMDB [2015]" to "Spotlight [IMDB] [2015]")
1296 | fileName = Regex.Replace(fileName, @"\[(\w+) (\[)", "[$1] $2");
1297 |
1298 | //remove all tags (only tags without numbers to keep years)
1299 | //fileName = Regex.Replace(fileName, @"\[\D+\]", "");
1300 |
1301 | //remove [PRE] and misspellings thereof (not needed when remove all tags used)
1302 | fileName = Regex.Replace(fileName, @"\[(P|R)(R|F)E\]", "", RegexOptions.IgnoreCase);
1303 |
1304 | //remove [Multi-Audio] (not needed when remove all tags used)
1305 | fileName = Regex.Replace(fileName, @"\[(Mu.*|Dual)(-|\s)Audio\]", "", RegexOptions.IgnoreCase);
1306 |
1307 | //remove [Multi-Subs] (not needed when remove all tags used)
1308 | fileName = Regex.Replace(fileName, @"\[Mu.*(-|\s)Sub(|s)\]", "", RegexOptions.IgnoreCase);
1309 |
1310 | //remove [Nordic] tag (keeping this because of some nordic without start bracket)
1311 | fileName = Regex.Replace(fileName, @"(\s|\[)nordic\]", "", RegexOptions.IgnoreCase);
1312 |
1313 | //remove [Only On 4K Devices] tag
1314 | fileName = Regex.Replace(fileName, @"\[Only (On|For) 4K Devices\]", "", RegexOptions.IgnoreCase);
1315 |
1316 | //replace [4K] tag
1317 | fileName = Regex.Replace(fileName, @"(\[4K\]|4K)", " [UHD]", RegexOptions.IgnoreCase);
1318 |
1319 | //remove 4K tag
1320 | //fileName = Regex.Replace(fileName, @"4K", "", RegexOptions.IgnoreCase);
1321 |
1322 | //remove stuff (not needed when remove all tags used)
1323 | fileName = Regex.Replace(fileName, @"\[K(|I)DS\]", "", RegexOptions.IgnoreCase);
1324 | fileName = Regex.Replace(fileName, @"\[SE\]", "", RegexOptions.IgnoreCase);
1325 | fileName = Regex.Replace(fileName, @"\[IMDB\]", "", RegexOptions.IgnoreCase);
1326 | fileName = Regex.Replace(fileName, @"\[IMDB\]", "", RegexOptions.IgnoreCase);
1327 | fileName = Regex.Replace(fileName, @"\[DOCU\]", "", RegexOptions.IgnoreCase);
1328 | fileName = Regex.Replace(fileName, @"\[PEE\]", "", RegexOptions.IgnoreCase);
1329 | fileName = Regex.Replace(fileName, @"\[DELETE\]", "", RegexOptions.IgnoreCase);
1330 |
1331 | //replace space between Sxx and Exx (escape \ by double \\) ($1 and $2 capture group 1 and 2)
1332 | fileName = Regex.Replace(fileName, @"(s\d+)\s(e\d+)", "$1$2", RegexOptions.IgnoreCase);
1333 |
1334 | //replace eg 1x01 with S01E01
1335 | fileName = Regex.Replace(fileName, @"(\d)x(\d+)", "S0$1E$2", RegexOptions.IgnoreCase);
1336 | fileName = Regex.Replace(fileName, @"(\d+)x(\d+)", "S$1E$2", RegexOptions.IgnoreCase);
1337 |
1338 | //remove dash before SxxExx
1339 | fileName = Regex.Replace(fileName, @"-\s(s\d+)(e\d+)", "$1$2", RegexOptions.IgnoreCase);
1340 |
1341 | //remove everything after SxxExx
1342 | fileName = Regex.Replace(fileName, @"(s\d+)(e\d+).*", "$1$2", RegexOptions.IgnoreCase).Trim('.', ' ');
1343 |
1344 | //remove double naming
1345 | fileName = Regex.Replace(fileName, @".*s(\d+)\s", "", RegexOptions.IgnoreCase).Trim('.', ' ');
1346 |
1347 | //remove erroneous spaces
1348 | fileName = fileName
1349 | .Replace("( ", "(")
1350 | .Replace(" )", ")")
1351 | .Replace("[ ", "[")
1352 | .Replace(" ]", "]");
1353 |
1354 | //replace "9 - 1 - 1", "9 - 11", "9- 11", "9 -11" with no space in between dash
1355 | fileName = Regex.Replace(fileName, @"(\d)(\s-|-\s|\s-\s)(\d)", "$1-$3");
1356 |
1357 | //add space before dash (-) only if space already after
1358 | fileName = Regex.Replace(fileName, @"(\w)-\s(\w)", "$1 - $2");
1359 |
1360 | //remove space before dash (-) only if no space after
1361 | fileName = Regex.Replace(fileName, @"(\w)\s-(\w)", "$1-$2");
1362 |
1363 | //replace more than one space with one space
1364 | fileName = Regex.Replace(fileName, @"\s{2,}", " ");
1365 |
1366 | //replace more than one dash with one dash
1367 | fileName = Regex.Replace(fileName, @"-{2,}", "-");
1368 |
1369 | //correct case of 4K tag
1370 | //fileName = Regex.Replace(fileName, @"(4k|\[4k\])", "[4K]", RegexOptions.IgnoreCase);
1371 | //fileName = Regex.Replace(fileName, @"4k", "4K", RegexOptions.IgnoreCase);
1372 |
1373 | //replace brackets with parentheses only on 4-digit year
1374 | fileName = Regex.Replace(fileName, @"\[(\d{4})\]", "($1)");
1375 |
1376 | //replace year and UHD tag with correct order; (year) [UHD]
1377 | fileName = Regex.Replace(fileName, @"(\[UHD\]) (\(\d{4}\))", "$2 $1");
1378 |
1379 | //problematic Swedish namings; Swedish movie and serie titles should not use upper case letters on each word in a title as in the English language,
1380 | //Windows would in some instances not be able to access duplicates through Samba on Linux if not corrected.
1381 | //This list needs to be constantly updated:
1382 | fileName = Regex.Replace(fileName, @"B.st i K.ket", "Bäst i köket", RegexOptions.IgnoreCase);
1383 | fileName = Regex.Replace(fileName, @"En bondg.rd mitt i stan", "En bondgård mitt i stan", RegexOptions.IgnoreCase);
1384 | fileName = Regex.Replace(fileName, @"Ensam i vildmarken", "Ensam i vildmarken", RegexOptions.IgnoreCase);
1385 | fileName = Regex.Replace(fileName, @"Insats torsk - sexhandeln inifrån", "Insats Torsk - Sexhandeln inifrån", RegexOptions.IgnoreCase);
1386 | fileName = Regex.Replace(fileName, @"Mästarnas M.stare", "Mästarnas mästare", RegexOptions.IgnoreCase);
1387 | fileName = Regex.Replace(fileName, @"Morden I Sandhamn", "Morden i Sandhamn", RegexOptions.IgnoreCase);
1388 | fileName = Regex.Replace(fileName, @"Sommaren med sl.kten", "Sommaren med släkten", RegexOptions.IgnoreCase);
1389 | fileName = Regex.Replace(fileName, @"Svenska Fall", "Svenska fall", RegexOptions.IgnoreCase);
1390 | fileName = Regex.Replace(fileName, @"Sveriges Yngsta M.sterkock", "Sveriges yngsta mästerkock", RegexOptions.IgnoreCase);
1391 | fileName = Regex.Replace(fileName, @"Udda Veckor", "Udda veckor", RegexOptions.IgnoreCase);
1392 | fileName = Regex.Replace(fileName, @"Wahlgrens v.rld", "Wahlgrens värld", RegexOptions.IgnoreCase);
1393 | fileName = Regex.Replace(fileName, @"Who Do You Think You Are. \(SE\)", "Vem tror du att du är", RegexOptions.IgnoreCase);
1394 |
1395 | //correct case The Of A An To On From if not preceeded by dash
1396 | fileName = Regex.Replace(fileName, @"(?", "").Trim()
1472 | .Replace(",", "").Trim()
1473 | .Replace("°", "").Trim();
1474 |
1475 | //normal filter, which behaves differently depending on OS
1476 | fileName = Path.GetInvalidFileNameChars().Aggregate(fileName, (current, c) => current.Replace(c.ToString(), "")).Trim();
1477 |
1478 | //remove [Multi-Sub/Audio]
1479 | fileName = Regex.Replace(fileName, @"\[Multi.*(-|\s)(Audio|Sub(|s))\]", "", RegexOptions.IgnoreCase);
1480 |
1481 | //replace 4K with UHD tag
1482 | //fileName = Regex.Replace(fileName, @"(4k|\[4k\])", "[4K]", RegexOptions.IgnoreCase);
1483 | fileName = Regex.Replace(fileName, @"4k", "UHD", RegexOptions.IgnoreCase);
1484 |
1485 | //remove [Only On 4K Devices] tag
1486 | fileName = Regex.Replace(fileName, @"\[Only (On|For) 4K Devices\]", "", RegexOptions.IgnoreCase);
1487 |
1488 | //replace more than one space with one space
1489 | fileName = Regex.Replace(fileName, @"\s{2,}", " ");
1490 |
1491 | //replace more than one dash with one dash
1492 | fileName = Regex.Replace(fileName, @"-{2,}", "-");
1493 |
1494 | //remove leading and trailing period and space
1495 | fileName = fileName.Trim('.', ' ');
1496 |
1497 | return fileName;
1498 | }
1499 | }
1500 | }
1501 |
--------------------------------------------------------------------------------