mirror of
https://github.com/krateng/maloja.git
synced 2025-04-16 00:40:32 +03:00
Implemented initial support for importing scrobbles
This commit is contained in:
parent
b8fc3db371
commit
e62c637aa0
@ -337,6 +337,12 @@ def set_settings(**keys):
|
||||
def set_apikeys(**keys):
|
||||
apikeystore.update(keys)
|
||||
|
||||
@api.post("import")
|
||||
@authenticated_api
|
||||
def import_scrobbles(identifier):
|
||||
from ..thirdparty import import_scrobbles
|
||||
import_scrobbles(identifier)
|
||||
|
||||
@api.get("backup")
|
||||
@authenticated_api
|
||||
def get_backup(**keys):
|
||||
|
@ -2,7 +2,7 @@ from .. import database_packed
|
||||
from . import filters
|
||||
from ..globalconf import malojaconfig
|
||||
|
||||
from .. import database, database_packed, malojatime, utilities, malojauri
|
||||
from .. import database, database_packed, malojatime, utilities, malojauri, thirdparty
|
||||
from doreah.regular import repeatdaily
|
||||
|
||||
import urllib
|
||||
@ -31,6 +31,7 @@ def update_jinja_environment():
|
||||
"utilities": utilities,
|
||||
"mlj_uri": malojauri,
|
||||
"settings": malojaconfig,
|
||||
"thirdparty": thirdparty,
|
||||
# external
|
||||
"urllib": urllib,
|
||||
"math":math,
|
||||
|
16
maloja/thirdparty/__init__.py
vendored
16
maloja/thirdparty/__init__.py
vendored
@ -13,6 +13,7 @@ import base64
|
||||
from doreah.logging import log
|
||||
|
||||
from ..globalconf import malojaconfig
|
||||
from .. import database
|
||||
|
||||
|
||||
services = {
|
||||
@ -22,6 +23,12 @@ services = {
|
||||
}
|
||||
|
||||
|
||||
def import_scrobbles(identifier):
|
||||
for service in services['import']:
|
||||
if service.identifier == identifier:
|
||||
return service.import_scrobbles()
|
||||
return False
|
||||
|
||||
def proxy_scrobble_all(artists,title,timestamp):
|
||||
for service in services["proxyscrobble"]:
|
||||
service.scrobble(artists,title,timestamp)
|
||||
@ -140,10 +147,15 @@ class ImportInterface(GenericInterface,abstract=True):
|
||||
# necessary auth settings exist
|
||||
def active_import(self):
|
||||
return (
|
||||
all(self.settings[key] not in [None,"ASK",False] for key in self.scrobbleimport["required_settings"]) and
|
||||
malojaconfig[self.scrobbleimport["activated_setting"]]
|
||||
all(self.settings[key] not in [None,"ASK",False] for key in self.scrobbleimport["required_settings"])
|
||||
#and malojaconfig[self.scrobbleimport["activated_setting"]]
|
||||
# registering as import source doesnt do anything on its own, so no need for a setting
|
||||
)
|
||||
|
||||
# wrapper so that all the inheriting classes can scrobble
|
||||
def self_scrobble(self,artists,title,timestamp):
|
||||
database.createScrobble(artists=artists,title=title,time=timestamp)
|
||||
|
||||
|
||||
# metadata
|
||||
class MetadataInterface(GenericInterface,abstract=True):
|
||||
|
@ -22,7 +22,8 @@
|
||||
['settings','Settings'],
|
||||
['apikeys','API Keys'],
|
||||
['manual','Manual Scrobbling'],
|
||||
['issues','Database Maintenance']
|
||||
['issues','Database Maintenance'],
|
||||
['import','Scrobble Import']
|
||||
] %}
|
||||
{% if page=='admin_' + tab_url %}
|
||||
<span style="opacity:0.5;">{{ tab_name }}</span>
|
||||
|
28
maloja/web/jinja/admin_import.jinja
Normal file
28
maloja/web/jinja/admin_import.jinja
Normal file
@ -0,0 +1,28 @@
|
||||
{% set page ='admin_import' %}
|
||||
{% extends "abstracts/admin.jinja" %}
|
||||
{% block title %}Maloja - Import Scrobbles{% endblock %}
|
||||
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
function import_scrobbles(identifier) {
|
||||
fetch('/apis/mlj_1/import?identifier=' + identifier,{'method':'POST'});
|
||||
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block maincontent %}
|
||||
You can import your scrobbles from other platforms. This will not overwrite scrobbles you've already made,
|
||||
unless they are deemed to be equivalent (exact same timestamp). Importing multiple times from the same
|
||||
source should also not lead to any duplicates.<br/><br/>
|
||||
|
||||
{% for importsource in thirdparty.services.import %}
|
||||
<h1>{{ importsource.name }}</h1>
|
||||
|
||||
<button type="button" onclick="import_scrobbles('{{ importsource.identifier }}')">Import</button>
|
||||
|
||||
{% endfor %}
|
||||
|
||||
{% endblock %}
|
Loading…
x
Reference in New Issue
Block a user