nwmetalinks 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nwmetalinks-1.0.0/PKG-INFO +142 -0
- nwmetalinks-1.0.0/README.md +125 -0
- nwmetalinks-1.0.0/nwmetalinks.egg-info/PKG-INFO +142 -0
- nwmetalinks-1.0.0/nwmetalinks.egg-info/SOURCES.txt +8 -0
- nwmetalinks-1.0.0/nwmetalinks.egg-info/dependency_links.txt +1 -0
- nwmetalinks-1.0.0/nwmetalinks.egg-info/top_level.txt +2 -0
- nwmetalinks-1.0.0/nwmetalinks.py +170 -0
- nwmetalinks-1.0.0/setup.cfg +4 -0
- nwmetalinks-1.0.0/setup.py +147 -0
- nwmetalinks-1.0.0/setupinfo.py +11 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nwmetalinks
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A library designed to generate MetaLink 4.0 XML files.
|
|
5
|
+
Home-page: https://github.com/numbworks/nwmetalinks
|
|
6
|
+
Author: numbworks
|
|
7
|
+
License: MIT
|
|
8
|
+
Requires-Python: >=3.12
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
Dynamic: author
|
|
11
|
+
Dynamic: description
|
|
12
|
+
Dynamic: description-content-type
|
|
13
|
+
Dynamic: home-page
|
|
14
|
+
Dynamic: license
|
|
15
|
+
Dynamic: requires-python
|
|
16
|
+
Dynamic: summary
|
|
17
|
+
|
|
18
|
+
# nwmetalinks
|
|
19
|
+
|
|
20
|
+
## Introduction
|
|
21
|
+
|
|
22
|
+
This packages consists of the following modules:
|
|
23
|
+
|
|
24
|
+
- `nwmetalinks` is a library that creates MetaLink v4 strings from user-provided URLs and their corresponding filenames.
|
|
25
|
+
|
|
26
|
+
## Getting Started
|
|
27
|
+
|
|
28
|
+
I'll use Debian as operating system, but the concept is similar for Windows or Mac.
|
|
29
|
+
|
|
30
|
+
Procedure:
|
|
31
|
+
|
|
32
|
+
1. Install `pip` and `venv`:
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
sudo apt install python3-pip python3.12-venv
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
2. Create a virtual environment:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
python3 -m venv /tmp/nwmetalinks
|
|
42
|
+
source /tmp/nwmetalinks/bin/activate
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
3. Download and install the package:
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
pip install nwmetalinks
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
4. Enter in the interactive Python environment:
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
python3
|
|
55
|
+
```
|
|
56
|
+
```
|
|
57
|
+
Python 3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0] on linux
|
|
58
|
+
Type "help", "copyright", "credits" or "license" for more information.
|
|
59
|
+
>>>
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
5. Try out if the library works:
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
from nwmetalinks import MetaLinkFactory
|
|
66
|
+
|
|
67
|
+
metalink_factory : MetaLinkFactory = MetaLinkFactory()
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
6. Exit from the interactive Python environment:
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
exit()
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
7. Deactivate and delete the virtual environment:
|
|
77
|
+
|
|
78
|
+
```sh
|
|
79
|
+
deactivate
|
|
80
|
+
rm -rf /tmp/nwmetalinks
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
8. Done!
|
|
84
|
+
|
|
85
|
+
## The Typical Use Case
|
|
86
|
+
|
|
87
|
+
In order to use the library, the first thing we need to do is to create a list of download URLs and a list containing their corresponding filenames, and then pass them to the `CreateMetaLink4` method of a `MetaLinkFactory` object, as shown in the following example:
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
from nwmetalinks import MetaLinkFactory
|
|
91
|
+
|
|
92
|
+
package_name : str = "nwmetalinks"
|
|
93
|
+
tuples : list[tuple[str, str]] = [
|
|
94
|
+
("https://numbworks.github.io/nwmetalinks.zip", "nwmetalinks.zip"),
|
|
95
|
+
("https://numbworks.github.io/nwmetalinks.tar.gz", "NW.nwmetalinks.tar.gz")
|
|
96
|
+
]
|
|
97
|
+
|
|
98
|
+
metalink : str = MetaLinkFactory().create_metalink4("nwmetalinks", tuples)
|
|
99
|
+
|
|
100
|
+
with open("nwmetalinks.metalink", "w", encoding="utf-8") as f:
|
|
101
|
+
f.write(metalink)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## MetaLink v4
|
|
105
|
+
|
|
106
|
+
Here is a minimal example of a MetaLink v4 file:
|
|
107
|
+
|
|
108
|
+
```xml
|
|
109
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
110
|
+
<metalink xmlns="urn:ietf:params:xml:ns:metalink" version="4.0">
|
|
111
|
+
<identity>My Package Name</identity>
|
|
112
|
+
|
|
113
|
+
<file name="example.bin">
|
|
114
|
+
<url>https://example.com/example.bin</url>
|
|
115
|
+
</file>
|
|
116
|
+
</metalink>
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Even if it's a XML file under the hood, a MetaLink file is expected to have the `.metalink` extension (instead of `.xml`).
|
|
120
|
+
|
|
121
|
+
## MetaLink v4 and JDownloader
|
|
122
|
+
|
|
123
|
+
JDownloader has full support for the MetaLink v4 format, but it's worth mentioning that by default, once the user imports a MetaLink file, JDownloader will ping all the files inside it, to check for their online status.
|
|
124
|
+
|
|
125
|
+
When importing a MetaLink file with hundreds or thousands of links inside, could flood the website and bring the provider to blacklist your IP address.
|
|
126
|
+
|
|
127
|
+
Before importing a MetaLink file, it could be a good practice to disable the `Do Link Check` feature:
|
|
128
|
+
|
|
129
|
+
1. Open JDownloader 2.
|
|
130
|
+
2. Go to `Settings` -> `Advanced Settings`.
|
|
131
|
+
3. Locate the setting: `LinkCollector: Do Link Check`
|
|
132
|
+
4. Untick (disable) this option.
|
|
133
|
+
4. Done!
|
|
134
|
+
|
|
135
|
+
## Links
|
|
136
|
+
|
|
137
|
+
- Source: https://github.com/numbworks/nwmetalinks
|
|
138
|
+
- License: https://github.com/numbworks/nwmetalinks/blob/master/LICENSE
|
|
139
|
+
|
|
140
|
+
## Total Downloads (PyPi)
|
|
141
|
+
|
|
142
|
+
[](https://pepy.tech/projects/nwmetalinks)
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# nwmetalinks
|
|
2
|
+
|
|
3
|
+
## Introduction
|
|
4
|
+
|
|
5
|
+
This packages consists of the following modules:
|
|
6
|
+
|
|
7
|
+
- `nwmetalinks` is a library that creates MetaLink v4 strings from user-provided URLs and their corresponding filenames.
|
|
8
|
+
|
|
9
|
+
## Getting Started
|
|
10
|
+
|
|
11
|
+
I'll use Debian as operating system, but the concept is similar for Windows or Mac.
|
|
12
|
+
|
|
13
|
+
Procedure:
|
|
14
|
+
|
|
15
|
+
1. Install `pip` and `venv`:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
sudo apt install python3-pip python3.12-venv
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
2. Create a virtual environment:
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
python3 -m venv /tmp/nwmetalinks
|
|
25
|
+
source /tmp/nwmetalinks/bin/activate
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
3. Download and install the package:
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
pip install nwmetalinks
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
4. Enter in the interactive Python environment:
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
python3
|
|
38
|
+
```
|
|
39
|
+
```
|
|
40
|
+
Python 3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0] on linux
|
|
41
|
+
Type "help", "copyright", "credits" or "license" for more information.
|
|
42
|
+
>>>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
5. Try out if the library works:
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from nwmetalinks import MetaLinkFactory
|
|
49
|
+
|
|
50
|
+
metalink_factory : MetaLinkFactory = MetaLinkFactory()
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
6. Exit from the interactive Python environment:
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
exit()
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
7. Deactivate and delete the virtual environment:
|
|
60
|
+
|
|
61
|
+
```sh
|
|
62
|
+
deactivate
|
|
63
|
+
rm -rf /tmp/nwmetalinks
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
8. Done!
|
|
67
|
+
|
|
68
|
+
## The Typical Use Case
|
|
69
|
+
|
|
70
|
+
In order to use the library, the first thing we need to do is to create a list of download URLs and a list containing their corresponding filenames, and then pass them to the `CreateMetaLink4` method of a `MetaLinkFactory` object, as shown in the following example:
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from nwmetalinks import MetaLinkFactory
|
|
74
|
+
|
|
75
|
+
package_name : str = "nwmetalinks"
|
|
76
|
+
tuples : list[tuple[str, str]] = [
|
|
77
|
+
("https://numbworks.github.io/nwmetalinks.zip", "nwmetalinks.zip"),
|
|
78
|
+
("https://numbworks.github.io/nwmetalinks.tar.gz", "NW.nwmetalinks.tar.gz")
|
|
79
|
+
]
|
|
80
|
+
|
|
81
|
+
metalink : str = MetaLinkFactory().create_metalink4("nwmetalinks", tuples)
|
|
82
|
+
|
|
83
|
+
with open("nwmetalinks.metalink", "w", encoding="utf-8") as f:
|
|
84
|
+
f.write(metalink)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## MetaLink v4
|
|
88
|
+
|
|
89
|
+
Here is a minimal example of a MetaLink v4 file:
|
|
90
|
+
|
|
91
|
+
```xml
|
|
92
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
93
|
+
<metalink xmlns="urn:ietf:params:xml:ns:metalink" version="4.0">
|
|
94
|
+
<identity>My Package Name</identity>
|
|
95
|
+
|
|
96
|
+
<file name="example.bin">
|
|
97
|
+
<url>https://example.com/example.bin</url>
|
|
98
|
+
</file>
|
|
99
|
+
</metalink>
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Even if it's a XML file under the hood, a MetaLink file is expected to have the `.metalink` extension (instead of `.xml`).
|
|
103
|
+
|
|
104
|
+
## MetaLink v4 and JDownloader
|
|
105
|
+
|
|
106
|
+
JDownloader has full support for the MetaLink v4 format, but it's worth mentioning that by default, once the user imports a MetaLink file, JDownloader will ping all the files inside it, to check for their online status.
|
|
107
|
+
|
|
108
|
+
When importing a MetaLink file with hundreds or thousands of links inside, could flood the website and bring the provider to blacklist your IP address.
|
|
109
|
+
|
|
110
|
+
Before importing a MetaLink file, it could be a good practice to disable the `Do Link Check` feature:
|
|
111
|
+
|
|
112
|
+
1. Open JDownloader 2.
|
|
113
|
+
2. Go to `Settings` -> `Advanced Settings`.
|
|
114
|
+
3. Locate the setting: `LinkCollector: Do Link Check`
|
|
115
|
+
4. Untick (disable) this option.
|
|
116
|
+
4. Done!
|
|
117
|
+
|
|
118
|
+
## Links
|
|
119
|
+
|
|
120
|
+
- Source: https://github.com/numbworks/nwmetalinks
|
|
121
|
+
- License: https://github.com/numbworks/nwmetalinks/blob/master/LICENSE
|
|
122
|
+
|
|
123
|
+
## Total Downloads (PyPi)
|
|
124
|
+
|
|
125
|
+
[](https://pepy.tech/projects/nwmetalinks)
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nwmetalinks
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A library designed to generate MetaLink 4.0 XML files.
|
|
5
|
+
Home-page: https://github.com/numbworks/nwmetalinks
|
|
6
|
+
Author: numbworks
|
|
7
|
+
License: MIT
|
|
8
|
+
Requires-Python: >=3.12
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
Dynamic: author
|
|
11
|
+
Dynamic: description
|
|
12
|
+
Dynamic: description-content-type
|
|
13
|
+
Dynamic: home-page
|
|
14
|
+
Dynamic: license
|
|
15
|
+
Dynamic: requires-python
|
|
16
|
+
Dynamic: summary
|
|
17
|
+
|
|
18
|
+
# nwmetalinks
|
|
19
|
+
|
|
20
|
+
## Introduction
|
|
21
|
+
|
|
22
|
+
This packages consists of the following modules:
|
|
23
|
+
|
|
24
|
+
- `nwmetalinks` is a library that creates MetaLink v4 strings from user-provided URLs and their corresponding filenames.
|
|
25
|
+
|
|
26
|
+
## Getting Started
|
|
27
|
+
|
|
28
|
+
I'll use Debian as operating system, but the concept is similar for Windows or Mac.
|
|
29
|
+
|
|
30
|
+
Procedure:
|
|
31
|
+
|
|
32
|
+
1. Install `pip` and `venv`:
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
sudo apt install python3-pip python3.12-venv
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
2. Create a virtual environment:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
python3 -m venv /tmp/nwmetalinks
|
|
42
|
+
source /tmp/nwmetalinks/bin/activate
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
3. Download and install the package:
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
pip install nwmetalinks
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
4. Enter in the interactive Python environment:
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
python3
|
|
55
|
+
```
|
|
56
|
+
```
|
|
57
|
+
Python 3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0] on linux
|
|
58
|
+
Type "help", "copyright", "credits" or "license" for more information.
|
|
59
|
+
>>>
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
5. Try out if the library works:
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
from nwmetalinks import MetaLinkFactory
|
|
66
|
+
|
|
67
|
+
metalink_factory : MetaLinkFactory = MetaLinkFactory()
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
6. Exit from the interactive Python environment:
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
exit()
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
7. Deactivate and delete the virtual environment:
|
|
77
|
+
|
|
78
|
+
```sh
|
|
79
|
+
deactivate
|
|
80
|
+
rm -rf /tmp/nwmetalinks
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
8. Done!
|
|
84
|
+
|
|
85
|
+
## The Typical Use Case
|
|
86
|
+
|
|
87
|
+
In order to use the library, the first thing we need to do is to create a list of download URLs and a list containing their corresponding filenames, and then pass them to the `CreateMetaLink4` method of a `MetaLinkFactory` object, as shown in the following example:
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
from nwmetalinks import MetaLinkFactory
|
|
91
|
+
|
|
92
|
+
package_name : str = "nwmetalinks"
|
|
93
|
+
tuples : list[tuple[str, str]] = [
|
|
94
|
+
("https://numbworks.github.io/nwmetalinks.zip", "nwmetalinks.zip"),
|
|
95
|
+
("https://numbworks.github.io/nwmetalinks.tar.gz", "NW.nwmetalinks.tar.gz")
|
|
96
|
+
]
|
|
97
|
+
|
|
98
|
+
metalink : str = MetaLinkFactory().create_metalink4("nwmetalinks", tuples)
|
|
99
|
+
|
|
100
|
+
with open("nwmetalinks.metalink", "w", encoding="utf-8") as f:
|
|
101
|
+
f.write(metalink)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## MetaLink v4
|
|
105
|
+
|
|
106
|
+
Here is a minimal example of a MetaLink v4 file:
|
|
107
|
+
|
|
108
|
+
```xml
|
|
109
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
110
|
+
<metalink xmlns="urn:ietf:params:xml:ns:metalink" version="4.0">
|
|
111
|
+
<identity>My Package Name</identity>
|
|
112
|
+
|
|
113
|
+
<file name="example.bin">
|
|
114
|
+
<url>https://example.com/example.bin</url>
|
|
115
|
+
</file>
|
|
116
|
+
</metalink>
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Even if it's a XML file under the hood, a MetaLink file is expected to have the `.metalink` extension (instead of `.xml`).
|
|
120
|
+
|
|
121
|
+
## MetaLink v4 and JDownloader
|
|
122
|
+
|
|
123
|
+
JDownloader has full support for the MetaLink v4 format, but it's worth mentioning that by default, once the user imports a MetaLink file, JDownloader will ping all the files inside it, to check for their online status.
|
|
124
|
+
|
|
125
|
+
When importing a MetaLink file with hundreds or thousands of links inside, could flood the website and bring the provider to blacklist your IP address.
|
|
126
|
+
|
|
127
|
+
Before importing a MetaLink file, it could be a good practice to disable the `Do Link Check` feature:
|
|
128
|
+
|
|
129
|
+
1. Open JDownloader 2.
|
|
130
|
+
2. Go to `Settings` -> `Advanced Settings`.
|
|
131
|
+
3. Locate the setting: `LinkCollector: Do Link Check`
|
|
132
|
+
4. Untick (disable) this option.
|
|
133
|
+
4. Done!
|
|
134
|
+
|
|
135
|
+
## Links
|
|
136
|
+
|
|
137
|
+
- Source: https://github.com/numbworks/nwmetalinks
|
|
138
|
+
- License: https://github.com/numbworks/nwmetalinks/blob/master/LICENSE
|
|
139
|
+
|
|
140
|
+
## Total Downloads (PyPi)
|
|
141
|
+
|
|
142
|
+
[](https://pepy.tech/projects/nwmetalinks)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
'''
|
|
2
|
+
A library designed to generate MetaLink 4.0 XML files.
|
|
3
|
+
|
|
4
|
+
Alias: nwml
|
|
5
|
+
'''
|
|
6
|
+
|
|
7
|
+
# GLOBAL MODULES
|
|
8
|
+
import xml.etree.ElementTree as ET
|
|
9
|
+
from xml.dom import minidom
|
|
10
|
+
from xml.dom.minidom import Document
|
|
11
|
+
from xml.etree.ElementTree import Element, SubElement
|
|
12
|
+
from typing import Optional
|
|
13
|
+
|
|
14
|
+
# LOCAL MODULES
|
|
15
|
+
# CONSTANTS
|
|
16
|
+
# STATIC CLASSES
|
|
17
|
+
class _MessageCollectionValidator():
|
|
18
|
+
|
|
19
|
+
'''Collects all the messages used for logging and for the exceptions used by Validator.'''
|
|
20
|
+
|
|
21
|
+
@staticmethod
|
|
22
|
+
def provided_package_name_null_or_empty(package_name_name : str = "package_name") -> str:
|
|
23
|
+
return f"'{package_name_name}' cannot be None, empty, or whitespace."
|
|
24
|
+
|
|
25
|
+
@staticmethod
|
|
26
|
+
def provided_instance_null(instance_name : str) -> str:
|
|
27
|
+
return f"'{instance_name}' cannot be None."
|
|
28
|
+
|
|
29
|
+
@staticmethod
|
|
30
|
+
def provided_list_contains_null(lst_name : str) -> str:
|
|
31
|
+
return f"'{lst_name}' contains one or more null entries."
|
|
32
|
+
|
|
33
|
+
@staticmethod
|
|
34
|
+
def list_counts_do_not_match(urls_name : str = "urls", file_names_name : str = "file_names") -> str:
|
|
35
|
+
return f"'{urls_name}' and '{file_names_name}' must have the same number of items."
|
|
36
|
+
|
|
37
|
+
@staticmethod
|
|
38
|
+
def provided_file_entry_null_url(file_entry : tuple) -> str:
|
|
39
|
+
return f"The provided file entries has a null or empty url ('{file_entry}')."
|
|
40
|
+
|
|
41
|
+
@staticmethod
|
|
42
|
+
def provided_file_entry_null_filename(file_entry : tuple) -> str:
|
|
43
|
+
return f"The provided file entries has a null or empty fileName ('{file_entry}')."
|
|
44
|
+
class _MessageCollection(
|
|
45
|
+
_MessageCollectionValidator):
|
|
46
|
+
|
|
47
|
+
'''Collects all the messages used for logging and for the exceptions.'''
|
|
48
|
+
class Validator():
|
|
49
|
+
|
|
50
|
+
'''Collects all validation methods.'''
|
|
51
|
+
|
|
52
|
+
@staticmethod
|
|
53
|
+
def validate_string(str_val : Optional[str], str_name : str = "str") -> None:
|
|
54
|
+
|
|
55
|
+
'''Validates that the provided string is not None, empty, or whitespace.'''
|
|
56
|
+
|
|
57
|
+
if str_val is None or not str(str_val).strip():
|
|
58
|
+
raise ValueError(_MessageCollection.provided_package_name_null_or_empty(str_name))
|
|
59
|
+
|
|
60
|
+
@staticmethod
|
|
61
|
+
def validate_instance(instance : object, instance_name : str = "instance") -> None:
|
|
62
|
+
|
|
63
|
+
'''Validates that the provided instance is not None.'''
|
|
64
|
+
|
|
65
|
+
if instance is None:
|
|
66
|
+
raise ValueError(_MessageCollection.provided_instance_null(instance_name))
|
|
67
|
+
|
|
68
|
+
@staticmethod
|
|
69
|
+
def validate_list(lst : list, lst_name : str = "lst") -> None:
|
|
70
|
+
|
|
71
|
+
'''Validates the provided list and its entries.'''
|
|
72
|
+
|
|
73
|
+
Validator.validate_instance(instance = lst, instance_name = lst_name)
|
|
74
|
+
|
|
75
|
+
if any(x is None for x in lst):
|
|
76
|
+
raise ValueError(_MessageCollection.provided_list_contains_null(lst_name))
|
|
77
|
+
|
|
78
|
+
@staticmethod
|
|
79
|
+
def validate_urls_and_filenames(urls : list[str], file_names : list[str]) -> None:
|
|
80
|
+
|
|
81
|
+
'''Validates the provided urls and their corresponding file_names.'''
|
|
82
|
+
|
|
83
|
+
Validator.validate_list(lst = urls, lst_name = "urls")
|
|
84
|
+
Validator.validate_list(lst = file_names, lst_name = "file_names")
|
|
85
|
+
|
|
86
|
+
if len(urls) != len(file_names):
|
|
87
|
+
raise ValueError(_MessageCollection.list_counts_do_not_match(urls_name = "urls", file_names_name = "file_names"))
|
|
88
|
+
|
|
89
|
+
@staticmethod
|
|
90
|
+
def validate_tuple(tpl : tuple[str, str]) -> None:
|
|
91
|
+
|
|
92
|
+
'''Validates the URL and filename of the provided tuple.'''
|
|
93
|
+
|
|
94
|
+
url, file_name = tpl
|
|
95
|
+
|
|
96
|
+
if url is None or not str(url).strip():
|
|
97
|
+
raise Exception(_MessageCollection.provided_file_entry_null_url(tpl))
|
|
98
|
+
|
|
99
|
+
if file_name is None or not str(file_name).strip():
|
|
100
|
+
raise Exception(_MessageCollection.provided_file_entry_null_filename(tpl))
|
|
101
|
+
|
|
102
|
+
@staticmethod
|
|
103
|
+
def validate_tuples(tuples : list[tuple[str, str]]) -> None:
|
|
104
|
+
|
|
105
|
+
'''Validates the provided tuples and their entries.'''
|
|
106
|
+
|
|
107
|
+
Validator.validate_instance(instance = tuples, instance_name = "tuples")
|
|
108
|
+
|
|
109
|
+
if any(x is None for x in tuples):
|
|
110
|
+
raise ValueError(_MessageCollection.provided_list_contains_null("tuples"))
|
|
111
|
+
|
|
112
|
+
for tpl in tuples:
|
|
113
|
+
Validator.validate_tuple(tpl = tpl)
|
|
114
|
+
|
|
115
|
+
# CLASSES
|
|
116
|
+
class MetaLinkFactory():
|
|
117
|
+
|
|
118
|
+
'''Collects all the logic related to MetaLink XML generation.'''
|
|
119
|
+
|
|
120
|
+
def __map(self, urls : list[str], file_names : list[str]) -> list[tuple[str, str]]:
|
|
121
|
+
|
|
122
|
+
'''Maps lists of URLs and filenames into a list of tuples.'''
|
|
123
|
+
|
|
124
|
+
tuples : list[tuple[str, str]] = []
|
|
125
|
+
|
|
126
|
+
for i in range(len(urls)):
|
|
127
|
+
tuples.append((urls[i], file_names[i]))
|
|
128
|
+
|
|
129
|
+
return tuples
|
|
130
|
+
|
|
131
|
+
def create_metalink4_from_lists(self, package_name : str, urls : list[str], file_names : list[str]) -> str:
|
|
132
|
+
|
|
133
|
+
'''Creates MetaLink 4.0 XML content from separate url and filename lists.'''
|
|
134
|
+
|
|
135
|
+
Validator.validate_string(str_val = package_name, str_name = "package_name")
|
|
136
|
+
Validator.validate_urls_and_filenames(urls = urls, file_names = file_names)
|
|
137
|
+
|
|
138
|
+
tuples : list[tuple[str, str]] = self.__map(urls = urls, file_names = file_names)
|
|
139
|
+
xml_content : str = self.create_metalink4(package_name = package_name, tuples = tuples)
|
|
140
|
+
|
|
141
|
+
return xml_content
|
|
142
|
+
def create_metalink4(self, package_name : str, tuples : list[tuple[str, str]]) -> str:
|
|
143
|
+
|
|
144
|
+
'''Creates MetaLink 4.0 XML content from a list of (url, file_name) tuples.'''
|
|
145
|
+
|
|
146
|
+
Validator.validate_string(str_val = package_name, str_name = "package_name")
|
|
147
|
+
Validator.validate_tuples(tuples = tuples)
|
|
148
|
+
|
|
149
|
+
xml_namespace : str = "urn:ietf:params:xml:ns:metalink"
|
|
150
|
+
ET.register_namespace("", xml_namespace)
|
|
151
|
+
|
|
152
|
+
element_metalink : Element = Element(f"{{{xml_namespace}}}metalink", attrib = {"version": "4.0"})
|
|
153
|
+
|
|
154
|
+
element_identity : Element = SubElement(element_metalink, f"{{{xml_namespace}}}identity")
|
|
155
|
+
element_identity.text = package_name
|
|
156
|
+
|
|
157
|
+
for url, file_name in tuples:
|
|
158
|
+
element_file : Element = SubElement(element_metalink, f"{{{xml_namespace}}}file", attrib = {"name": file_name})
|
|
159
|
+
element_url : Element = SubElement(element_file, f"{{{xml_namespace}}}url")
|
|
160
|
+
element_url.text = url
|
|
161
|
+
|
|
162
|
+
xml_raw : bytes = ET.tostring(element_metalink, encoding = "utf-8")
|
|
163
|
+
xml_parsed : Document = minidom.parseString(xml_raw)
|
|
164
|
+
xml_pretty : str = xml_parsed.toprettyxml(indent = " ", encoding = "utf-8").decode("utf-8")
|
|
165
|
+
|
|
166
|
+
return xml_pretty
|
|
167
|
+
|
|
168
|
+
# MAIN
|
|
169
|
+
if __name__ == "__main__":
|
|
170
|
+
pass
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
'''Contains packaging instructions.'''
|
|
2
|
+
|
|
3
|
+
# GLOBAL MODULES
|
|
4
|
+
from setupinfo import PROJECT_VERSION, PROJECT_AUTHOR, PROJECT_URL, LIBRARY_NAME, LIBRARY_DESCRIPTION
|
|
5
|
+
from setuptools import setup
|
|
6
|
+
|
|
7
|
+
# SETUP
|
|
8
|
+
if __name__ == "__main__":
|
|
9
|
+
setup(
|
|
10
|
+
name = LIBRARY_NAME,
|
|
11
|
+
version = PROJECT_VERSION,
|
|
12
|
+
description = LIBRARY_DESCRIPTION,
|
|
13
|
+
author = PROJECT_AUTHOR,
|
|
14
|
+
url = PROJECT_URL,
|
|
15
|
+
py_modules = [ LIBRARY_NAME, "setupinfo" ],
|
|
16
|
+
install_requires = [ ],
|
|
17
|
+
python_requires = ">=3.12",
|
|
18
|
+
license = "MIT",
|
|
19
|
+
entry_points = { }
|
|
20
|
+
,
|
|
21
|
+
long_description="""# nwmetalinks
|
|
22
|
+
|
|
23
|
+
## Introduction
|
|
24
|
+
|
|
25
|
+
This packages consists of the following modules:
|
|
26
|
+
|
|
27
|
+
- `nwmetalinks` is a library that creates MetaLink v4 strings from user-provided URLs and their corresponding filenames.
|
|
28
|
+
|
|
29
|
+
## Getting Started
|
|
30
|
+
|
|
31
|
+
I'll use Debian as operating system, but the concept is similar for Windows or Mac.
|
|
32
|
+
|
|
33
|
+
Procedure:
|
|
34
|
+
|
|
35
|
+
1. Install `pip` and `venv`:
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
sudo apt install python3-pip python3.12-venv
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
2. Create a virtual environment:
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
python3 -m venv /tmp/nwmetalinks
|
|
45
|
+
source /tmp/nwmetalinks/bin/activate
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
3. Download and install the package:
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
pip install nwmetalinks
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
4. Enter in the interactive Python environment:
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
python3
|
|
58
|
+
```
|
|
59
|
+
```
|
|
60
|
+
Python 3.12.3 (main, Aug 31 2026, 10:18:26) [GCC 13.3.0] on linux
|
|
61
|
+
Type "help", "copyright", "credits" or "license" for more information.
|
|
62
|
+
>>>
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
5. Try out if the library works:
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from nwmetalinks import MetaLinkFactory
|
|
69
|
+
|
|
70
|
+
metalink_factory : MetaLinkFactory = MetaLinkFactory()
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
6. Exit from the interactive Python environment:
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
exit()
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
7. Deactivate and delete the virtual environment:
|
|
80
|
+
|
|
81
|
+
```sh
|
|
82
|
+
deactivate
|
|
83
|
+
rm -rf /tmp/nwmetalinks
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
8. Done!
|
|
87
|
+
|
|
88
|
+
## The Typical Use Case
|
|
89
|
+
|
|
90
|
+
In order to use the library, the first thing we need to do is to create a list of download URLs and a list containing their corresponding filenames, and then pass them to the `CreateMetaLink4` method of a `MetaLinkFactory` object, as shown in the following example:
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
from nwmetalinks import MetaLinkFactory
|
|
94
|
+
|
|
95
|
+
package_name : str = "nwmetalinks"
|
|
96
|
+
tuples : list[tuple[str, str]] = [
|
|
97
|
+
("https://numbworks.github.io/nwmetalinks.zip", "nwmetalinks.zip"),
|
|
98
|
+
("https://numbworks.github.io/nwmetalinks.tar.gz", "NW.nwmetalinks.tar.gz")
|
|
99
|
+
]
|
|
100
|
+
|
|
101
|
+
metalink : str = MetaLinkFactory().create_metalink4("nwmetalinks", tuples)
|
|
102
|
+
|
|
103
|
+
with open("nwmetalinks.metalink", "w", encoding="utf-8") as f:
|
|
104
|
+
f.write(metalink)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## MetaLink v4
|
|
108
|
+
|
|
109
|
+
Here is a minimal example of a MetaLink v4 file:
|
|
110
|
+
|
|
111
|
+
```xml
|
|
112
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
113
|
+
<metalink xmlns="urn:ietf:params:xml:ns:metalink" version="4.0">
|
|
114
|
+
<identity>My Package Name</identity>
|
|
115
|
+
|
|
116
|
+
<file name="example.bin">
|
|
117
|
+
<url>https://example.com/example.bin</url>
|
|
118
|
+
</file>
|
|
119
|
+
</metalink>
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Even if it's a XML file under the hood, a MetaLink file is expected to have the `.metalink` extension (instead of `.xml`).
|
|
123
|
+
|
|
124
|
+
## MetaLink v4 and JDownloader
|
|
125
|
+
|
|
126
|
+
JDownloader has full support for the MetaLink v4 format, but it's worth mentioning that by default, once the user imports a MetaLink file, JDownloader will ping all the files inside it, to check for their online status.
|
|
127
|
+
|
|
128
|
+
When importing a MetaLink file with hundreds or thousands of links inside, could flood the website and bring the provider to blacklist your IP address.
|
|
129
|
+
|
|
130
|
+
Before importing a MetaLink file, it could be a good practice to disable the `Do Link Check` feature:
|
|
131
|
+
|
|
132
|
+
1. Open JDownloader 2.
|
|
133
|
+
2. Go to `Settings` -> `Advanced Settings`.
|
|
134
|
+
3. Locate the setting: `LinkCollector: Do Link Check`
|
|
135
|
+
4. Untick (disable) this option.
|
|
136
|
+
4. Done!
|
|
137
|
+
|
|
138
|
+
## Links
|
|
139
|
+
|
|
140
|
+
- Source: https://github.com/numbworks/nwmetalinks
|
|
141
|
+
- License: https://github.com/numbworks/nwmetalinks/blob/master/LICENSE
|
|
142
|
+
|
|
143
|
+
## Total Downloads (PyPi)
|
|
144
|
+
|
|
145
|
+
[](https://pepy.tech/projects/nwmetalinks)""",
|
|
146
|
+
long_description_content_type="text/markdown"
|
|
147
|
+
)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'''Contains project information.'''
|
|
2
|
+
|
|
3
|
+
# INFORMATION
|
|
4
|
+
PROJECT_VERSION : str = "1.0.0"
|
|
5
|
+
PROJECT_AUTHOR : str = "numbworks"
|
|
6
|
+
PROJECT_ALIAS : str = "nwml"
|
|
7
|
+
|
|
8
|
+
LIBRARY_NAME : str = "nwmetalinks"
|
|
9
|
+
LIBRARY_DESCRIPTION : str = "A library designed to generate MetaLink 4.0 XML files."
|
|
10
|
+
|
|
11
|
+
PROJECT_URL : str = f"https://github.com/{PROJECT_AUTHOR}/{LIBRARY_NAME}"
|