Compare commits
63 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
6e0a0d51b5 | ||
![]() |
55aad4e6ee | ||
![]() |
d1e401cb0c | ||
![]() |
018479fae9 | ||
![]() |
1c18e72539 | ||
![]() |
779e710045 | ||
![]() |
089a981f6e | ||
![]() |
3b24bbee5f | ||
![]() |
f9a597bed9 | ||
![]() |
a637b3bb24 | ||
![]() |
3e520820d8 | ||
![]() |
3a71929821 | ||
![]() |
a08629c503 | ||
![]() |
cfc30c1234 | ||
![]() |
ddbd486500 | ||
![]() |
f5794a5bae | ||
![]() |
bb1bf87fe2 | ||
![]() |
acc59523e0 | ||
![]() |
38d7ea16b4 | ||
![]() |
6e3147c5f5 | ||
![]() |
1b09f225ff | ||
![]() |
3cf8c4f8a8 | ||
![]() |
30be4b473f | ||
![]() |
6908034a86 | ||
![]() |
cba43f675a | ||
![]() |
6ff826bc3a | ||
![]() |
c7afd10ec0 | ||
![]() |
b39d5174f9 | ||
![]() |
501bc0ab3f | ||
![]() |
688d28b5ea | ||
![]() |
27d2c7b078 | ||
![]() |
2fb12ccf65 | ||
![]() |
cb92d159c1 | ||
![]() |
64bdf4237c | ||
![]() |
fd7b4ec7e3 | ||
![]() |
57eb57d4d7 | ||
![]() |
7974e9505b | ||
![]() |
7498fb37b5 | ||
![]() |
2cc3e88e6c | ||
![]() |
5fd8cfeb80 | ||
![]() |
b295566a4e | ||
![]() |
e0943a2d55 | ||
![]() |
3015740c3e | ||
![]() |
ec9ff2f803 | ||
![]() |
ec8aae9122 | ||
![]() |
52e608cc43 | ||
![]() |
8213f270e5 | ||
![]() |
7085042b0d | ||
![]() |
6a411d2458 | ||
![]() |
38e2fbabb8 | ||
![]() |
85709f754a | ||
![]() |
623a1e8a91 | ||
![]() |
de69945ebe | ||
![]() |
7095fa6ac6 | ||
![]() |
a59e8298fd | ||
![]() |
2737d52279 | ||
![]() |
0ac1ad4386 | ||
![]() |
2db328ac31 | ||
![]() |
b6de4ad054 | ||
![]() |
cfea7164b7 | ||
![]() |
7e7e5a6be4 | ||
![]() |
df57f4c009 | ||
![]() |
c2185c4ce5 |
3
.github/FUNDING.yml
vendored
Normal file
3
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
github: JonnyWong16
|
||||
patreon: Tautulli
|
||||
custom: ["https://bit.ly/2InPp15"]
|
13
API.md
13
API.md
@@ -174,7 +174,7 @@ Delete the 3rd party API lookup info.
|
||||
```
|
||||
Required parameters:
|
||||
rating_key (int): 1234
|
||||
(Note: Must be the movie, show, or artist rating key)
|
||||
(Note: Must be the movie, show, artist, album, or track rating key)
|
||||
Optional parameters:
|
||||
None
|
||||
|
||||
@@ -416,6 +416,7 @@ Returns:
|
||||
"Drama",
|
||||
"Fantasy"
|
||||
],
|
||||
"grandparent_guid": "com.plexapp.agents.thetvdb://121361?lang=en",
|
||||
"grandparent_rating_key": "1219",
|
||||
"grandparent_thumb": "/library/metadata/1219/thumb/1503306930",
|
||||
"grandparent_title": "Game of Thrones",
|
||||
@@ -443,6 +444,7 @@ Returns:
|
||||
"optimized_version_title": "",
|
||||
"originally_available_at": "2016-04-24",
|
||||
"original_title": "",
|
||||
"parent_guid": "com.plexapp.agents.thetvdb://121361/6?lang=en",
|
||||
"parent_media_index": "6",
|
||||
"parent_rating_key": "153036",
|
||||
"parent_thumb": "/library/metadata/153036/thumb/1503889210",
|
||||
@@ -507,7 +509,9 @@ Returns:
|
||||
"stream_video_language": "",
|
||||
"stream_video_language_code": "",
|
||||
"stream_video_ref_frames": "4",
|
||||
"stream_video_full_resolution": "1080p",
|
||||
"stream_video_resolution": "1080",
|
||||
"stream_video_scan_type": "progressive",
|
||||
"stream_video_width": "1920",
|
||||
"studio": "HBO",
|
||||
"subtitle_codec": "",
|
||||
@@ -560,12 +564,14 @@ Returns:
|
||||
"video_decision": "direct play",
|
||||
"video_frame_rate": "23.976",
|
||||
"video_framerate": "24p",
|
||||
"video_full_resolution": "1080p",
|
||||
"video_height": "1078",
|
||||
"video_language": "",
|
||||
"video_language_code": "",
|
||||
"video_profile": "high",
|
||||
"video_ref_frames": "4",
|
||||
"video_resolution": "1080",
|
||||
"video_scan_type": "progressive",
|
||||
"video_width": "1920",
|
||||
"view_offset": "1000",
|
||||
"width": "1920",
|
||||
@@ -1110,6 +1116,7 @@ Returns:
|
||||
"Drama",
|
||||
"Fantasy"
|
||||
],
|
||||
"grandparent_guid": "com.plexapp.agents.thetvdb://121361?lang=en",
|
||||
"grandparent_rating_key": "1219",
|
||||
"grandparent_thumb": "/library/metadata/1219/thumb/1462175063",
|
||||
"grandparent_title": "Game of Thrones",
|
||||
@@ -1150,6 +1157,7 @@ Returns:
|
||||
"video_language_code": "",
|
||||
"video_profile": "high",
|
||||
"video_ref_frames": "4",
|
||||
"video_scan_type": "progressive",
|
||||
"video_width": "1920",
|
||||
"selected": 0
|
||||
},
|
||||
@@ -1184,6 +1192,7 @@ Returns:
|
||||
],
|
||||
"video_codec": "h264",
|
||||
"video_framerate": "24p",
|
||||
"video_full_resolution": "1080p",
|
||||
"video_profile": "high",
|
||||
"video_resolution": "1080",
|
||||
"width": "1920"
|
||||
@@ -1192,6 +1201,7 @@ Returns:
|
||||
"media_type": "episode",
|
||||
"original_title": "",
|
||||
"originally_available_at": "2016-04-24",
|
||||
"parent_guid": "com.plexapp.agents.thetvdb://121361/6?lang=en",
|
||||
"parent_media_index": "6",
|
||||
"parent_rating_key": "153036",
|
||||
"parent_thumb": "/library/metadata/153036/thumb/1462175062",
|
||||
@@ -2449,6 +2459,7 @@ Required parameters:
|
||||
body (str): The body of the message
|
||||
|
||||
Optional parameters:
|
||||
headers (str): The JSON headers for webhook notifications
|
||||
script_args (str): The arguments for script notifications
|
||||
|
||||
Returns:
|
||||
|
60
CHANGELOG.md
60
CHANGELOG.md
@@ -1,5 +1,65 @@
|
||||
# Changelog
|
||||
|
||||
## v2.1.39 (2019-12-08)
|
||||
|
||||
* UI:
|
||||
* New: Added creating admin username and password to setup wizard.
|
||||
* API:
|
||||
* Change: Remove default notification subject and body for notify API command.
|
||||
* Other:
|
||||
* Change: Check for database corruption when making backup.
|
||||
|
||||
|
||||
## v2.1.38 (2019-11-17)
|
||||
|
||||
* Notifications:
|
||||
* New: Added custom JSON headers to the webhook notification agent.
|
||||
* UI:
|
||||
* Fix: Homepage recently watched card not showing grouped history.
|
||||
* Other:
|
||||
* New: Added GitHub sponsor donation option.
|
||||
* Change: Improve resolving hostnames.
|
||||
|
||||
|
||||
## v2.1.37 (2019-10-11)
|
||||
|
||||
* Notifications:
|
||||
* Fix: Last.fm URLs linking to artist page instead of the album page.
|
||||
* New: Added option for MusicBrainz lookup for music notifications. Option must be enabled under 3rd Party APIs in the settings.
|
||||
* New: Added MusicBrainz ID and MusicBrainz URL notification parameters.
|
||||
* Change: Automatically truncate Discord description summary to 2048 characters.
|
||||
|
||||
|
||||
## v2.1.36-beta (2019-10-05)
|
||||
|
||||
* Monitoring:
|
||||
* Fix: Activity card title not updating after pre-rolls or auto-play.
|
||||
* History:
|
||||
* Fix: Display correct interlaced or progressive video scan type on stream data modal.
|
||||
* Graphs:
|
||||
* New: Separate interlaced and progressive video scan type on source and stream resolution graphs.
|
||||
* API:
|
||||
* New: Added parent_guid and grandparent_guid to get_activity and get_metadata commands.
|
||||
|
||||
|
||||
## v2.1.35-beta (2019-09-24)
|
||||
|
||||
* Monitoring:
|
||||
* Fix: Audio shown as blank on activity cards when changing audio tracks during direct play.
|
||||
* Fix: Display correct interlaced or progressive video scan type on activity cards.
|
||||
* New: Added flag for Nvidia hardware decoding on activity cards.
|
||||
* Notifications:
|
||||
* Fix: Notification parameter prefix and suffix were not substituted correctly.
|
||||
* Fix: Release Date notification parameter was incorrectly casted to an integer instead of a string.
|
||||
* New: Added video scan type and full resolution notification parameters.
|
||||
* UI:
|
||||
* Fix: Movies with the same title but different year being grouped on the homepage stats cards.
|
||||
* API:
|
||||
* New: Added video scan type and full resolution values to get_activity command.
|
||||
* Other:
|
||||
* Fix: Tautulli logging out every time after saving settings and restarting.
|
||||
|
||||
|
||||
## v2.1.34 (2019-09-03)
|
||||
|
||||
* History:
|
||||
|
@@ -1,41 +0,0 @@
|
||||
<!---
|
||||
Reporting Issues:
|
||||
* To ensure that a developer has enough information to work with please include all of the information below.
|
||||
Please provide as much detail as possible. Screenshots can be very useful to see the problem.
|
||||
* Use proper markdown syntax to structure your post (i.e. code/log in code blocks).
|
||||
See: https://help.github.com/articles/basic-writing-and-formatting-syntax/
|
||||
* Include a link to your **FULL** log file that has the error(not just a few lines!).
|
||||
Please use [Gist](http://gist.github.com) or [Pastebin](http://pastebin.com/).
|
||||
|
||||
Feature Requests:
|
||||
* Feature requests are handled on FeatHub: http://feathub.com/Tautulli/Tautulli
|
||||
* Do not post them on the GitHub issues tracker.
|
||||
-->
|
||||
|
||||
**Version:**
|
||||
|
||||
**Branch:**
|
||||
|
||||
**Commit hash:**
|
||||
|
||||
**Operating system:**
|
||||
|
||||
**Python version:**
|
||||
|
||||
**What you did?**
|
||||
|
||||
**What happened?**
|
||||
|
||||
**What you expected?**
|
||||
|
||||
**How can we reproduce your issue?**
|
||||
<!-- Provide a detailed step-by-step. -->
|
||||
|
||||
**What are your (relevant) settings?**
|
||||
|
||||
**Link to logs:**
|
||||
|
||||
|
||||
<!--
|
||||
Close your issue when it's solved! If you found the solution yourself please comment so that others benefit from it.
|
||||
-->
|
26
Tautulli.py
26
Tautulli.py
@@ -234,31 +234,19 @@ def main():
|
||||
plexpy.CONFIG.ENABLE_HTTPS = False
|
||||
|
||||
# Try to start the server. Will exit here is address is already in use.
|
||||
web_config = {
|
||||
'http_port': plexpy.HTTP_PORT,
|
||||
'http_host': plexpy.CONFIG.HTTP_HOST,
|
||||
'http_root': plexpy.CONFIG.HTTP_ROOT,
|
||||
'http_environment': plexpy.CONFIG.HTTP_ENVIRONMENT,
|
||||
'http_proxy': plexpy.CONFIG.HTTP_PROXY,
|
||||
'enable_https': plexpy.CONFIG.ENABLE_HTTPS,
|
||||
'https_cert': plexpy.CONFIG.HTTPS_CERT,
|
||||
'https_cert_chain': plexpy.CONFIG.HTTPS_CERT_CHAIN,
|
||||
'https_key': plexpy.CONFIG.HTTPS_KEY,
|
||||
'http_username': plexpy.CONFIG.HTTP_USERNAME,
|
||||
'http_password': plexpy.CONFIG.HTTP_PASSWORD,
|
||||
'http_basic_auth': plexpy.CONFIG.HTTP_BASIC_AUTH
|
||||
}
|
||||
webstart.initialize(web_config)
|
||||
webstart.start()
|
||||
|
||||
# Windows system tray icon
|
||||
if os.name == 'nt' and plexpy.CONFIG.WIN_SYS_TRAY:
|
||||
plexpy.win_system_tray()
|
||||
|
||||
logger.info("Tautulli is ready!")
|
||||
|
||||
# Open webbrowser
|
||||
if plexpy.CONFIG.LAUNCH_BROWSER and not args.nolaunch and not plexpy.DEV:
|
||||
plexpy.launch_browser(plexpy.CONFIG.HTTP_HOST, plexpy.HTTP_PORT,
|
||||
plexpy.HTTP_ROOT)
|
||||
|
||||
# Windows system tray icon
|
||||
if os.name == 'nt' and plexpy.CONFIG.WIN_SYS_TRAY:
|
||||
plexpy.win_system_tray()
|
||||
|
||||
# Wait endlessy for a signal to happen
|
||||
while True:
|
||||
if not plexpy.SIGNAL:
|
||||
|
@@ -229,6 +229,7 @@ ${next.modalIncludes()}
|
||||
</div>
|
||||
<ul id="donation_type" class="nav nav-pills" role="tablist" style="display: flex; justify-content: center; margin: 10px 0;">
|
||||
<li class="active"><a href="#patreon-donation" role="tab" data-toggle="tab">Patreon</a></li>
|
||||
<li><a href="#github-donation" role="tab" data-toggle="tab">GitHub</a></li>
|
||||
<li><a href="#paypal-donation" role="tab" data-toggle="tab">PayPal</a></li>
|
||||
</ul>
|
||||
<div class="tab-content">
|
||||
@@ -240,6 +241,14 @@ ${next.modalIncludes()}
|
||||
<img src="images/become_a_patron_button.png" alt="Become a Patron" height="40">
|
||||
</a>
|
||||
</div>
|
||||
<div role="tabpanel" class="tab-pane" id="github-donation" style="text-align: center">
|
||||
<p>
|
||||
Click the button below to continue to GitHub.
|
||||
</p>
|
||||
<a href="${anon_url('https://github.com/sponsors/JonnyWong16')}" target="_blank" class="btn btn-sm btn-default" style="font-weight: 600;">
|
||||
<i class="fa fa-heart fa-sm" style="color: #ea4aaa;"></i> Sponsor
|
||||
</a>
|
||||
</div>
|
||||
<div role="tabpanel" class="tab-pane" id="paypal-donation" style="text-align: center">
|
||||
<p>
|
||||
Click the button below to continue to PayPal.
|
||||
|
@@ -232,11 +232,11 @@ DOCUMENTATION :: END
|
||||
hw_d = ' (HW)' if data['transcode_hw_decoding'] else ''
|
||||
hw_e = ' (HW)' if data['transcode_hw_encoding'] else ''
|
||||
%>
|
||||
Transcode (${data['video_codec'].upper()}${hw_d} ${VIDEO_RESOLUTION_OVERRIDES.get(data['video_resolution'], data['video_resolution'])} <i class="fa fa-long-arrow-right"></i> ${data['stream_video_codec'].upper()}${hw_e} ${VIDEO_RESOLUTION_OVERRIDES.get(data['stream_video_resolution'], data['stream_video_resolution'])})
|
||||
Transcode (${data['video_codec'].upper()}${hw_d} ${data['video_full_resolution']} <i class="fa fa-long-arrow-right"></i> ${data['stream_video_codec'].upper()}${hw_e} ${data['stream_video_full_resolution']})
|
||||
% elif data['stream_video_decision'] == 'copy':
|
||||
Direct Stream (${data['stream_video_codec'].upper()} ${VIDEO_RESOLUTION_OVERRIDES.get(data['stream_video_resolution'], data['stream_video_resolution'])})
|
||||
Direct Stream (${data['stream_video_codec'].upper()} ${data['stream_video_full_resolution']})
|
||||
% else:
|
||||
Direct Play (${data['stream_video_codec'].upper()} ${VIDEO_RESOLUTION_OVERRIDES.get(data['stream_video_resolution'], data['stream_video_resolution'])})
|
||||
Direct Play (${data['stream_video_codec'].upper()} ${data['stream_video_full_resolution']})
|
||||
% endif
|
||||
% elif data['media_type'] == 'photo':
|
||||
Direct Play (${data['width']}x${data['height']})
|
||||
|
@@ -355,8 +355,9 @@
|
||||
var session_id = s.session_id;
|
||||
var instance = $('#activity-instance-' + key);
|
||||
|
||||
// Create a new instance if it doesn't exist
|
||||
if (!(instance.length)) {
|
||||
// Create a new instance if it doesn't exist or recreate the entire instance
|
||||
// if the rating key changed (for movies or episodes) with the same session key
|
||||
if (!(instance.length) || (s.media_type !== 'track' && s.rating_key !== instance.data('rating_key').toString())) {
|
||||
create_instances.push(key);
|
||||
getActivityInstance(key);
|
||||
return;
|
||||
@@ -382,7 +383,7 @@
|
||||
// Switching tracks can be under the same session key, so need to update the info.
|
||||
if (s.media_type === 'track') {
|
||||
// Update if artist changed
|
||||
if (s.grandparent_rating_key !== instance.data('grandparent_rating_key')) {
|
||||
if (s.grandparent_rating_key !== instance.data('grandparent_rating_key').toString()) {
|
||||
$('#background-' + key).css('background-image', 'url(pms_image_proxy?img=' + s.art + '&width=500&height=280&opacity=40&background=282828&blur=3&fallback=art&refresh=true)');
|
||||
$('#metadata-grandparent_title-' + key)
|
||||
.attr('href', 'info?rating_key=' + s.grandparent_rating_key)
|
||||
@@ -390,7 +391,7 @@
|
||||
.text(s.original_title || s.grandparent_title);
|
||||
}
|
||||
// Update cover if album changed
|
||||
if (s.parent_rating_key !== instance.data('parent_rating_key')) {
|
||||
if (s.parent_rating_key !== instance.data('parent_rating_key').toString()) {
|
||||
$('#poster-' + key).css('background-image', 'url(pms_image_proxy?img=' + s.parent_thumb + '&width=300&height=300&fallback=poster&refresh=true)');
|
||||
$('#poster-' + key + '-bg').css('background-image', 'url(pms_image_proxy?img=' + s.parent_thumb + '&width=300&height=300&opacity=60&background=282828&blur=3&fallback=poster&refresh=true)');
|
||||
$('#poster-url-' + key)
|
||||
@@ -402,7 +403,7 @@
|
||||
.text(s.parent_title);
|
||||
}
|
||||
// Update cover if track changed
|
||||
if (s.rating_key !== instance.data('rating_key')) {
|
||||
if (s.rating_key !== instance.data('rating_key').toString()) {
|
||||
$('#metadata-grandparent_title-' + key)
|
||||
.attr('href', 'info?rating_key=' + s.grandparent_rating_key)
|
||||
.attr('title', s.original_title || s.grandparent_title)
|
||||
@@ -445,7 +446,7 @@
|
||||
v_res = '4k';
|
||||
break;
|
||||
default:
|
||||
v_res = s.video_resolution + 'p'
|
||||
v_res = s.video_full_resolution;
|
||||
}
|
||||
var sv_res = '';
|
||||
switch (s.stream_video_resolution.toLowerCase()) {
|
||||
@@ -456,7 +457,7 @@
|
||||
sv_res = '4k';
|
||||
break;
|
||||
default:
|
||||
sv_res = s.stream_video_resolution + 'p'
|
||||
sv_res = s.stream_video_full_resolution;
|
||||
}
|
||||
if (s.stream_video_decision === 'transcode') {
|
||||
var hw_d = (s.transcode_hw_decoding === 1) ? ' (HW)' : '';
|
||||
@@ -580,7 +581,14 @@
|
||||
session_key: session_key
|
||||
},
|
||||
complete: function(xhr, status) {
|
||||
$('#currentActivity').append(xhr.responseText);
|
||||
var instance = $('#activity-instance-' + session_key);
|
||||
|
||||
if (instance.length) {
|
||||
instance.replaceWith(xhr.responseText);
|
||||
} else {
|
||||
$('#currentActivity').append(xhr.responseText);
|
||||
}
|
||||
|
||||
$('#activity-instance-' + session_key + ' .dashboard-activity-info-scroller').scrollbar();
|
||||
$('#activity-instance-' + session_key + ' [data-toggle=tooltip]').tooltip({ container: 'body', placement: 'right', delay: 50 });
|
||||
$('#terminate-button-' + session_key).tooltip('destroy').tooltip({ container: 'body', placement: 'left', delay: 50 });
|
||||
@@ -873,7 +881,10 @@
|
||||
async: true,
|
||||
complete: function (xhr, status) {
|
||||
$("#changelog-modal .modal-body").html(xhr.responseText);
|
||||
$('#changelog-modal').modal();
|
||||
$('#changelog-modal').modal({
|
||||
backdrop: 'static',
|
||||
keyboard: false
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
@@ -405,11 +405,11 @@ DOCUMENTATION :: END
|
||||
</a>
|
||||
</div>
|
||||
% endif
|
||||
% if data.get('tvmaze_id') or data.get('themoviedb_id'):
|
||||
% if data.get('tvmaze_id') or data.get('themoviedb_id') or data.get('musicbrainz_id'):
|
||||
<div class="btn-group">
|
||||
<button class="btn btn-danger btn-edit" data-toggle="modal" aria-pressed="false" autocomplete="off" id="delete-lookup-info"
|
||||
data-id="${data['grandparent_rating_key'] if data['media_type'] in ('episode', 'track') else data['parent_rating_key'] if data['media_type'] in ('season', 'album') else data['rating_key']}"
|
||||
data-title="${data['grandparent_title'] if data['media_type'] in ('episode', 'track') else data['parent_title'] if data['media_type'] in ('season', 'album') else data['title']}">
|
||||
data-id="${data['grandparent_rating_key'] if data['media_type'] == 'episode' else data['parent_rating_key'] if data['media_type'] == 'season' else data['rating_key']}"
|
||||
data-title="${data['grandparent_title'] if data['media_type'] == 'episode' else data['parent_title'] if data['media_type'] == 'season' else data['title']}">
|
||||
<i class="fa fa-search"></i> Delete Lookup Info
|
||||
</button>
|
||||
</div>
|
||||
@@ -751,7 +751,7 @@ DOCUMENTATION :: END
|
||||
});
|
||||
</script>
|
||||
% endif
|
||||
% if data.get('tvmaze_id') or data.get('themoviedb_id'):
|
||||
% if data.get('tvmaze_id') or data.get('themoviedb_id') or data.get('musicbrainz_id'):
|
||||
<script>
|
||||
$('#delete-lookup-info').on('click', function () {
|
||||
var msg = 'Are you sure you want to delete the 3rd party API lookup for <strong>' + $(this).data('title') + '</strong>?<br><br>' +
|
||||
|
@@ -50,7 +50,7 @@ media_info_table_options = {
|
||||
expand_details = '<span class="expand-media-info-tooltip" data-toggle="tooltip" title="Show Episodes"><i class="fa fa-plus-circle fa-fw"></i></span>';
|
||||
$(td).html('<div><a href="#"><div style="float: left;">' + expand_details + ' ' + date + '</div></a></div>');
|
||||
} else if (rowData['media_type'] === 'artist') {
|
||||
expand_details = '<span class="expand-media-info-tooltip" data-toggle="tooltip" title="Show Albumns"><i class="fa fa-plus-circle fa-fw"></i></span>';
|
||||
expand_details = '<span class="expand-media-info-tooltip" data-toggle="tooltip" title="Show Albums"><i class="fa fa-plus-circle fa-fw"></i></span>';
|
||||
$(td).html('<div><a href="#"><div style="float: left;">' + expand_details + ' ' + date + '</div></a></div>');
|
||||
} else if (rowData['media_type'] === 'album') {
|
||||
expand_details = '<span class="expand-media-info-tooltip" data-toggle="tooltip" title="Show Tracks"><i class="fa fa-plus-circle fa-fw"></i></span>';
|
||||
|
@@ -243,6 +243,11 @@
|
||||
</div>
|
||||
<ul class="submenu">
|
||||
<li>
|
||||
<div class="form-group">
|
||||
<label for="${action['name']}_subject">JSON Headers</label>
|
||||
<textarea class="form-control" id="${action['name']}_subject" name="${action['name']}_subject" data-parsley-trigger="change" data-autoresize required>${notifier['notify_text'][action['name']]['subject']}</textarea>
|
||||
<p class="help-block">Set custom JSON headers.</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="${action['name']}_body">JSON Data</label>
|
||||
<textarea class="form-control" id="${action['name']}_body" name="${action['name']}_body" data-parsley-trigger="change" data-autoresize required>${notifier['notify_text'][action['name']]['body']}</textarea>
|
||||
@@ -326,6 +331,15 @@
|
||||
<p class="help-block">Set custom arguments passed to the script.</p>
|
||||
</div>
|
||||
% elif notifier['agent_name'] == 'webhook':
|
||||
<div class="form-group">
|
||||
<label for="test_subject">JSON Headers</label>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<textarea class="form-control" id="test_subject" name="test_subject" data-autoresize></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<p class="help-block">Set custom JSON headers sent to the webhook.</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="test_body">JSON Data</label>
|
||||
<div class="row">
|
||||
|
@@ -1163,6 +1163,12 @@
|
||||
</label>
|
||||
<p class="help-block">Enable to lookup links to TVmaze (and IMDb if needed) for TV shows when available.</p>
|
||||
</div>
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" name="musicbrainz_lookup" id="musicbrainz_lookup" value="1" ${config['musicbrainz_lookup']}> Lookup MusicBrainz Links
|
||||
</label>
|
||||
<p class="help-block">Enable to lookup links to MusicBrainz for music when available.</p>
|
||||
</div>
|
||||
|
||||
<p><input type="button" class="btn btn-bright save-button" value="Save" data-success="Changes saved successfully"></p>
|
||||
|
||||
|
@@ -96,8 +96,8 @@ DOCUMENTATION :: END
|
||||
% if data['media_type'] != 'track':
|
||||
<tr>
|
||||
<td>Resolution</td>
|
||||
<td>${VIDEO_RESOLUTION_OVERRIDES.get(data['stream_video_resolution'], data['stream_video_resolution'])}</td>
|
||||
<td>${VIDEO_RESOLUTION_OVERRIDES.get(data['video_resolution'], data['video_resolution'])}</td>
|
||||
<td>${data['stream_video_full_resolution']}</td>
|
||||
<td>${data['video_full_resolution']}</td>
|
||||
</tr>
|
||||
% endif
|
||||
<tr>
|
||||
|
@@ -21,28 +21,21 @@
|
||||
<link href="${http_root}css/font-awesome.v4-shims.min.css" rel="stylesheet">
|
||||
|
||||
<!-- Favicons -->
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="${http_root}images/favicon/favicon-32x32.png?v=2.0.0">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="${http_root}images/favicon/favicon-16x16.png?v=2.0.0">
|
||||
<link rel="shortcut icon" href="${http_root}images/favicon/favicon.ico?v=2.0.0">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="${http_root}images/favicon/favicon-32x32.png?v=2.0.5">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="${http_root}images/favicon/favicon-16x16.png?v=2.0.5">
|
||||
<link rel="shortcut icon" href="${http_root}images/favicon/favicon.ico?v=2.0.5">
|
||||
|
||||
<!-- ICONS -->
|
||||
<!-- Android >M39 icon -->
|
||||
<link rel="icon" type="image/png" sizes="192x192" href="${http_root}images/favicon/android-chrome-192x192.png?v=2.0.0">
|
||||
<link rel="manifest" href="${http_root}json/Android-manifest.json?v=2.0.0">
|
||||
<meta name="theme-color" content="#1f1f1f">
|
||||
<!-- Android -->
|
||||
<link rel="manifest" href="${http_root}images/favicon/manifest.json?v=2.0.5">
|
||||
<meta name="theme-color" content="#282a2d">
|
||||
<!-- Apple -->
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="${http_root}images/favicon/apple-touch-icon.png?v=2.0.0">
|
||||
<link rel="mask-icon" href="${http_root}images/favicon/safari-pinned-tab.svg?v=2.0.0" color="#1f1f1f">
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="${http_root}images/favicon/apple-touch-icon.png?v=2.0.5">
|
||||
<link rel="mask-icon" href="${http_root}images/favicon/safari-pinned-tab.svg?v=2.0.5" color="#282a2d">
|
||||
<meta name="apple-mobile-web-app-title" content="Tautulli">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
||||
<meta name="viewport" content="initial-scale=1">
|
||||
<meta name="format-detection" content="telephone=no">
|
||||
<!-- IE10 icon -->
|
||||
<!-- Microsoft -->
|
||||
<meta name="application-name" content="Tautulli">
|
||||
<meta name="msapplication-TileColor" content="#1f1f1f">
|
||||
<meta name="msapplication-TileImage" content="${http_root}images/favicon/mstile-144x144.png?v=2.0.0">
|
||||
<meta name="msapplication-config" content="${http_root}xml/IEconfig.xml?v=2.0.0" />
|
||||
<meta name="msapplication-config" content="${http_root}images/favicon/browserconfig.xml?v=2.0.5">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@@ -67,8 +60,38 @@
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="wizard-card" data-cardname="card2">
|
||||
<h3>Plex Authentication</h3>
|
||||
<h3>Authentication</h3>
|
||||
<div class="wizard-input-section">
|
||||
<p class="help-block">
|
||||
Please setup an admin username and password for Tautulli.
|
||||
</p>
|
||||
</div>
|
||||
<div class="wizard-input-section">
|
||||
<label for="http_username">HTTP Username</label>
|
||||
<div class="row">
|
||||
<div class="col-xs-8">
|
||||
<input type="text" class="form-control auth-settings" id="http_username" name="http_username" value="" size="30">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="wizard-input-section">
|
||||
<label for="http_password">HTTP Password</label>
|
||||
<div class="row">
|
||||
<div class="col-xs-8">
|
||||
<input type="password" class="form-control auth-settings" id="http_password" name="http_password" value="" size="30" autocomplete="new-password">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" class="form-control" name="http_hash_password" id="http_hash_password" value="1">
|
||||
<input type="hidden" class="form-control" name="http_plex_admin" id="http_plex_admin" value="1">
|
||||
<input type="hidden" id="authentication_valid" data-validate="validateAuthentication" value="">
|
||||
<span style="display: none;" id="authentication-status"></span>
|
||||
</div>
|
||||
|
||||
<div class="wizard-card" data-cardname="card3">
|
||||
<h3>Plex Account</h3>
|
||||
<div class="wizard-input-section">
|
||||
<p class="help-block">
|
||||
Tautulli requires a Plex.tv account. Click the button below to sign in on Plex.tv. You may need to allow popups in your browser.
|
||||
@@ -78,7 +101,8 @@
|
||||
<a class="btn btn-dark" id="sign-in-plex" href="#" role="button">Sign In with Plex</a>
|
||||
<span style="margin-left: 10px; display: none;" id="pms-token-status"></span>
|
||||
</div>
|
||||
<div class="wizard-card" data-cardname="card3">
|
||||
|
||||
<div class="wizard-card" data-cardname="card4">
|
||||
<h3>Plex Media Server</h3>
|
||||
<div class="wizard-input-section">
|
||||
<p class="help-block">
|
||||
@@ -137,7 +161,7 @@
|
||||
<span style="margin-left: 10px; display: none;" id="pms-verify-status"></span>
|
||||
</div>
|
||||
|
||||
<div class="wizard-card" data-cardname="card4">
|
||||
<div class="wizard-card" data-cardname="card5">
|
||||
<h3>Activity Logging</h3>
|
||||
<div class="wizard-input-section">
|
||||
<p class="help-block">
|
||||
@@ -162,7 +186,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="wizard-card" data-cardname="card4">
|
||||
<div class="wizard-card" data-cardname="card6">
|
||||
<h3>Notifications</h3>
|
||||
<div class="wizard-input-section">
|
||||
<p class="help-block">
|
||||
@@ -175,7 +199,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="wizard-card" data-cardname="card5">
|
||||
<div class="wizard-card" data-cardname="card7">
|
||||
<h3>Database Import</h3>
|
||||
<div class="wizard-input-section">
|
||||
<p class="help-block">
|
||||
@@ -227,11 +251,29 @@
|
||||
<script src="${http_root}js/script.js${cache_param}"></script>
|
||||
<script src="${http_root}js/bootstrap-wizard.min.js"></script>
|
||||
<script>
|
||||
function validateAuthentication(el) {
|
||||
var http_username = $("#http_username").val();
|
||||
var http_password = $("#http_password").val();
|
||||
var valid_authentication = el.val();
|
||||
var retValue = {};
|
||||
|
||||
if (http_username === "" || http_password === "") {
|
||||
retValue.status = false;
|
||||
retValue.msg = "Please enter a username and password.";
|
||||
$("#authentication-status").html('<i class="fa fa-exclamation-circle"></i> Please enter a username and password.');
|
||||
$('#authentication-status').fadeIn('fast').delay(2000).fadeOut('fast');
|
||||
} else {
|
||||
retValue.status = true;
|
||||
}
|
||||
|
||||
return retValue;
|
||||
}
|
||||
|
||||
function validatePMSip(el) {
|
||||
var valid_pms_ip = el.val();
|
||||
var retValue = {};
|
||||
|
||||
if (valid_pms_ip == "") {
|
||||
if (valid_pms_ip === "") {
|
||||
retValue.status = false;
|
||||
retValue.msg = "Please verify your server.";
|
||||
$("#pms-verify-status").html('<i class="fa fa-exclamation-circle"></i> Please verify your server.');
|
||||
@@ -247,7 +289,7 @@
|
||||
var valid_pms_token = el.val();
|
||||
var retValue = {};
|
||||
|
||||
if (valid_pms_token == "") {
|
||||
if (valid_pms_token === "") {
|
||||
retValue.status = false;
|
||||
retValue.msg = "Please authenticate.";
|
||||
$("#pms-token-status").html('<i class="fa fa-exclamation-circle"></i> Please authenticate.');
|
||||
@@ -284,7 +326,7 @@ $(document).ready(function() {
|
||||
$.fn.wizard.logging = false;
|
||||
var options = {
|
||||
keyboard : false,
|
||||
contentHeight : 400,
|
||||
contentHeight : 450,
|
||||
contentWidth : 700,
|
||||
backdrop: 'static',
|
||||
buttons: {submitText: 'Finish'},
|
||||
|
2
lib/musicbrainzngs/__init__.py
Normal file
2
lib/musicbrainzngs/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from musicbrainzngs.musicbrainz import *
|
||||
from musicbrainzngs.caa import *
|
187
lib/musicbrainzngs/caa.py
Normal file
187
lib/musicbrainzngs/caa.py
Normal file
@@ -0,0 +1,187 @@
|
||||
# This file is part of the musicbrainzngs library
|
||||
# Copyright (C) Alastair Porter, Wieland Hoffmann, and others
|
||||
# This file is distributed under a BSD-2-Clause type license.
|
||||
# See the COPYING file for more information.
|
||||
|
||||
__all__ = [
|
||||
'set_caa_hostname', 'get_image_list', 'get_release_group_image_list',
|
||||
'get_release_group_image_front', 'get_image_front', 'get_image_back',
|
||||
'get_image'
|
||||
]
|
||||
|
||||
import json
|
||||
|
||||
from musicbrainzngs import compat
|
||||
from musicbrainzngs import musicbrainz
|
||||
from musicbrainzngs.util import _unicode
|
||||
|
||||
hostname = "coverartarchive.org"
|
||||
https = True
|
||||
|
||||
|
||||
def set_caa_hostname(new_hostname, use_https=False):
|
||||
"""Set the base hostname for Cover Art Archive requests.
|
||||
Defaults to 'coverartarchive.org', accessing over https.
|
||||
For backwards compatibility, `use_https` is False by default.
|
||||
|
||||
:param str new_hostname: The hostname (and port) of the CAA server to connect to
|
||||
:param bool use_https: `True` if the host should be accessed using https. Default is `False`
|
||||
"""
|
||||
global hostname
|
||||
global https
|
||||
hostname = new_hostname
|
||||
https = use_https
|
||||
|
||||
|
||||
def _caa_request(mbid, imageid=None, size=None, entitytype="release"):
|
||||
""" Make a CAA request.
|
||||
|
||||
:param imageid: ``front``, ``back`` or a number from the listing obtained
|
||||
with :meth:`get_image_list`.
|
||||
:type imageid: str
|
||||
|
||||
:param size: "250", "500", "1200"
|
||||
:type size: str or None
|
||||
|
||||
:param entitytype: ``release`` or ``release-group``
|
||||
:type entitytype: str
|
||||
"""
|
||||
# Construct the full URL for the request, including hostname and
|
||||
# query string.
|
||||
path = [entitytype, mbid]
|
||||
if imageid and size:
|
||||
path.append("%s-%s" % (imageid, size))
|
||||
elif imageid:
|
||||
path.append(imageid)
|
||||
url = compat.urlunparse((
|
||||
'https' if https else 'http',
|
||||
hostname,
|
||||
'/%s' % '/'.join(path),
|
||||
'',
|
||||
'',
|
||||
''
|
||||
))
|
||||
musicbrainz._log.debug("GET request for %s" % (url, ))
|
||||
|
||||
# Set up HTTP request handler and URL opener.
|
||||
httpHandler = compat.HTTPHandler(debuglevel=0)
|
||||
handlers = [httpHandler]
|
||||
|
||||
opener = compat.build_opener(*handlers)
|
||||
|
||||
# Make request.
|
||||
req = musicbrainz._MusicbrainzHttpRequest("GET", url, None)
|
||||
# Useragent isn't needed for CAA, but we'll add it if it exists
|
||||
if musicbrainz._useragent != "":
|
||||
req.add_header('User-Agent', musicbrainz._useragent)
|
||||
musicbrainz._log.debug("requesting with UA %s" % musicbrainz._useragent)
|
||||
|
||||
resp = musicbrainz._safe_read(opener, req, None)
|
||||
|
||||
# TODO: The content type declared by the CAA for JSON files is
|
||||
# 'applicaiton/octet-stream'. This is not useful to detect whether the
|
||||
# content is JSON, so default to decoding JSON if no imageid was supplied.
|
||||
# http://tickets.musicbrainz.org/browse/CAA-75
|
||||
if imageid:
|
||||
# If we asked for an image, return the image
|
||||
return resp
|
||||
else:
|
||||
# Otherwise it's json
|
||||
data = _unicode(resp)
|
||||
return json.loads(data)
|
||||
|
||||
|
||||
def get_image_list(releaseid):
|
||||
"""Get the list of cover art associated with a release.
|
||||
|
||||
The return value is the deserialized response of the `JSON listing
|
||||
<http://musicbrainz.org/doc/Cover_Art_Archive/API#.2Frelease.2F.7Bmbid.7D.2F>`_
|
||||
returned by the Cover Art Archive API.
|
||||
|
||||
If an error occurs then a :class:`~musicbrainzngs.ResponseError` will
|
||||
be raised with one of the following HTTP codes:
|
||||
|
||||
* 400: `Releaseid` is not a valid UUID
|
||||
* 404: No release exists with an MBID of `releaseid`
|
||||
* 503: Ratelimit exceeded
|
||||
"""
|
||||
return _caa_request(releaseid)
|
||||
|
||||
|
||||
def get_release_group_image_list(releasegroupid):
|
||||
"""Get the list of cover art associated with a release group.
|
||||
|
||||
The return value is the deserialized response of the `JSON listing
|
||||
<http://musicbrainz.org/doc/Cover_Art_Archive/API#.2Frelease-group.2F.7Bmbid.7D.2F>`_
|
||||
returned by the Cover Art Archive API.
|
||||
|
||||
If an error occurs then a :class:`~musicbrainzngs.ResponseError` will
|
||||
be raised with one of the following HTTP codes:
|
||||
|
||||
* 400: `Releaseid` is not a valid UUID
|
||||
* 404: No release exists with an MBID of `releaseid`
|
||||
* 503: Ratelimit exceeded
|
||||
"""
|
||||
return _caa_request(releasegroupid, entitytype="release-group")
|
||||
|
||||
|
||||
def get_release_group_image_front(releasegroupid, size=None):
|
||||
"""Download the front cover art for a release group.
|
||||
The `size` argument and the possible error conditions are the same as for
|
||||
:meth:`get_image`.
|
||||
"""
|
||||
return get_image(releasegroupid, "front", size=size,
|
||||
entitytype="release-group")
|
||||
|
||||
|
||||
def get_image_front(releaseid, size=None):
|
||||
"""Download the front cover art for a release.
|
||||
The `size` argument and the possible error conditions are the same as for
|
||||
:meth:`get_image`.
|
||||
"""
|
||||
return get_image(releaseid, "front", size=size)
|
||||
|
||||
|
||||
def get_image_back(releaseid, size=None):
|
||||
"""Download the back cover art for a release.
|
||||
The `size` argument and the possible error conditions are the same as for
|
||||
:meth:`get_image`.
|
||||
"""
|
||||
return get_image(releaseid, "back", size=size)
|
||||
|
||||
|
||||
def get_image(mbid, coverid, size=None, entitytype="release"):
|
||||
"""Download cover art for a release. The coverart file to download
|
||||
is specified by the `coverid` argument.
|
||||
|
||||
If `size` is not specified, download the largest copy present, which can be
|
||||
very large.
|
||||
|
||||
If an error occurs then a :class:`~musicbrainzngs.ResponseError`
|
||||
will be raised with one of the following HTTP codes:
|
||||
|
||||
* 400: `Releaseid` is not a valid UUID or `coverid` is invalid
|
||||
* 404: No release exists with an MBID of `releaseid`
|
||||
* 503: Ratelimit exceeded
|
||||
|
||||
:param coverid: ``front``, ``back`` or a number from the listing obtained with
|
||||
:meth:`get_image_list`
|
||||
:type coverid: int or str
|
||||
|
||||
:param size: "250", "500", "1200" or None. If it is None, the largest
|
||||
available picture will be downloaded. If the image originally
|
||||
uploaded to the Cover Art Archive was smaller than the
|
||||
requested size, only the original image will be returned.
|
||||
:type size: str or None
|
||||
|
||||
:param entitytype: The type of entity for which to download the cover art.
|
||||
This is either ``release`` or ``release-group``.
|
||||
:type entitytype: str
|
||||
:return: The binary image data
|
||||
:type: str
|
||||
"""
|
||||
if isinstance(coverid, int):
|
||||
coverid = "%d" % (coverid, )
|
||||
if isinstance(size, int):
|
||||
size = "%d" % (size, )
|
||||
return _caa_request(mbid, coverid, size=size, entitytype=entitytype)
|
61
lib/musicbrainzngs/compat.py
Normal file
61
lib/musicbrainzngs/compat.py
Normal file
@@ -0,0 +1,61 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2012 Kenneth Reitz.
|
||||
|
||||
# Permission to use, copy, modify, and/or distribute this software for any
|
||||
# purpose with or without fee is hereby granted, provided that the above
|
||||
# copyright notice and this permission notice appear in all copies.
|
||||
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
"""
|
||||
pythoncompat
|
||||
"""
|
||||
|
||||
|
||||
import sys
|
||||
|
||||
# -------
|
||||
# Pythons
|
||||
# -------
|
||||
|
||||
# Syntax sugar.
|
||||
_ver = sys.version_info
|
||||
|
||||
#: Python 2.x?
|
||||
is_py2 = (_ver[0] == 2)
|
||||
|
||||
#: Python 3.x?
|
||||
is_py3 = (_ver[0] == 3)
|
||||
|
||||
# ---------
|
||||
# Specifics
|
||||
# ---------
|
||||
|
||||
if is_py2:
|
||||
from StringIO import StringIO
|
||||
from urllib2 import HTTPPasswordMgr, HTTPDigestAuthHandler, Request,\
|
||||
HTTPHandler, build_opener, HTTPError, URLError
|
||||
from httplib import BadStatusLine, HTTPException
|
||||
from urlparse import urlunparse
|
||||
from urllib import urlencode, quote_plus
|
||||
|
||||
bytes = str
|
||||
unicode = unicode
|
||||
basestring = basestring
|
||||
elif is_py3:
|
||||
from io import StringIO
|
||||
from urllib.request import HTTPPasswordMgr, HTTPDigestAuthHandler, Request,\
|
||||
HTTPHandler, build_opener
|
||||
from urllib.error import HTTPError, URLError
|
||||
from http.client import HTTPException, BadStatusLine
|
||||
from urllib.parse import urlunparse, urlencode, quote_plus
|
||||
|
||||
unicode = str
|
||||
bytes = bytes
|
||||
basestring = (str,bytes)
|
817
lib/musicbrainzngs/mbxml.py
Normal file
817
lib/musicbrainzngs/mbxml.py
Normal file
@@ -0,0 +1,817 @@
|
||||
# This file is part of the musicbrainzngs library
|
||||
# Copyright (C) Alastair Porter, Adrian Sampson, and others
|
||||
# This file is distributed under a BSD-2-Clause type license.
|
||||
# See the COPYING file for more information.
|
||||
|
||||
import re
|
||||
import xml.etree.ElementTree as ET
|
||||
import logging
|
||||
|
||||
from . import util
|
||||
|
||||
|
||||
def fixtag(tag, namespaces):
|
||||
# given a decorated tag (of the form {uri}tag), return prefixed
|
||||
# tag and namespace declaration, if any
|
||||
if isinstance(tag, ET.QName):
|
||||
tag = tag.text
|
||||
namespace_uri, tag = tag[1:].split("}", 1)
|
||||
prefix = namespaces.get(namespace_uri)
|
||||
if prefix is None:
|
||||
prefix = "ns%d" % len(namespaces)
|
||||
namespaces[namespace_uri] = prefix
|
||||
if prefix == "xml":
|
||||
xmlns = None
|
||||
else:
|
||||
xmlns = ("xmlns:%s" % prefix, namespace_uri)
|
||||
else:
|
||||
xmlns = None
|
||||
return "%s:%s" % (prefix, tag), xmlns
|
||||
|
||||
|
||||
NS_MAP = {"http://musicbrainz.org/ns/mmd-2.0#": "ws2",
|
||||
"http://musicbrainz.org/ns/ext#-2.0": "ext"}
|
||||
_log = logging.getLogger("musicbrainzngs")
|
||||
|
||||
def get_error_message(error):
|
||||
""" Given an error XML message from the webservice containing
|
||||
<error><text>x</text><text>y</text></error>, return a list
|
||||
of [x, y]"""
|
||||
try:
|
||||
tree = util.bytes_to_elementtree(error)
|
||||
root = tree.getroot()
|
||||
errors = []
|
||||
if root.tag == "error":
|
||||
for ch in root:
|
||||
if ch.tag == "text":
|
||||
errors.append(ch.text)
|
||||
return errors
|
||||
except ET.ParseError:
|
||||
return None
|
||||
|
||||
def make_artist_credit(artists):
|
||||
names = []
|
||||
for artist in artists:
|
||||
if isinstance(artist, dict):
|
||||
if "name" in artist:
|
||||
names.append(artist.get("name", ""))
|
||||
else:
|
||||
names.append(artist.get("artist", {}).get("name", ""))
|
||||
else:
|
||||
names.append(artist)
|
||||
return "".join(names)
|
||||
|
||||
def parse_elements(valid_els, inner_els, element):
|
||||
""" Extract single level subelements from an element.
|
||||
For example, given the element:
|
||||
<element>
|
||||
<subelement>Text</subelement>
|
||||
</element>
|
||||
and a list valid_els that contains "subelement",
|
||||
return a dict {'subelement': 'Text'}
|
||||
|
||||
Delegate the parsing of multi-level subelements to another function.
|
||||
For example, given the element:
|
||||
<element>
|
||||
<subelement>
|
||||
<a>Foo</a><b>Bar</b>
|
||||
</subelement>
|
||||
</element>
|
||||
and a dictionary {'subelement': parse_subelement},
|
||||
call parse_subelement(<subelement>) and
|
||||
return a dict {'subelement': <result>}
|
||||
if parse_subelement returns a tuple of the form
|
||||
(True, {'subelement-key': <result>})
|
||||
then merge the second element of the tuple into the
|
||||
result (which may have a key other than 'subelement' or
|
||||
more than 1 key)
|
||||
"""
|
||||
result = {}
|
||||
for sub in element:
|
||||
t = fixtag(sub.tag, NS_MAP)[0]
|
||||
if ":" in t:
|
||||
t = t.split(":")[1]
|
||||
if t in valid_els:
|
||||
result[t] = sub.text or ""
|
||||
elif t in inner_els.keys():
|
||||
inner_result = inner_els[t](sub)
|
||||
if isinstance(inner_result, tuple) and inner_result[0]:
|
||||
result.update(inner_result[1])
|
||||
else:
|
||||
result[t] = inner_result
|
||||
# add counts for lists when available
|
||||
m = re.match(r'([a-z0-9-]+)-list', t)
|
||||
if m and "count" in sub.attrib:
|
||||
result["%s-count" % m.group(1)] = int(sub.attrib["count"])
|
||||
else:
|
||||
_log.info("in <%s>, uncaught <%s>",
|
||||
fixtag(element.tag, NS_MAP)[0], t)
|
||||
return result
|
||||
|
||||
def parse_attributes(attributes, element):
|
||||
""" Extract attributes from an element.
|
||||
For example, given the element:
|
||||
<element type="Group" />
|
||||
and a list attributes that contains "type",
|
||||
return a dict {'type': 'Group'}
|
||||
"""
|
||||
result = {}
|
||||
for attr in element.attrib:
|
||||
if "{" in attr:
|
||||
a = fixtag(attr, NS_MAP)[0]
|
||||
else:
|
||||
a = attr
|
||||
if a in attributes:
|
||||
result[a] = element.attrib[attr]
|
||||
else:
|
||||
_log.info("in <%s>, uncaught attribute %s", fixtag(element.tag, NS_MAP)[0], attr)
|
||||
|
||||
return result
|
||||
|
||||
def parse_message(message):
|
||||
tree = util.bytes_to_elementtree(message)
|
||||
root = tree.getroot()
|
||||
result = {}
|
||||
valid_elements = {"area": parse_area,
|
||||
"artist": parse_artist,
|
||||
"instrument": parse_instrument,
|
||||
"label": parse_label,
|
||||
"place": parse_place,
|
||||
"event": parse_event,
|
||||
"release": parse_release,
|
||||
"release-group": parse_release_group,
|
||||
"series": parse_series,
|
||||
"recording": parse_recording,
|
||||
"work": parse_work,
|
||||
"url": parse_url,
|
||||
|
||||
"disc": parse_disc,
|
||||
"cdstub": parse_cdstub,
|
||||
"isrc": parse_isrc,
|
||||
|
||||
"annotation-list": parse_annotation_list,
|
||||
"area-list": parse_area_list,
|
||||
"artist-list": parse_artist_list,
|
||||
"label-list": parse_label_list,
|
||||
"place-list": parse_place_list,
|
||||
"event-list": parse_event_list,
|
||||
"instrument-list": parse_instrument_list,
|
||||
"release-list": parse_release_list,
|
||||
"release-group-list": parse_release_group_list,
|
||||
"series-list": parse_series_list,
|
||||
"recording-list": parse_recording_list,
|
||||
"work-list": parse_work_list,
|
||||
"url-list": parse_url_list,
|
||||
|
||||
"collection-list": parse_collection_list,
|
||||
"collection": parse_collection,
|
||||
|
||||
"message": parse_response_message
|
||||
}
|
||||
result.update(parse_elements([], valid_elements, root))
|
||||
return result
|
||||
|
||||
def parse_response_message(message):
|
||||
return parse_elements(["text"], {}, message)
|
||||
|
||||
def parse_collection_list(cl):
|
||||
return [parse_collection(c) for c in cl]
|
||||
|
||||
def parse_collection(collection):
|
||||
result = {}
|
||||
attribs = ["id", "type", "entity-type"]
|
||||
elements = ["name", "editor"]
|
||||
inner_els = {"release-list": parse_release_list,
|
||||
"artist-list": parse_artist_list,
|
||||
"event-list": parse_event_list,
|
||||
"place-list": parse_place_list,
|
||||
"recording-list": parse_recording_list,
|
||||
"work-list": parse_work_list}
|
||||
result.update(parse_attributes(attribs, collection))
|
||||
result.update(parse_elements(elements, inner_els, collection))
|
||||
|
||||
return result
|
||||
|
||||
def parse_annotation_list(al):
|
||||
return [parse_annotation(a) for a in al]
|
||||
|
||||
def parse_annotation(annotation):
|
||||
result = {}
|
||||
attribs = ["type", "ext:score"]
|
||||
elements = ["entity", "name", "text"]
|
||||
result.update(parse_attributes(attribs, annotation))
|
||||
result.update(parse_elements(elements, {}, annotation))
|
||||
return result
|
||||
|
||||
def parse_lifespan(lifespan):
|
||||
parts = parse_elements(["begin", "end", "ended"], {}, lifespan)
|
||||
|
||||
return parts
|
||||
|
||||
def parse_area_list(al):
|
||||
return [parse_area(a) for a in al]
|
||||
|
||||
def parse_area(area):
|
||||
result = {}
|
||||
attribs = ["id", "type", "ext:score"]
|
||||
elements = ["name", "sort-name", "disambiguation"]
|
||||
inner_els = {"life-span": parse_lifespan,
|
||||
"alias-list": parse_alias_list,
|
||||
"relation-list": parse_relation_list,
|
||||
"annotation": parse_annotation,
|
||||
"iso-3166-1-code-list": parse_element_list,
|
||||
"iso-3166-2-code-list": parse_element_list,
|
||||
"iso-3166-3-code-list": parse_element_list}
|
||||
|
||||
result.update(parse_attributes(attribs, area))
|
||||
result.update(parse_elements(elements, inner_els, area))
|
||||
|
||||
return result
|
||||
|
||||
def parse_artist_list(al):
|
||||
return [parse_artist(a) for a in al]
|
||||
|
||||
def parse_artist(artist):
|
||||
result = {}
|
||||
attribs = ["id", "type", "ext:score"]
|
||||
elements = ["name", "sort-name", "country", "user-rating",
|
||||
"disambiguation", "gender", "ipi"]
|
||||
inner_els = {"area": parse_area,
|
||||
"begin-area": parse_area,
|
||||
"end-area": parse_area,
|
||||
"life-span": parse_lifespan,
|
||||
"recording-list": parse_recording_list,
|
||||
"relation-list": parse_relation_list,
|
||||
"release-list": parse_release_list,
|
||||
"release-group-list": parse_release_group_list,
|
||||
"work-list": parse_work_list,
|
||||
"tag-list": parse_tag_list,
|
||||
"user-tag-list": parse_tag_list,
|
||||
"rating": parse_rating,
|
||||
"ipi-list": parse_element_list,
|
||||
"isni-list": parse_element_list,
|
||||
"alias-list": parse_alias_list,
|
||||
"annotation": parse_annotation}
|
||||
|
||||
result.update(parse_attributes(attribs, artist))
|
||||
result.update(parse_elements(elements, inner_els, artist))
|
||||
|
||||
return result
|
||||
|
||||
def parse_coordinates(c):
|
||||
return parse_elements(['latitude', 'longitude'], {}, c)
|
||||
|
||||
def parse_place_list(pl):
|
||||
return [parse_place(p) for p in pl]
|
||||
|
||||
def parse_place(place):
|
||||
result = {}
|
||||
attribs = ["id", "type", "ext:score"]
|
||||
elements = ["name", "address",
|
||||
"ipi", "disambiguation"]
|
||||
inner_els = {"area": parse_area,
|
||||
"coordinates": parse_coordinates,
|
||||
"life-span": parse_lifespan,
|
||||
"tag-list": parse_tag_list,
|
||||
"user-tag-list": parse_tag_list,
|
||||
"alias-list": parse_alias_list,
|
||||
"relation-list": parse_relation_list,
|
||||
"annotation": parse_annotation}
|
||||
|
||||
result.update(parse_attributes(attribs, place))
|
||||
result.update(parse_elements(elements, inner_els, place))
|
||||
|
||||
return result
|
||||
|
||||
def parse_event_list(el):
|
||||
return [parse_event(e) for e in el]
|
||||
|
||||
def parse_event(event):
|
||||
result = {}
|
||||
attribs = ["id", "type", "ext:score"]
|
||||
elements = ["name", "time", "setlist", "cancelled", "disambiguation", "user-rating"]
|
||||
inner_els = {"life-span": parse_lifespan,
|
||||
"relation-list": parse_relation_list,
|
||||
"alias-list": parse_alias_list,
|
||||
"tag-list": parse_tag_list,
|
||||
"user-tag-list": parse_tag_list,
|
||||
"rating": parse_rating}
|
||||
|
||||
result.update(parse_attributes(attribs, event))
|
||||
result.update(parse_elements(elements, inner_els, event))
|
||||
|
||||
return result
|
||||
|
||||
def parse_instrument(instrument):
|
||||
result = {}
|
||||
attribs = ["id", "type", "ext:score"]
|
||||
elements = ["name", "description", "disambiguation"]
|
||||
inner_els = {"relation-list": parse_relation_list,
|
||||
"tag-list": parse_tag_list,
|
||||
"alias-list": parse_alias_list,
|
||||
"annotation": parse_annotation}
|
||||
result.update(parse_attributes(attribs, instrument))
|
||||
result.update(parse_elements(elements, inner_els, instrument))
|
||||
|
||||
return result
|
||||
|
||||
def parse_label_list(ll):
|
||||
return [parse_label(l) for l in ll]
|
||||
|
||||
def parse_label(label):
|
||||
result = {}
|
||||
attribs = ["id", "type", "ext:score"]
|
||||
elements = ["name", "sort-name", "country", "label-code", "user-rating",
|
||||
"ipi", "disambiguation"]
|
||||
inner_els = {"area": parse_area,
|
||||
"life-span": parse_lifespan,
|
||||
"release-list": parse_release_list,
|
||||
"tag-list": parse_tag_list,
|
||||
"user-tag-list": parse_tag_list,
|
||||
"rating": parse_rating,
|
||||
"ipi-list": parse_element_list,
|
||||
"alias-list": parse_alias_list,
|
||||
"relation-list": parse_relation_list,
|
||||
"annotation": parse_annotation}
|
||||
|
||||
result.update(parse_attributes(attribs, label))
|
||||
result.update(parse_elements(elements, inner_els, label))
|
||||
|
||||
return result
|
||||
|
||||
def parse_relation_target(tgt):
|
||||
attributes = parse_attributes(['id'], tgt)
|
||||
if 'id' in attributes:
|
||||
return (True, {'target-id': attributes['id']})
|
||||
else:
|
||||
return (True, {'target-id': tgt.text})
|
||||
|
||||
def parse_relation_list(rl):
|
||||
attribs = ["target-type"]
|
||||
ttype = parse_attributes(attribs, rl)
|
||||
key = "%s-relation-list" % ttype["target-type"]
|
||||
return (True, {key: [parse_relation(r) for r in rl]})
|
||||
|
||||
def parse_relation(relation):
|
||||
result = {}
|
||||
attribs = ["type", "type-id"]
|
||||
elements = ["target", "direction", "begin", "end", "ended", "ordering-key"]
|
||||
inner_els = {"area": parse_area,
|
||||
"artist": parse_artist,
|
||||
"instrument": parse_instrument,
|
||||
"label": parse_label,
|
||||
"place": parse_place,
|
||||
"event": parse_event,
|
||||
"recording": parse_recording,
|
||||
"release": parse_release,
|
||||
"release-group": parse_release_group,
|
||||
"series": parse_series,
|
||||
"attribute-list": parse_element_list,
|
||||
"work": parse_work,
|
||||
"target": parse_relation_target
|
||||
}
|
||||
result.update(parse_attributes(attribs, relation))
|
||||
result.update(parse_elements(elements, inner_els, relation))
|
||||
# We parse attribute-list again to get attributes that have both
|
||||
# text and attribute values
|
||||
result.update(parse_elements(['target-credit'], {"attribute-list": parse_relation_attribute_list}, relation))
|
||||
|
||||
return result
|
||||
|
||||
def parse_relation_attribute_list(attributelist):
|
||||
ret = []
|
||||
for attribute in attributelist:
|
||||
ret.append(parse_relation_attribute_element(attribute))
|
||||
return (True, {"attributes": ret})
|
||||
|
||||
def parse_relation_attribute_element(element):
|
||||
# Parses an attribute into a dictionary containing an element
|
||||
# {"attribute": <text value>} and also an additional element
|
||||
# containing any xml attributes.
|
||||
# e.g <attribute value="BuxWV 1">number</attribute>
|
||||
# -> {"attribute": "number", "value": "BuxWV 1"}
|
||||
result = {}
|
||||
for attr in element.attrib:
|
||||
if "{" in attr:
|
||||
a = fixtag(attr, NS_MAP)[0]
|
||||
else:
|
||||
a = attr
|
||||
result[a] = element.attrib[attr]
|
||||
result["attribute"] = element.text
|
||||
return result
|
||||
|
||||
def parse_release(release):
|
||||
result = {}
|
||||
attribs = ["id", "ext:score"]
|
||||
elements = ["title", "status", "disambiguation", "quality", "country",
|
||||
"barcode", "date", "packaging", "asin"]
|
||||
inner_els = {"text-representation": parse_text_representation,
|
||||
"artist-credit": parse_artist_credit,
|
||||
"label-info-list": parse_label_info_list,
|
||||
"medium-list": parse_medium_list,
|
||||
"release-group": parse_release_group,
|
||||
"tag-list": parse_tag_list,
|
||||
"user-tag-list": parse_tag_list,
|
||||
"relation-list": parse_relation_list,
|
||||
"annotation": parse_annotation,
|
||||
"cover-art-archive": parse_caa,
|
||||
"release-event-list": parse_release_event_list}
|
||||
|
||||
result.update(parse_attributes(attribs, release))
|
||||
result.update(parse_elements(elements, inner_els, release))
|
||||
if "artist-credit" in result:
|
||||
result["artist-credit-phrase"] = make_artist_credit(
|
||||
result["artist-credit"])
|
||||
|
||||
return result
|
||||
|
||||
def parse_medium_list(ml):
|
||||
"""medium-list results from search have an additional
|
||||
<track-count> element containing the number of tracks
|
||||
over all mediums. Optionally add this"""
|
||||
medium_list = []
|
||||
track_count = None
|
||||
for m in ml:
|
||||
tag = fixtag(m.tag, NS_MAP)[0]
|
||||
if tag == "ws2:medium":
|
||||
medium_list.append(parse_medium(m))
|
||||
elif tag == "ws2:track-count":
|
||||
track_count = int(m.text)
|
||||
ret = {"medium-list": medium_list}
|
||||
if track_count is not None:
|
||||
ret["medium-track-count"] = track_count
|
||||
|
||||
return (True, ret)
|
||||
|
||||
def parse_release_event_list(rel):
|
||||
return [parse_release_event(re) for re in rel]
|
||||
|
||||
def parse_release_event(event):
|
||||
result = {}
|
||||
elements = ["date"]
|
||||
inner_els = {"area": parse_area}
|
||||
|
||||
result.update(parse_elements(elements, inner_els, event))
|
||||
return result
|
||||
|
||||
def parse_medium(medium):
|
||||
result = {}
|
||||
elements = ["position", "format", "title"]
|
||||
inner_els = {"disc-list": parse_disc_list,
|
||||
"pregap": parse_track,
|
||||
"track-list": parse_track_list,
|
||||
"data-track-list": parse_track_list}
|
||||
|
||||
result.update(parse_elements(elements, inner_els, medium))
|
||||
return result
|
||||
|
||||
def parse_disc_list(dl):
|
||||
return [parse_disc(d) for d in dl]
|
||||
|
||||
def parse_text_representation(textr):
|
||||
return parse_elements(["language", "script"], {}, textr)
|
||||
|
||||
def parse_release_group(rg):
|
||||
result = {}
|
||||
attribs = ["id", "type", "ext:score"]
|
||||
elements = ["title", "user-rating", "first-release-date", "primary-type",
|
||||
"disambiguation"]
|
||||
inner_els = {"artist-credit": parse_artist_credit,
|
||||
"release-list": parse_release_list,
|
||||
"tag-list": parse_tag_list,
|
||||
"user-tag-list": parse_tag_list,
|
||||
"secondary-type-list": parse_element_list,
|
||||
"relation-list": parse_relation_list,
|
||||
"rating": parse_rating,
|
||||
"annotation": parse_annotation}
|
||||
|
||||
result.update(parse_attributes(attribs, rg))
|
||||
result.update(parse_elements(elements, inner_els, rg))
|
||||
if "artist-credit" in result:
|
||||
result["artist-credit-phrase"] = make_artist_credit(result["artist-credit"])
|
||||
|
||||
return result
|
||||
|
||||
def parse_recording(recording):
|
||||
result = {}
|
||||
attribs = ["id", "ext:score"]
|
||||
elements = ["title", "length", "user-rating", "disambiguation", "video"]
|
||||
inner_els = {"artist-credit": parse_artist_credit,
|
||||
"release-list": parse_release_list,
|
||||
"tag-list": parse_tag_list,
|
||||
"user-tag-list": parse_tag_list,
|
||||
"rating": parse_rating,
|
||||
"isrc-list": parse_external_id_list,
|
||||
"relation-list": parse_relation_list,
|
||||
"annotation": parse_annotation}
|
||||
|
||||
result.update(parse_attributes(attribs, recording))
|
||||
result.update(parse_elements(elements, inner_els, recording))
|
||||
if "artist-credit" in result:
|
||||
result["artist-credit-phrase"] = make_artist_credit(result["artist-credit"])
|
||||
|
||||
return result
|
||||
|
||||
def parse_series_list(sl):
|
||||
return [parse_series(s) for s in sl]
|
||||
|
||||
def parse_series(series):
|
||||
result = {}
|
||||
attribs = ["id", "type", "ext:score"]
|
||||
elements = ["name", "disambiguation"]
|
||||
inner_els = {"alias-list": parse_alias_list,
|
||||
"relation-list": parse_relation_list,
|
||||
"annotation": parse_annotation}
|
||||
|
||||
result.update(parse_attributes(attribs, series))
|
||||
result.update(parse_elements(elements, inner_els, series))
|
||||
|
||||
return result
|
||||
|
||||
def parse_external_id_list(pl):
|
||||
return [parse_attributes(["id"], p)["id"] for p in pl]
|
||||
|
||||
def parse_element_list(el):
|
||||
return [e.text for e in el]
|
||||
|
||||
def parse_work_list(wl):
|
||||
return [parse_work(w) for w in wl]
|
||||
|
||||
def parse_work(work):
|
||||
result = {}
|
||||
attribs = ["id", "ext:score", "type"]
|
||||
elements = ["title", "user-rating", "language", "iswc", "disambiguation"]
|
||||
inner_els = {"tag-list": parse_tag_list,
|
||||
"user-tag-list": parse_tag_list,
|
||||
"rating": parse_rating,
|
||||
"alias-list": parse_alias_list,
|
||||
"iswc-list": parse_element_list,
|
||||
"relation-list": parse_relation_list,
|
||||
"annotation": parse_response_message,
|
||||
"attribute-list": parse_work_attribute_list
|
||||
}
|
||||
|
||||
result.update(parse_attributes(attribs, work))
|
||||
result.update(parse_elements(elements, inner_els, work))
|
||||
|
||||
return result
|
||||
|
||||
def parse_work_attribute_list(wal):
|
||||
return [parse_work_attribute(wa) for wa in wal]
|
||||
|
||||
def parse_work_attribute(wa):
|
||||
attribs = ["type"]
|
||||
typeinfo = parse_attributes(attribs, wa)
|
||||
result = {}
|
||||
if typeinfo:
|
||||
result = {"attribute": typeinfo["type"],
|
||||
"value": wa.text}
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def parse_url_list(ul):
|
||||
return [parse_url(u) for u in ul]
|
||||
|
||||
def parse_url(url):
|
||||
result = {}
|
||||
attribs = ["id"]
|
||||
elements = ["resource"]
|
||||
inner_els = {"relation-list": parse_relation_list}
|
||||
|
||||
result.update(parse_attributes(attribs, url))
|
||||
result.update(parse_elements(elements, inner_els, url))
|
||||
|
||||
return result
|
||||
|
||||
def parse_disc(disc):
|
||||
result = {}
|
||||
attribs = ["id"]
|
||||
elements = ["sectors"]
|
||||
inner_els = {"release-list": parse_release_list,
|
||||
"offset-list": parse_offset_list
|
||||
}
|
||||
|
||||
result.update(parse_attributes(attribs, disc))
|
||||
result.update(parse_elements(elements, inner_els, disc))
|
||||
|
||||
return result
|
||||
|
||||
def parse_cdstub(cdstub):
|
||||
result = {}
|
||||
attribs = ["id"]
|
||||
elements = ["title", "artist", "barcode"]
|
||||
inner_els = {"track-list": parse_track_list}
|
||||
|
||||
result.update(parse_attributes(attribs, cdstub))
|
||||
result.update(parse_elements(elements, inner_els, cdstub))
|
||||
|
||||
return result
|
||||
|
||||
def parse_offset_list(ol):
|
||||
return [int(o.text) for o in ol]
|
||||
|
||||
def parse_instrument_list(rl):
|
||||
result = []
|
||||
for r in rl:
|
||||
result.append(parse_instrument(r))
|
||||
return result
|
||||
|
||||
def parse_release_list(rl):
|
||||
result = []
|
||||
for r in rl:
|
||||
result.append(parse_release(r))
|
||||
return result
|
||||
|
||||
def parse_release_group_list(rgl):
|
||||
result = []
|
||||
for rg in rgl:
|
||||
result.append(parse_release_group(rg))
|
||||
return result
|
||||
|
||||
def parse_isrc(isrc):
|
||||
result = {}
|
||||
attribs = ["id"]
|
||||
inner_els = {"recording-list": parse_recording_list}
|
||||
|
||||
result.update(parse_attributes(attribs, isrc))
|
||||
result.update(parse_elements([], inner_els, isrc))
|
||||
|
||||
return result
|
||||
|
||||
def parse_recording_list(recs):
|
||||
result = []
|
||||
for r in recs:
|
||||
result.append(parse_recording(r))
|
||||
return result
|
||||
|
||||
def parse_artist_credit(ac):
|
||||
result = []
|
||||
for namecredit in ac:
|
||||
result.append(parse_name_credit(namecredit))
|
||||
join = parse_attributes(["joinphrase"], namecredit)
|
||||
if "joinphrase" in join:
|
||||
result.append(join["joinphrase"])
|
||||
return result
|
||||
|
||||
def parse_name_credit(nc):
|
||||
result = {}
|
||||
elements = ["name"]
|
||||
inner_els = {"artist": parse_artist}
|
||||
|
||||
result.update(parse_elements(elements, inner_els, nc))
|
||||
|
||||
return result
|
||||
|
||||
def parse_label_info_list(lil):
|
||||
result = []
|
||||
|
||||
for li in lil:
|
||||
result.append(parse_label_info(li))
|
||||
return result
|
||||
|
||||
def parse_label_info(li):
|
||||
result = {}
|
||||
elements = ["catalog-number"]
|
||||
inner_els = {"label": parse_label}
|
||||
|
||||
result.update(parse_elements(elements, inner_els, li))
|
||||
return result
|
||||
|
||||
def parse_track_list(tl):
|
||||
result = []
|
||||
for t in tl:
|
||||
result.append(parse_track(t))
|
||||
return result
|
||||
|
||||
def parse_track(track):
|
||||
result = {}
|
||||
attribs = ["id"]
|
||||
elements = ["number", "position", "title", "length"]
|
||||
inner_els = {"recording": parse_recording,
|
||||
"artist-credit": parse_artist_credit}
|
||||
|
||||
result.update(parse_attributes(attribs, track))
|
||||
result.update(parse_elements(elements, inner_els, track))
|
||||
if "artist-credit" in result.get("recording", {}) and "artist-credit" not in result:
|
||||
result["artist-credit"] = result["recording"]["artist-credit"]
|
||||
if "artist-credit" in result:
|
||||
result["artist-credit-phrase"] = make_artist_credit(result["artist-credit"])
|
||||
# Make a length field that contains track length or recording length
|
||||
track_or_recording = None
|
||||
if "length" in result:
|
||||
track_or_recording = result["length"]
|
||||
elif result.get("recording", {}).get("length"):
|
||||
track_or_recording = result.get("recording", {}).get("length")
|
||||
if track_or_recording:
|
||||
result["track_or_recording_length"] = track_or_recording
|
||||
return result
|
||||
|
||||
def parse_tag_list(tl):
|
||||
return [parse_tag(t) for t in tl]
|
||||
|
||||
def parse_tag(tag):
|
||||
result = {}
|
||||
attribs = ["count"]
|
||||
elements = ["name"]
|
||||
|
||||
result.update(parse_attributes(attribs, tag))
|
||||
result.update(parse_elements(elements, {}, tag))
|
||||
|
||||
return result
|
||||
|
||||
def parse_rating(rating):
|
||||
result = {}
|
||||
attribs = ["votes-count"]
|
||||
|
||||
result.update(parse_attributes(attribs, rating))
|
||||
result["rating"] = rating.text
|
||||
|
||||
return result
|
||||
|
||||
def parse_alias_list(al):
|
||||
return [parse_alias(a) for a in al]
|
||||
|
||||
def parse_alias(alias):
|
||||
result = {}
|
||||
attribs = ["locale", "sort-name", "type", "primary",
|
||||
"begin-date", "end-date"]
|
||||
|
||||
result.update(parse_attributes(attribs, alias))
|
||||
result["alias"] = alias.text
|
||||
|
||||
return result
|
||||
|
||||
def parse_caa(caa_element):
|
||||
result = {}
|
||||
elements = ["artwork", "count", "front", "back", "darkened"]
|
||||
|
||||
result.update(parse_elements(elements, {}, caa_element))
|
||||
return result
|
||||
|
||||
|
||||
###
|
||||
|
||||
def make_barcode_request(release2barcode):
|
||||
NS = "http://musicbrainz.org/ns/mmd-2.0#"
|
||||
root = ET.Element("{%s}metadata" % NS)
|
||||
rel_list = ET.SubElement(root, "{%s}release-list" % NS)
|
||||
for release, barcode in release2barcode.items():
|
||||
rel_xml = ET.SubElement(rel_list, "{%s}release" % NS)
|
||||
bar_xml = ET.SubElement(rel_xml, "{%s}barcode" % NS)
|
||||
rel_xml.set("{%s}id" % NS, release)
|
||||
bar_xml.text = barcode
|
||||
|
||||
return ET.tostring(root, "utf-8")
|
||||
|
||||
def make_tag_request(**kwargs):
|
||||
NS = "http://musicbrainz.org/ns/mmd-2.0#"
|
||||
root = ET.Element("{%s}metadata" % NS)
|
||||
for entity_type in ['artist', 'label', 'place', 'recording', 'release', 'release_group', 'work']:
|
||||
entity_tags = kwargs.pop(entity_type + '_tags', None)
|
||||
if entity_tags is not None:
|
||||
e_list = ET.SubElement(root, "{%s}%s-list" % (NS, entity_type.replace('_', '-')))
|
||||
for e, tags in entity_tags.items():
|
||||
e_xml = ET.SubElement(e_list, "{%s}%s" % (NS, entity_type.replace('_', '-')))
|
||||
e_xml.set("{%s}id" % NS, e)
|
||||
taglist = ET.SubElement(e_xml, "{%s}user-tag-list" % NS)
|
||||
for tag in tags:
|
||||
usertag_xml = ET.SubElement(taglist, "{%s}user-tag" % NS)
|
||||
name_xml = ET.SubElement(usertag_xml, "{%s}name" % NS)
|
||||
name_xml.text = tag
|
||||
if kwargs.keys():
|
||||
raise TypeError("make_tag_request() got an unexpected keyword argument '%s'" % kwargs.popitem()[0])
|
||||
|
||||
return ET.tostring(root, "utf-8")
|
||||
|
||||
def make_rating_request(**kwargs):
|
||||
NS = "http://musicbrainz.org/ns/mmd-2.0#"
|
||||
root = ET.Element("{%s}metadata" % NS)
|
||||
for entity_type in ['artist', 'label', 'recording', 'release_group', 'work']:
|
||||
entity_ratings = kwargs.pop(entity_type + '_ratings', None)
|
||||
if entity_ratings is not None:
|
||||
e_list = ET.SubElement(root, "{%s}%s-list" % (NS, entity_type.replace('_', '-')))
|
||||
for e, rating in entity_ratings.items():
|
||||
e_xml = ET.SubElement(e_list, "{%s}%s" % (NS, entity_type.replace('_', '-')))
|
||||
e_xml.set("{%s}id" % NS, e)
|
||||
rating_xml = ET.SubElement(e_xml, "{%s}user-rating" % NS)
|
||||
rating_xml.text = str(rating)
|
||||
if kwargs.keys():
|
||||
raise TypeError("make_rating_request() got an unexpected keyword argument '%s'" % kwargs.popitem()[0])
|
||||
|
||||
return ET.tostring(root, "utf-8")
|
||||
|
||||
def make_isrc_request(recording2isrcs):
|
||||
NS = "http://musicbrainz.org/ns/mmd-2.0#"
|
||||
root = ET.Element("{%s}metadata" % NS)
|
||||
rec_list = ET.SubElement(root, "{%s}recording-list" % NS)
|
||||
for rec, isrcs in recording2isrcs.items():
|
||||
if len(isrcs) > 0:
|
||||
rec_xml = ET.SubElement(rec_list, "{%s}recording" % NS)
|
||||
rec_xml.set("{%s}id" % NS, rec)
|
||||
isrc_list_xml = ET.SubElement(rec_xml, "{%s}isrc-list" % NS)
|
||||
isrc_list_xml.set("{%s}count" % NS, str(len(isrcs)))
|
||||
for isrc in isrcs:
|
||||
isrc_xml = ET.SubElement(isrc_list_xml, "{%s}isrc" % NS)
|
||||
isrc_xml.set("{%s}id" % NS, isrc)
|
||||
return ET.tostring(root, "utf-8")
|
1312
lib/musicbrainzngs/musicbrainz.py
Normal file
1312
lib/musicbrainzngs/musicbrainz.py
Normal file
File diff suppressed because it is too large
Load Diff
44
lib/musicbrainzngs/util.py
Normal file
44
lib/musicbrainzngs/util.py
Normal file
@@ -0,0 +1,44 @@
|
||||
# This file is part of the musicbrainzngs library
|
||||
# Copyright (C) Alastair Porter, Adrian Sampson, and others
|
||||
# This file is distributed under a BSD-2-Clause type license.
|
||||
# See the COPYING file for more information.
|
||||
|
||||
import sys
|
||||
import locale
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
from . import compat
|
||||
|
||||
def _unicode(string, encoding=None):
|
||||
"""Try to decode byte strings to unicode.
|
||||
This can only be a guess, but this might be better than failing.
|
||||
It is safe to use this on numbers or strings that are already unicode.
|
||||
"""
|
||||
if isinstance(string, compat.unicode):
|
||||
unicode_string = string
|
||||
elif isinstance(string, compat.bytes):
|
||||
# use given encoding, stdin, preferred until something != None is found
|
||||
if encoding is None:
|
||||
encoding = sys.stdin.encoding
|
||||
if encoding is None:
|
||||
encoding = locale.getpreferredencoding()
|
||||
unicode_string = string.decode(encoding, "ignore")
|
||||
else:
|
||||
unicode_string = compat.unicode(string)
|
||||
return unicode_string.replace('\x00', '').strip()
|
||||
|
||||
def bytes_to_elementtree(bytes_or_file):
|
||||
"""Given a bytestring or a file-like object that will produce them,
|
||||
parse and return an ElementTree.
|
||||
"""
|
||||
if isinstance(bytes_or_file, compat.basestring):
|
||||
s = bytes_or_file
|
||||
else:
|
||||
s = bytes_or_file.read()
|
||||
|
||||
if compat.is_py3:
|
||||
s = _unicode(s, "utf-8")
|
||||
|
||||
f = compat.StringIO(s)
|
||||
tree = ET.ElementTree(file=f)
|
||||
return tree
|
@@ -22,8 +22,8 @@ from pytz.tzfile import build_tzinfo
|
||||
|
||||
|
||||
# The IANA (nee Olson) database is updated several times a year.
|
||||
OLSON_VERSION = '2019a'
|
||||
VERSION = '2019.1' # pip compatible version number.
|
||||
OLSON_VERSION = '2019c'
|
||||
VERSION = '2019.3' # pip compatible version number.
|
||||
__version__ = VERSION
|
||||
|
||||
OLSEN_VERSION = OLSON_VERSION # Old releases had this misspelling
|
||||
@@ -188,8 +188,14 @@ def _unmunge_zone(zone):
|
||||
return zone.replace('_plus_', '+').replace('_minus_', '-')
|
||||
|
||||
|
||||
_all_timezones_lower_to_standard = None
|
||||
|
||||
|
||||
def _case_insensitive_zone_lookup(zone):
|
||||
"""case-insensitively matching timezone, else return zone unchanged"""
|
||||
global _all_timezones_lower_to_standard
|
||||
if _all_timezones_lower_to_standard is None:
|
||||
_all_timezones_lower_to_standard = dict((tz.lower(), tz) for tz in all_timezones) # noqa
|
||||
return _all_timezones_lower_to_standard.get(zone.lower()) or zone # noqa
|
||||
|
||||
|
||||
@@ -1098,7 +1104,6 @@ all_timezones = LazyList(
|
||||
tz for tz in all_timezones if resource_exists(tz))
|
||||
|
||||
all_timezones_set = LazySet(all_timezones)
|
||||
_all_timezones_lower_to_standard = dict((tz.lower(), tz) for tz in all_timezones)
|
||||
common_timezones = \
|
||||
['Africa/Abidjan',
|
||||
'Africa/Accra',
|
||||
|
@@ -27,8 +27,8 @@ from pytz.tzinfo import DstTzInfo, StaticTzInfo # noqa
|
||||
|
||||
# I test for expected version to ensure the correct version of pytz is
|
||||
# actually being tested.
|
||||
EXPECTED_VERSION = '2019.1'
|
||||
EXPECTED_OLSON_VERSION = '2019a'
|
||||
EXPECTED_VERSION = '2019.3'
|
||||
EXPECTED_OLSON_VERSION = '2019c'
|
||||
|
||||
fmt = '%Y-%m-%d %H:%M:%S %Z%z'
|
||||
|
||||
@@ -183,8 +183,14 @@ class PicklingTest(unittest.TestCase):
|
||||
# Python 3 introduced a new pickle protocol where numbers are stored in
|
||||
# hexadecimal representation. Here we extract the pickle
|
||||
# representation of the number for the current Python version.
|
||||
old_pickle_pattern = pickle.dumps(tz._utcoffset.seconds)[3:-1]
|
||||
new_pickle_pattern = pickle.dumps(new_utcoffset)[3:-1]
|
||||
#
|
||||
# Test protocol 3 on Python 3 and protocol 0 on Python 2.
|
||||
if sys.version_info >= (3,):
|
||||
protocol = 3
|
||||
else:
|
||||
protocol = 0
|
||||
old_pickle_pattern = pickle.dumps(tz._utcoffset.seconds, protocol)[3:-1]
|
||||
new_pickle_pattern = pickle.dumps(new_utcoffset, protocol)[3:-1]
|
||||
hacked_p = p.replace(old_pickle_pattern, new_pickle_pattern)
|
||||
|
||||
self.assertNotEqual(p, hacked_p)
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user