pydez 0.1.0__py3-none-any.whl
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.
- pydez/__init__.py +80 -0
- pydez/analyses.py +93 -0
- pydez/pieces.py +159 -0
- pydez/sources.py +171 -0
- pydez-0.1.0.dist-info/METADATA +98 -0
- pydez-0.1.0.dist-info/RECORD +9 -0
- pydez-0.1.0.dist-info/WHEEL +5 -0
- pydez-0.1.0.dist-info/licenses/LICENSE +165 -0
- pydez-0.1.0.dist-info/top_level.txt +1 -0
pydez/__init__.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""pydez: Python Library for Dezrann Formats
|
|
2
|
+
|
|
3
|
+
A simple, spec-compliant library for working with Dezrann file formats:
|
|
4
|
+
- .dez files (Analysis and Label data)
|
|
5
|
+
- .json files (Piece, Source, and Metadata)
|
|
6
|
+
|
|
7
|
+
Core classes:
|
|
8
|
+
- Label: Individual annotation with start, duration, tag, type, comment, etc.
|
|
9
|
+
- Analysis: Collection of Labels with metadata
|
|
10
|
+
- Piece: Musical piece with opus metadata and sources
|
|
11
|
+
|
|
12
|
+
Source subclasses:
|
|
13
|
+
- ScoreSource, ScoreNeumaSource, ScoreGallicaSource
|
|
14
|
+
- TabSource
|
|
15
|
+
- VideoSource, VideoYouTubeSource
|
|
16
|
+
- AudioSource, AudioYouTubeSource
|
|
17
|
+
- ImagesSource
|
|
18
|
+
- AnalysisSource, SelectionSource
|
|
19
|
+
- LyricsSource
|
|
20
|
+
- MidiSource
|
|
21
|
+
- GenericSource
|
|
22
|
+
|
|
23
|
+
All classes support:
|
|
24
|
+
- dump() -> Convert to dict
|
|
25
|
+
- load()/save() (file I/O via JSON)
|
|
26
|
+
- build() (from dict with error handling)
|
|
27
|
+
- += operator for combining instances
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
from .analyses import Label, Analysis
|
|
31
|
+
from .pieces import Piece, Corpus
|
|
32
|
+
from .sources import (
|
|
33
|
+
Source,
|
|
34
|
+
ScoreSource, ScoreNeumaSource, ScoreGallicaSource,
|
|
35
|
+
TabSource,
|
|
36
|
+
VideoSource, VideoYouTubeSource,
|
|
37
|
+
AudioSource, AudioYouTubeSource,
|
|
38
|
+
ImagesSource,
|
|
39
|
+
AnalysisSource, SelectionSource,
|
|
40
|
+
LyricsSource,
|
|
41
|
+
MidiSource,
|
|
42
|
+
GenericSource
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
__all__ = [
|
|
46
|
+
# Analysis classes
|
|
47
|
+
'Label',
|
|
48
|
+
'Analysis',
|
|
49
|
+
# Corpus and Piece class
|
|
50
|
+
'Corpus',
|
|
51
|
+
'Piece',
|
|
52
|
+
# Base Source class
|
|
53
|
+
'Source',
|
|
54
|
+
# Score sources
|
|
55
|
+
'ScoreSource',
|
|
56
|
+
'ScoreNeumaSource',
|
|
57
|
+
'ScoreGallicaSource',
|
|
58
|
+
#
|
|
59
|
+
'TabSource',
|
|
60
|
+
# YouTube sources
|
|
61
|
+
'YouTubeSource',
|
|
62
|
+
'VideoYouTubeSource',
|
|
63
|
+
'AudioYouTubeSource',
|
|
64
|
+
# Video and Audio sources
|
|
65
|
+
'VideoSource',
|
|
66
|
+
'AudioSource',
|
|
67
|
+
# Images source
|
|
68
|
+
'ImagesSource',
|
|
69
|
+
# Analysis sources
|
|
70
|
+
'AnalysisSource',
|
|
71
|
+
'SelectionSource',
|
|
72
|
+
# Lyrics source
|
|
73
|
+
'LyricsSource',
|
|
74
|
+
# MIDI source
|
|
75
|
+
'MidiSource',
|
|
76
|
+
# Generic fallback
|
|
77
|
+
'GenericSource'
|
|
78
|
+
]
|
|
79
|
+
|
|
80
|
+
__version__ = '0.1.0'
|
pydez/analyses.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import warnings
|
|
3
|
+
from typing import Any, Dict, List, Union
|
|
4
|
+
|
|
5
|
+
class Label:
|
|
6
|
+
def __init__(self, start: float, duration: float = None, tag: str = None,
|
|
7
|
+
type: str = None, comment: str = None, **kwargs):
|
|
8
|
+
self.d = {
|
|
9
|
+
'start': start,
|
|
10
|
+
'duration': duration,
|
|
11
|
+
'tag': tag,
|
|
12
|
+
'type': type,
|
|
13
|
+
'comment': comment
|
|
14
|
+
}
|
|
15
|
+
self.d.update(kwargs)
|
|
16
|
+
|
|
17
|
+
def __getattr__(self, name: str) -> Any:
|
|
18
|
+
return self.d[name]
|
|
19
|
+
|
|
20
|
+
def __setattr__(self, name: str, value: Any) -> None:
|
|
21
|
+
if name == 'd':
|
|
22
|
+
super().__setattr__(name, value)
|
|
23
|
+
else:
|
|
24
|
+
self.d[name] = value
|
|
25
|
+
|
|
26
|
+
def dump(self) -> Dict[str, Any]:
|
|
27
|
+
return self.d.copy()
|
|
28
|
+
|
|
29
|
+
@classmethod
|
|
30
|
+
def load(cls, filepath: str) -> 'Label':
|
|
31
|
+
with open(filepath, 'r') as f:
|
|
32
|
+
print(f" <== {filepath}")
|
|
33
|
+
json_data = json.load(f)
|
|
34
|
+
return cls(**json_data)
|
|
35
|
+
|
|
36
|
+
def save(self, filepath: str) -> None:
|
|
37
|
+
with open(filepath, 'w') as f:
|
|
38
|
+
print(f" ==> {filepath}")
|
|
39
|
+
json.dump(self.dump(), f, indent=2)
|
|
40
|
+
|
|
41
|
+
class Analysis:
|
|
42
|
+
def __init__(self, labels: List[Label] = None, **kwargs):
|
|
43
|
+
self.d = {
|
|
44
|
+
'labels': labels if labels is not None else []
|
|
45
|
+
}
|
|
46
|
+
self.d.update(kwargs)
|
|
47
|
+
|
|
48
|
+
def __iter__(self):
|
|
49
|
+
return self.d['labels'].__iter__()
|
|
50
|
+
|
|
51
|
+
def __len__(self):
|
|
52
|
+
return len(self.d)
|
|
53
|
+
|
|
54
|
+
def __iadd__(self, other: Union['Analysis', Label]) -> 'Analysis':
|
|
55
|
+
if isinstance(other, Analysis):
|
|
56
|
+
self.d['labels'].extend(other.d['labels'])
|
|
57
|
+
elif isinstance(other, Label):
|
|
58
|
+
self.d['labels'].append(other)
|
|
59
|
+
else:
|
|
60
|
+
raise TypeError("Can only add Analysis or Label to Analysis")
|
|
61
|
+
return self
|
|
62
|
+
|
|
63
|
+
def dump(self) -> Dict[str, Any]:
|
|
64
|
+
return {
|
|
65
|
+
'labels': [label.dump() for label in self.d['labels']],
|
|
66
|
+
**{k: v for k, v in self.d.items() if k != 'labels'}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@classmethod
|
|
70
|
+
def build(cls, json_data: Dict[str, Any]) -> 'Analysis':
|
|
71
|
+
labels = []
|
|
72
|
+
for label_data in json_data.get('labels', []):
|
|
73
|
+
try:
|
|
74
|
+
labels.append(Label(**label_data))
|
|
75
|
+
except Exception as e:
|
|
76
|
+
warnings.warn(f"Failed to load label: {e}")
|
|
77
|
+
other_attrs = {k: v for k, v in json_data.items() if k != 'labels'}
|
|
78
|
+
return cls(labels=labels, **other_attrs)
|
|
79
|
+
|
|
80
|
+
@classmethod
|
|
81
|
+
def load(cls, filepath: str) -> 'Analysis':
|
|
82
|
+
with open(filepath, 'r') as f:
|
|
83
|
+
print(f" <== {filepath}")
|
|
84
|
+
json_data = json.load(f)
|
|
85
|
+
return cls.build(json_data)
|
|
86
|
+
|
|
87
|
+
def save(self, filepath: str) -> None:
|
|
88
|
+
with open(filepath, 'w') as f:
|
|
89
|
+
print(f" ==> {filepath}")
|
|
90
|
+
json.dump(self.dump(), f, indent=2)
|
|
91
|
+
|
|
92
|
+
def __str__(self):
|
|
93
|
+
return f"Analysis ({len(self)} labels)"
|
pydez/pieces.py
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
|
|
2
|
+
import json
|
|
3
|
+
import warnings
|
|
4
|
+
import os
|
|
5
|
+
from typing import Any, Dict, List, Optional, Union
|
|
6
|
+
from .sources import Source
|
|
7
|
+
|
|
8
|
+
API_CORPUS = "curl -sS --request POST --url https://test-ws.dezrann.net/corpus --header 'Content-Type: multipart/form-data' --form metadata=@%s"
|
|
9
|
+
|
|
10
|
+
class Piece:
|
|
11
|
+
"""Represents a piece with opus metadata and sources"""
|
|
12
|
+
|
|
13
|
+
def __init__(self, opus: Optional[Dict[str, Any]] = None,
|
|
14
|
+
sources: Optional[List[Source]] = None,
|
|
15
|
+
settings: Optional[Dict[str, Any]] = None,
|
|
16
|
+
**kwargs):
|
|
17
|
+
self.d = {
|
|
18
|
+
'opus': opus if opus is not None else {},
|
|
19
|
+
'sources': sources if sources is not None else []
|
|
20
|
+
}
|
|
21
|
+
if settings is not None:
|
|
22
|
+
self.d['settings'] = settings
|
|
23
|
+
self.d.update(kwargs)
|
|
24
|
+
|
|
25
|
+
def __getitem__(self, source_id: str) -> Source:
|
|
26
|
+
"""Get source by ID. Raises KeyError if not found."""
|
|
27
|
+
for source in self.d['sources']:
|
|
28
|
+
if source.d.get('id') == source_id:
|
|
29
|
+
return source
|
|
30
|
+
raise KeyError(f"Source with id '{source_id}' not found")
|
|
31
|
+
|
|
32
|
+
def get_query(self) -> (List[Source], Dict[str, Any]):
|
|
33
|
+
"""Resolve ref-source IDs, fetch, and parse each source."""
|
|
34
|
+
print(self.d)
|
|
35
|
+
try:
|
|
36
|
+
refs_source = self.d['query']['ref-source']
|
|
37
|
+
except:
|
|
38
|
+
raise ValueError('Query not present')
|
|
39
|
+
|
|
40
|
+
resolved = []
|
|
41
|
+
for source_id in refs_source:
|
|
42
|
+
source = self[source_id] # Raises KeyError if not found
|
|
43
|
+
print(f' <== {str(source)}: {source_id}')
|
|
44
|
+
if source.fetch():
|
|
45
|
+
try:
|
|
46
|
+
source.parse()
|
|
47
|
+
except NotImplementedError:
|
|
48
|
+
pass
|
|
49
|
+
resolved.append(source)
|
|
50
|
+
return resolved, self.d['query']
|
|
51
|
+
|
|
52
|
+
def __str__(self) -> str:
|
|
53
|
+
"""Return a string representation like 'Piece 'id': 3 sources: Audio, Score, Tab'
|
|
54
|
+
"""
|
|
55
|
+
piece_id = self.d.get('opus', {}).get('id', 'unknown')
|
|
56
|
+
source_types = [str(source) for source in self.d.get('sources', [])]
|
|
57
|
+
sources_str = ', '.join(source_types) if source_types else 'no sources'
|
|
58
|
+
num_sources = len(source_types)
|
|
59
|
+
return f"Piece '{piece_id}': {num_sources} source{'s' if num_sources != 1 else ''}: {sources_str}"
|
|
60
|
+
|
|
61
|
+
def dump(self) -> Dict[str, Any]:
|
|
62
|
+
result = {
|
|
63
|
+
'opus': self.d.get('opus', {}).copy(),
|
|
64
|
+
'sources': [source.dump() for source in self.d.get('sources', [])]
|
|
65
|
+
}
|
|
66
|
+
if 'settings' in self.d:
|
|
67
|
+
result['settings'] = self.d['settings'].copy()
|
|
68
|
+
result.update({k: v for k, v in self.d.items()
|
|
69
|
+
if k not in ('opus', 'sources', 'settings')})
|
|
70
|
+
return result
|
|
71
|
+
|
|
72
|
+
@classmethod
|
|
73
|
+
def build(cls, json_data: Dict[str, Any]) -> 'Piece':
|
|
74
|
+
sources = []
|
|
75
|
+
for source_data in json_data.get('sources', []):
|
|
76
|
+
try:
|
|
77
|
+
sources.append(Source.build(source_data))
|
|
78
|
+
except Exception as e:
|
|
79
|
+
warnings.warn(f"Failed to load source: {e}")
|
|
80
|
+
opus = json_data.get('opus', {})
|
|
81
|
+
settings = json_data.get('settings', None)
|
|
82
|
+
other_attrs = {k: v for k, v in json_data.items()
|
|
83
|
+
if k not in ('opus', 'sources', 'settings')}
|
|
84
|
+
return cls(opus=opus, sources=sources, settings=settings, **other_attrs)
|
|
85
|
+
|
|
86
|
+
@classmethod
|
|
87
|
+
def load(cls, filepath: str) -> 'Piece':
|
|
88
|
+
with open(filepath, 'r') as f:
|
|
89
|
+
print(f" <== {filepath}")
|
|
90
|
+
json_data = json.load(f)
|
|
91
|
+
return cls.build(json_data)
|
|
92
|
+
|
|
93
|
+
def save(self, filepath: str) -> None:
|
|
94
|
+
with open(filepath, 'w') as f:
|
|
95
|
+
print(f" ==> {filepath}")
|
|
96
|
+
json.dump(self.dump(), f, indent=2)
|
|
97
|
+
|
|
98
|
+
def __iadd__(self, other: Source) -> 'Piece':
|
|
99
|
+
if isinstance(other, Source):
|
|
100
|
+
self.d['sources'].append(other)
|
|
101
|
+
else:
|
|
102
|
+
raise TypeError("Can only add Source to Piece")
|
|
103
|
+
return self
|
|
104
|
+
|
|
105
|
+
def fetch(self, timeout: int = 10) -> int:
|
|
106
|
+
"""Fetch all sources. Returns count of successfully fetched sources."""
|
|
107
|
+
count = 0
|
|
108
|
+
for source in self.d.get('sources', []):
|
|
109
|
+
try:
|
|
110
|
+
if source.fetch(timeout):
|
|
111
|
+
count += 1
|
|
112
|
+
except Exception:
|
|
113
|
+
pass # Silently ignore failures
|
|
114
|
+
return count
|
|
115
|
+
|
|
116
|
+
def parse(self) -> int:
|
|
117
|
+
"""Parse all sources. Returns count of successfully parsed sources."""
|
|
118
|
+
count = 0
|
|
119
|
+
for source in self.d.get('sources', []):
|
|
120
|
+
try:
|
|
121
|
+
source.parse()
|
|
122
|
+
count += 1
|
|
123
|
+
except Exception:
|
|
124
|
+
pass # Silently ignore failures
|
|
125
|
+
return count
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
class Corpus:
|
|
129
|
+
|
|
130
|
+
def __init__(self):
|
|
131
|
+
self.d = { 'pieces' : [] }
|
|
132
|
+
|
|
133
|
+
def __iadd__(self, other: Piece) -> 'Corpus':
|
|
134
|
+
if isinstance(other, Piece):
|
|
135
|
+
self.d['pieces'].append(other)
|
|
136
|
+
else:
|
|
137
|
+
raise TypeError("Can only add Piece to Corpus")
|
|
138
|
+
return self
|
|
139
|
+
|
|
140
|
+
def dump(self) -> Dict[str, Any]:
|
|
141
|
+
result = {
|
|
142
|
+
'pieces': [source.dump() for source in self.d.get('pieces', [])]
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
result.update({k: v for k, v in self.d.items()
|
|
146
|
+
if k not in ('pieces')})
|
|
147
|
+
return result
|
|
148
|
+
|
|
149
|
+
def save(self, filepath: str) -> None:
|
|
150
|
+
with open(filepath, 'w') as f:
|
|
151
|
+
print(f" ==> {filepath}")
|
|
152
|
+
json.dump(self.dump(), f, indent=2)
|
|
153
|
+
|
|
154
|
+
def publish(self):
|
|
155
|
+
filepath = 'corpus.json'
|
|
156
|
+
self.save(filepath)
|
|
157
|
+
cmd = API_CORPUS % filepath
|
|
158
|
+
print(cmd)
|
|
159
|
+
os.system(cmd)
|
pydez/sources.py
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import uuid
|
|
3
|
+
import warnings
|
|
4
|
+
from typing import Any, Dict, List, Optional, Union
|
|
5
|
+
from urllib.request import urlopen
|
|
6
|
+
from urllib.error import URLError, HTTPError
|
|
7
|
+
|
|
8
|
+
class Source:
|
|
9
|
+
"""Base class for Dezrann sources. All sources have a URL (or URL list)."""
|
|
10
|
+
|
|
11
|
+
FIELD: Optional[str] = None
|
|
12
|
+
url: Optional[Union[str, List[str]]] = None
|
|
13
|
+
data: Optional[bytes] = None
|
|
14
|
+
str_details: Optional[str] = None
|
|
15
|
+
|
|
16
|
+
SOURCE_TYPES: List[type] = []
|
|
17
|
+
|
|
18
|
+
def __init__(self, data = None, **kwargs):
|
|
19
|
+
self.d = kwargs
|
|
20
|
+
|
|
21
|
+
# Id
|
|
22
|
+
if not 'id' in self.d:
|
|
23
|
+
self.d['id'] = str(uuid.uuid4())[:6]
|
|
24
|
+
|
|
25
|
+
# Data may me provided either through data, or through FIELD
|
|
26
|
+
if data:
|
|
27
|
+
self.data = data
|
|
28
|
+
if self.FIELD:
|
|
29
|
+
self.d[self.FIELD] = data
|
|
30
|
+
else:
|
|
31
|
+
self.data = None
|
|
32
|
+
|
|
33
|
+
if self.FIELD and self.FIELD in self.d:
|
|
34
|
+
self.url = self.d[self.FIELD]
|
|
35
|
+
else:
|
|
36
|
+
self.url = None
|
|
37
|
+
|
|
38
|
+
def str_details(self) -> str:
|
|
39
|
+
return None
|
|
40
|
+
|
|
41
|
+
def __str__(self) -> str:
|
|
42
|
+
class_name = self.__class__.__name__
|
|
43
|
+
if class_name.endswith('Source'):
|
|
44
|
+
type_name = class_name[:-6]
|
|
45
|
+
else:
|
|
46
|
+
type_name = class_name
|
|
47
|
+
if self.str_details():
|
|
48
|
+
return f"{type_name} ({self.str_details})"
|
|
49
|
+
return type_name
|
|
50
|
+
|
|
51
|
+
def dump(self) -> Dict[str, Any]:
|
|
52
|
+
return self.d.copy()
|
|
53
|
+
|
|
54
|
+
@classmethod
|
|
55
|
+
def build(cls, json_data: Dict[str, Any]) -> 'Source':
|
|
56
|
+
for source_type in cls.SOURCE_TYPES:
|
|
57
|
+
if source_type.FIELD and source_type.FIELD in json_data:
|
|
58
|
+
return source_type(**json_data)
|
|
59
|
+
return GenericSource(**json_data)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def fetch(self, timeout: int = 10) -> bool:
|
|
63
|
+
"""Fetch the URL content into self.data. Returns True if successful."""
|
|
64
|
+
if self.url is None:
|
|
65
|
+
warnings.warn("No URL to fetch")
|
|
66
|
+
return False
|
|
67
|
+
|
|
68
|
+
# Normalize to list for uniform handling
|
|
69
|
+
urls = [self.url] if isinstance(self.url, str) else self.url
|
|
70
|
+
self.data = []
|
|
71
|
+
|
|
72
|
+
for url in urls:
|
|
73
|
+
try:
|
|
74
|
+
print(f" <== {url}")
|
|
75
|
+
with urlopen(url, timeout=timeout) as response:
|
|
76
|
+
self.data.append(response.read())
|
|
77
|
+
except (URLError, HTTPError, ValueError) as e:
|
|
78
|
+
warnings.warn(f"Failed to fetch {url}: {e}")
|
|
79
|
+
return False
|
|
80
|
+
|
|
81
|
+
# For single URL, store as bytes instead of list
|
|
82
|
+
if len(self.data) == 1:
|
|
83
|
+
self.data = self.data[0]
|
|
84
|
+
|
|
85
|
+
return True
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def parse(self) -> None:
|
|
89
|
+
raise NotImplementedError("Subclasses must implement parse()")
|
|
90
|
+
|
|
91
|
+
class ScoreSource(Source):
|
|
92
|
+
FIELD = 'score'
|
|
93
|
+
|
|
94
|
+
class ScoreNeumaSource(ScoreSource):
|
|
95
|
+
FIELD = 'score:neuma'
|
|
96
|
+
|
|
97
|
+
class ScoreGallicaSource(ScoreSource):
|
|
98
|
+
FIELD = 'score:gallica'
|
|
99
|
+
|
|
100
|
+
class TabSource(Source):
|
|
101
|
+
FIELD = 'tab'
|
|
102
|
+
|
|
103
|
+
class YouTubeSource(Source):
|
|
104
|
+
pass
|
|
105
|
+
|
|
106
|
+
class VideoYouTubeSource(YouTubeSource):
|
|
107
|
+
FIELD = 'video:yt'
|
|
108
|
+
|
|
109
|
+
class AudioYouTubeSource(YouTubeSource):
|
|
110
|
+
FIELD = 'audio:yt'
|
|
111
|
+
|
|
112
|
+
class VideoSource(Source):
|
|
113
|
+
FIELD = 'video'
|
|
114
|
+
|
|
115
|
+
class AudioSource(Source):
|
|
116
|
+
FIELD = 'audio'
|
|
117
|
+
|
|
118
|
+
class ImagesSource(Source):
|
|
119
|
+
FIELD = 'images'
|
|
120
|
+
|
|
121
|
+
def __init__(self, **kwargs):
|
|
122
|
+
super().__init__(**kwargs)
|
|
123
|
+
if 'images' in self.d and 'positions' not in self.d:
|
|
124
|
+
warnings.warn("Images source should have a 'positions' field")
|
|
125
|
+
|
|
126
|
+
class AnalysisSource(Source):
|
|
127
|
+
"""Analysis source (.dez format)."""
|
|
128
|
+
FIELD = 'analysis'
|
|
129
|
+
|
|
130
|
+
def parse(self) -> None:
|
|
131
|
+
if self.data is None:
|
|
132
|
+
raise ValueError("No data to parse. Call fetch() first.")
|
|
133
|
+
try:
|
|
134
|
+
json_data = json.loads(self.data.decode('utf-8'))
|
|
135
|
+
from .analyses import Analysis
|
|
136
|
+
self.analysis = Analysis.build(json_data)
|
|
137
|
+
except (json.JSONDecodeError, UnicodeDecodeError) as e:
|
|
138
|
+
raise ValueError(f"Failed to parse analysis data: {e}")
|
|
139
|
+
|
|
140
|
+
def str_details(self):
|
|
141
|
+
return str(self.analysis) if 'analysis' in self.__dict__ else None
|
|
142
|
+
|
|
143
|
+
class SelectionSource(AnalysisSource):
|
|
144
|
+
"""Selection source (.dez format)."""
|
|
145
|
+
FIELD = 'selection'
|
|
146
|
+
|
|
147
|
+
class LyricsSource(Source):
|
|
148
|
+
FIELD = 'lyrics'
|
|
149
|
+
|
|
150
|
+
class MidiSource(Source):
|
|
151
|
+
FIELD = 'midi'
|
|
152
|
+
|
|
153
|
+
class GenericSource(Source):
|
|
154
|
+
FIELD = None
|
|
155
|
+
|
|
156
|
+
Source.SOURCE_TYPES = [
|
|
157
|
+
ScoreNeumaSource,
|
|
158
|
+
ScoreGallicaSource,
|
|
159
|
+
ScoreSource,
|
|
160
|
+
TabSource,
|
|
161
|
+
VideoYouTubeSource,
|
|
162
|
+
AudioYouTubeSource,
|
|
163
|
+
VideoSource,
|
|
164
|
+
AudioSource,
|
|
165
|
+
ImagesSource,
|
|
166
|
+
AnalysisSource,
|
|
167
|
+
SelectionSource,
|
|
168
|
+
LyricsSource,
|
|
169
|
+
MidiSource,
|
|
170
|
+
]
|
|
171
|
+
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pydez
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python bindings for Dezrann
|
|
5
|
+
Home-page: https://gitlab.com/algomus.fr/dezrann/pydez
|
|
6
|
+
Author: Mathieu Giraud
|
|
7
|
+
Author-email: Mathieu Giraud <mathieu@algomus.fr>
|
|
8
|
+
License: LGPL-3.0-or-later
|
|
9
|
+
Project-URL: Homepage, https://gitlab.com/algomus.fr/dezrann/pydez
|
|
10
|
+
Project-URL: Documentation, https://gitlab.com/algomus.fr/dezrann/pydez#readme
|
|
11
|
+
Project-URL: Repository, https://gitlab.com/algomus.fr/dezrann/pydez.git
|
|
12
|
+
Project-URL: Issues, https://gitlab.com/algomus.fr/dezrann/pydez/issues
|
|
13
|
+
Keywords: dezrann,music,annotation,analysis,corpus
|
|
14
|
+
Classifier: Development Status :: 3 - Alpha
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Intended Audience :: Science/Research
|
|
17
|
+
Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
25
|
+
Classifier: Topic :: Artistic Software
|
|
26
|
+
Classifier: Topic :: Multimedia :: Sound/Audio
|
|
27
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
28
|
+
Requires-Python: >=3.8
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Requires-Dist: Flask>=2.0
|
|
32
|
+
Dynamic: author
|
|
33
|
+
Dynamic: home-page
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
Dynamic: requires-python
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# pydez: Python bindings for Dezrann
|
|
39
|
+
|
|
40
|
+
[Dezrann](https://dezrann.net) is an open platform to hear, study, and annotate music on the web.
|
|
41
|
+
Pydez is a simple, spec-compliant Python library for working with Dezrann file formats:
|
|
42
|
+
- `.dez` files (Analysis and Label data), as defined in [Encoding music annotations](https://doc.dezrann.net/dez-format)
|
|
43
|
+
- `.json` files (Corpus, Piece, Source, and Metadata),
|
|
44
|
+
as defined in [Specifying corpus and piece (meta)data](https://doc.dezrann.net/metadata)
|
|
45
|
+
|
|
46
|
+
## Features
|
|
47
|
+
|
|
48
|
+
- **Label**: Individual annotation with `start`, `duration`, `tag`, `type`, `comment`, and custom attributes
|
|
49
|
+
- **Analysis**: Collection of Labels with metadata and layout rules
|
|
50
|
+
- **Source**: Base class with subclasses for different source types
|
|
51
|
+
- **Piece**: Musical piece with opus metadata and multiple sources
|
|
52
|
+
|
|
53
|
+
All classes support:
|
|
54
|
+
- `dump()` → Convert to dict
|
|
55
|
+
- `load(filepath)` → Load from JSON file
|
|
56
|
+
- `save(filepath)` → Save to JSON file
|
|
57
|
+
- `build(dict)` → Create from dict with error handling
|
|
58
|
+
- `+=` operator for combining instances
|
|
59
|
+
|
|
60
|
+
## Installation
|
|
61
|
+
|
|
62
|
+
```sh
|
|
63
|
+
pip install pydez
|
|
64
|
+
|
|
65
|
+
# or, for development
|
|
66
|
+
git clone https://gitlab.com/algomus.fr/dezrann/pydez.git
|
|
67
|
+
cd pydez
|
|
68
|
+
pip install -e .
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Example usage
|
|
72
|
+
|
|
73
|
+
Working with analyses and pieces
|
|
74
|
+
|
|
75
|
+
```sh
|
|
76
|
+
python examples/create_analysis.py
|
|
77
|
+
python examples/create_piece.py
|
|
78
|
+
python examples/load_modify.py
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Creating a service handling music data, as described in [External services](https://doc.dezrann.net/api-services)
|
|
82
|
+
|
|
83
|
+
```sh
|
|
84
|
+
python examples/service.py
|
|
85
|
+
python examples/service-test.py
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Running tests
|
|
89
|
+
|
|
90
|
+
```sh
|
|
91
|
+
cd pydez
|
|
92
|
+
python -m pytest tests/
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
Dezrann is open-source, and developped with the help of many contributors in the [Algomus](https://www.algomus.fr) computer music team and elsewhere.
|
|
98
|
+
The Python bindings are licensed under the LGPL version 3 or any later version.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
pydez/__init__.py,sha256=X36t4_wVrK-NrR9Xs9dsj5njIiyoKQCei6Sm8eTwN_w,1857
|
|
2
|
+
pydez/analyses.py,sha256=WXnzkRz-AqeJAKn6KDeTxsCWFPMYAYWfRQ707p7lx-M,2901
|
|
3
|
+
pydez/pieces.py,sha256=_q20GuIr0KEJEj7nhO16l8hNLMIbCkrf18uLrCA16nc,5615
|
|
4
|
+
pydez/sources.py,sha256=h9UP0m0-8VJrmJrnCD3ihaId0d8G-OrPcyMBgO4FG8w,4579
|
|
5
|
+
pydez-0.1.0.dist-info/licenses/LICENSE,sha256=46mU2C5kSwOnkqkw9XQAJlhBL2JAf1_uCD8lVcXyMRg,7652
|
|
6
|
+
pydez-0.1.0.dist-info/METADATA,sha256=x_9VgK1WJcUcVctwOZziX2oCKrUemIbRqWqriVl8Cz8,3371
|
|
7
|
+
pydez-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
8
|
+
pydez-0.1.0.dist-info/top_level.txt,sha256=Q_JLMsgo71LLThth6oF5odSwCMjz06GSogNpx_Maj9I,6
|
|
9
|
+
pydez-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
6
|
+
of this license document, but changing it is not allowed.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
11
|
+
License, supplemented by the additional permissions listed below.
|
|
12
|
+
|
|
13
|
+
0. Additional Definitions.
|
|
14
|
+
|
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
17
|
+
General Public License.
|
|
18
|
+
|
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
|
20
|
+
other than an Application or a Combined Work as defined below.
|
|
21
|
+
|
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
25
|
+
of using an interface provided by the Library.
|
|
26
|
+
|
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
28
|
+
Application with the Library. The particular version of the Library
|
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
|
30
|
+
Version".
|
|
31
|
+
|
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
35
|
+
based on the Application, and not on the Linked Version.
|
|
36
|
+
|
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
38
|
+
object code and/or source code for the Application, including any data
|
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
41
|
+
|
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
|
43
|
+
|
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
|
46
|
+
|
|
47
|
+
2. Conveying Modified Versions.
|
|
48
|
+
|
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
|
51
|
+
that uses the facility (other than as an argument passed when the
|
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
|
53
|
+
version:
|
|
54
|
+
|
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
|
56
|
+
ensure that, in the event an Application does not supply the
|
|
57
|
+
function or data, the facility still operates, and performs
|
|
58
|
+
whatever part of its purpose remains meaningful, or
|
|
59
|
+
|
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
|
61
|
+
this License applicable to that copy.
|
|
62
|
+
|
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
|
64
|
+
|
|
65
|
+
The object code form of an Application may incorporate material from
|
|
66
|
+
a header file that is part of the Library. You may convey such object
|
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
|
68
|
+
material is not limited to numerical parameters, data structure
|
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
|
71
|
+
|
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
|
73
|
+
Library is used in it and that the Library and its use are
|
|
74
|
+
covered by this License.
|
|
75
|
+
|
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
77
|
+
document.
|
|
78
|
+
|
|
79
|
+
4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
|
82
|
+
taken together, effectively do not restrict modification of the
|
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
|
85
|
+
the following:
|
|
86
|
+
|
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
|
88
|
+
the Library is used in it and that the Library and its use are
|
|
89
|
+
covered by this License.
|
|
90
|
+
|
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
92
|
+
document.
|
|
93
|
+
|
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
|
95
|
+
execution, include the copyright notice for the Library among
|
|
96
|
+
these notices, as well as a reference directing the user to the
|
|
97
|
+
copies of the GNU GPL and this license document.
|
|
98
|
+
|
|
99
|
+
d) Do one of the following:
|
|
100
|
+
|
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
+
License, and the Corresponding Application Code in a form
|
|
103
|
+
suitable for, and under terms that permit, the user to
|
|
104
|
+
recombine or relink the Application with a modified version of
|
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
+
Corresponding Source.
|
|
108
|
+
|
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
|
111
|
+
a copy of the Library already present on the user's computer
|
|
112
|
+
system, and (b) will operate properly with a modified version
|
|
113
|
+
of the Library that is interface-compatible with the Linked
|
|
114
|
+
Version.
|
|
115
|
+
|
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
|
117
|
+
be required to provide such information under section 6 of the
|
|
118
|
+
GNU GPL, and only to the extent that such information is
|
|
119
|
+
necessary to install and execute a modified version of the
|
|
120
|
+
Combined Work produced by recombining or relinking the
|
|
121
|
+
Application with a modified version of the Linked Version. (If
|
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
126
|
+
for conveying Corresponding Source.)
|
|
127
|
+
|
|
128
|
+
5. Combined Libraries.
|
|
129
|
+
|
|
130
|
+
You may place library facilities that are a work based on the
|
|
131
|
+
Library side by side in a single library together with other library
|
|
132
|
+
facilities that are not Applications and are not covered by this
|
|
133
|
+
License, and convey such a combined library under terms of your
|
|
134
|
+
choice, if you do both of the following:
|
|
135
|
+
|
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
|
137
|
+
on the Library, uncombined with any other library facilities,
|
|
138
|
+
conveyed under the terms of this License.
|
|
139
|
+
|
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
|
141
|
+
is a work based on the Library, and explaining where to find the
|
|
142
|
+
accompanying uncombined form of the same work.
|
|
143
|
+
|
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
|
145
|
+
|
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
148
|
+
versions will be similar in spirit to the present version, but may
|
|
149
|
+
differ in detail to address new problems or concerns.
|
|
150
|
+
|
|
151
|
+
Each version is given a distinguishing version number. If the
|
|
152
|
+
Library as you received it specifies that a certain numbered version
|
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
|
154
|
+
applies to it, you have the option of following the terms and
|
|
155
|
+
conditions either of that published version or of any later version
|
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
|
160
|
+
|
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
164
|
+
permanent authorization for you to choose that version for the
|
|
165
|
+
Library.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pydez
|