mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +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):
|
def set_apikeys(**keys):
|
||||||
apikeystore.update(keys)
|
apikeystore.update(keys)
|
||||||
|
|
||||||
|
@api.post("import")
|
||||||
|
@authenticated_api
|
||||||
|
def import_scrobbles(identifier):
|
||||||
|
from ..thirdparty import import_scrobbles
|
||||||
|
import_scrobbles(identifier)
|
||||||
|
|
||||||
@api.get("backup")
|
@api.get("backup")
|
||||||
@authenticated_api
|
@authenticated_api
|
||||||
def get_backup(**keys):
|
def get_backup(**keys):
|
||||||
|
@ -2,7 +2,7 @@ from .. import database_packed
|
|||||||
from . import filters
|
from . import filters
|
||||||
from ..globalconf import malojaconfig
|
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
|
from doreah.regular import repeatdaily
|
||||||
|
|
||||||
import urllib
|
import urllib
|
||||||
@ -31,6 +31,7 @@ def update_jinja_environment():
|
|||||||
"utilities": utilities,
|
"utilities": utilities,
|
||||||
"mlj_uri": malojauri,
|
"mlj_uri": malojauri,
|
||||||
"settings": malojaconfig,
|
"settings": malojaconfig,
|
||||||
|
"thirdparty": thirdparty,
|
||||||
# external
|
# external
|
||||||
"urllib": urllib,
|
"urllib": urllib,
|
||||||
"math":math,
|
"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 doreah.logging import log
|
||||||
|
|
||||||
from ..globalconf import malojaconfig
|
from ..globalconf import malojaconfig
|
||||||
|
from .. import database
|
||||||
|
|
||||||
|
|
||||||
services = {
|
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):
|
def proxy_scrobble_all(artists,title,timestamp):
|
||||||
for service in services["proxyscrobble"]:
|
for service in services["proxyscrobble"]:
|
||||||
service.scrobble(artists,title,timestamp)
|
service.scrobble(artists,title,timestamp)
|
||||||
@ -140,10 +147,15 @@ class ImportInterface(GenericInterface,abstract=True):
|
|||||||
# necessary auth settings exist
|
# necessary auth settings exist
|
||||||
def active_import(self):
|
def active_import(self):
|
||||||
return (
|
return (
|
||||||
all(self.settings[key] not in [None,"ASK",False] for key in self.scrobbleimport["required_settings"]) and
|
all(self.settings[key] not in [None,"ASK",False] for key in self.scrobbleimport["required_settings"])
|
||||||
malojaconfig[self.scrobbleimport["activated_setting"]]
|
#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
|
# metadata
|
||||||
class MetadataInterface(GenericInterface,abstract=True):
|
class MetadataInterface(GenericInterface,abstract=True):
|
||||||
|
@ -22,7 +22,8 @@
|
|||||||
['settings','Settings'],
|
['settings','Settings'],
|
||||||
['apikeys','API Keys'],
|
['apikeys','API Keys'],
|
||||||
['manual','Manual Scrobbling'],
|
['manual','Manual Scrobbling'],
|
||||||
['issues','Database Maintenance']
|
['issues','Database Maintenance'],
|
||||||
|
['import','Scrobble Import']
|
||||||
] %}
|
] %}
|
||||||
{% if page=='admin_' + tab_url %}
|
{% if page=='admin_' + tab_url %}
|
||||||
<span style="opacity:0.5;">{{ tab_name }}</span>
|
<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