Skip to content

Commit

Permalink
fix pylint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
blastbeng committed Oct 29, 2024
1 parent e049739 commit c451e76
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 61 deletions.
8 changes: 4 additions & 4 deletions spotisub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
logging.basicConfig(
handlers=[
RotatingFileHandler(os.path.abspath(
os.curdir) +
os.curdir) +
"/cache/spotisub.log", maxBytes=1048576,
backupCount=5),
backupCount=5),
logging.StreamHandler()],
format='%(asctime)s %(levelname)-8s %(message)s',
level=int(
os.environ.get(constants.LOG_LEVEL,constants.LOG_LEVEL_DEFAULT_VALUE)),
os.environ.get(constants.LOG_LEVEL, constants.LOG_LEVEL_DEFAULT_VALUE)),
datefmt='%Y-%m-%d %H:%M:%S')


Expand All @@ -37,4 +37,4 @@
configuration_db = SQLAlchemy(spotisub)
login = LoginManager(spotisub)
login.login_view = 'login'
from spotisub import routes, classes, errors
from spotisub import routes, classes, errors
37 changes: 22 additions & 15 deletions spotisub/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ def __init__(self, dbtype, dbname=''):

spotify_song_artist_relation = Table(
SPOTIFY_SONG_ARTIST_RELATION, metadata, Column(
'uuid',
String(36),
primary_key=True,
nullable=False),Column(
'uuid',
String(36),
primary_key=True,
nullable=False), Column(
'song_relation_uuid', String(36), nullable=False), Column(
'artist_relation_uuid', String(36), nullable=False))

Expand Down Expand Up @@ -187,7 +187,8 @@ def __init__(self, dbtype, dbname=''):
def create_db_tables():
"""Create tables"""
dbms.metadata.create_all(dbms.db_engine)
upgrade()
#temp removed, db upgrade will be reimplemented in a future release
#upgrade()


def upgrade():
Expand Down Expand Up @@ -314,7 +315,7 @@ def insert_song(playlist_info, subsonic_track,
else:
conn.rollback()
return None

else:
conn.rollback()
return None
Expand All @@ -324,6 +325,7 @@ def insert_song(playlist_info, subsonic_track,
conn.close()
return return_dict


def create_playlist(playlist_info):
"""Create empty playlist into database"""
pl_info = None
Expand All @@ -344,7 +346,8 @@ def insert_playlist_type(conn, playlist_info):
if "uuid" in playlist_info and playlist_info["uuid"] is not None:
playlist_info_db = select_playlist_info_by_uuid_with_conn(
conn, playlist_info["uuid"])
if playlist_info_db is None and "name" in playlist_info and playlist_info["name"] is not None:
if playlist_info_db is None and "name" in playlist_info and playlist_info[
"name"] is not None:
playlist_info_db = select_playlist_info_by_name_with_conn(
conn, playlist_info["name"])
elif playlist_info_db is None and "import_arg" in playlist_info and playlist_info["import_arg"] is not None:
Expand All @@ -361,7 +364,7 @@ def insert_playlist_type(conn, playlist_info):
subsonic_playlist_id=subsonic_playlist_id_info,
subsonic_playlist_name=playlist_info["name"],
import_arg=playlist_info["import_arg"],
prefix=playlist_info["prefix"].replace( "\"", ""))
prefix=playlist_info["prefix"].replace("\"", ""))
stmt.compile()
conn.execute(stmt)
logging.info(
Expand All @@ -377,7 +380,7 @@ def insert_playlist_type(conn, playlist_info):
type=playlist_info["type"],
subsonic_playlist_id=subsonic_playlist_id_info,
subsonic_playlist_name=playlist_info["name"],
prefix=playlist_info["prefix"].replace( "\"", ""))
prefix=playlist_info["prefix"].replace("\"", ""))
stmt.compile()
conn.execute(stmt)
return select_playlist_info_by_uuid_with_conn(
Expand Down Expand Up @@ -668,7 +671,9 @@ def insert_playlist_relation(
conn.execute(stmt)
return select_playlist_relation_by_uuid(old_relation.uuid)

def select_playlist_info_by_subsonic_id_with_conn(conn, subsonic_playlist_uuid):

def select_playlist_info_by_subsonic_id_with_conn(
conn, subsonic_playlist_uuid):
"""select spotify artists by uuid"""
value = None
stmt = select(
Expand All @@ -693,6 +698,7 @@ def select_playlist_info_by_subsonic_id_with_conn(conn, subsonic_playlist_uuid):

return value


def select_playlist_info_by_subsonic_id(subsonic_playlist_uuid):
"""select spotify artists by uuid"""
value = None
Expand Down Expand Up @@ -941,7 +947,7 @@ def count_songs(

stmt = stmt.group_by(
dbms.subsonic_spotify_relation.c.spotify_song_uuid,
dbms.playlist_info.c.subsonic_playlist_name)
dbms.playlist_info.c.subsonic_playlist_name)

stmt = select(func.count()).select_from(stmt.subquery())

Expand Down Expand Up @@ -1290,7 +1296,7 @@ def limit_and_order_stmt(stmt, page=None, limit=None, order=None, asc=None):
stmt = stmt.limit(limit).offset(page * limit)
order_by = []
if order is not None:
order = "case when "+order+" is null then 1 else 0 end, "+order
order = "case when " + order + " is null then 1 else 0 end, " + order
if asc:
stmt = stmt.order_by(collate(text(order), 'NOCASE'))
else:
Expand All @@ -1311,7 +1317,8 @@ def select_songs_by_artist_uuid(
dbms.playlist_info.c.ignored.label('ignored_whole_pl'),
dbms.spotify_album.c.name.label('album_name'),
dbms.spotify_album.c.ignored.label('spotify_album_ignored'),
dbms.subsonic_spotify_relation.c.uuid.label('subsonic_spotify_relation_uuid'),
dbms.subsonic_spotify_relation.c.uuid.label(
'subsonic_spotify_relation_uuid'),
dbms.subsonic_spotify_relation.c.subsonic_song_id,
dbms.playlist_info.c.subsonic_playlist_name,
dbms.playlist_info.c.subsonic_playlist_id,
Expand Down Expand Up @@ -1374,7 +1381,7 @@ def select_count_songs_by_artist_uuid(conn, artist_uuid):
stmt = stmt.group_by(
dbms.subsonic_spotify_relation.c.spotify_song_uuid,
dbms.playlist_info.c.subsonic_playlist_name)

stmt.compile()

stmt = select(func.count()).select_from(stmt.subquery())
Expand Down Expand Up @@ -1459,7 +1466,7 @@ def select_count_songs_by_album_uuid(conn, album_uuid):
stmt = stmt.group_by(
dbms.subsonic_spotify_relation.c.spotify_song_uuid,
dbms.playlist_info.c.subsonic_playlist_name)

stmt.compile()

stmt = select(func.count()).select_from(stmt.subquery())
Expand Down
56 changes: 38 additions & 18 deletions spotisub/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ def show_recommendations_for_artist(uuid):
thread.start()
thread.join()
else:
logging.info("Skipping thread execution becase a full reimport process is running")
logging.info(
"Skipping thread execution becase a full reimport process is running")


def show_recommendations_for_artist_run(uuid):
Expand Down Expand Up @@ -335,7 +336,8 @@ def my_recommendations(uuid):
thread.start()
thread.join()
else:
logging.info("Skipping thread execution becase a full reimport process is running")
logging.info(
"Skipping thread execution becase a full reimport process is running")


def my_recommendations_run(uuid):
Expand Down Expand Up @@ -413,7 +415,8 @@ def get_user_saved_tracks(uuid):
thread.start()
thread.join()
else:
logging.info("Skipping thread execution becase a full reimport process is running")
logging.info(
"Skipping thread execution becase a full reimport process is running")


def get_user_saved_tracks_run(uuid):
Expand Down Expand Up @@ -445,7 +448,8 @@ def get_user_playlists(uuid):
thread.start()
thread.join()
else:
logging.info("Skipping thread execution becase a full reimport process is running")
logging.info(
"Skipping thread execution becase a full reimport process is running")


def get_user_playlists_run(uuid, offset=0):
Expand Down Expand Up @@ -605,7 +609,7 @@ def reimport(uuid):
for thread in threading.enumerate():
if (thread.name == playlist_info.type or thread.name.startswith(
playlist_info.type)) and thread.is_alive():
#thread.kill()
# thread.kill()
timedelta_sec = timedelta(seconds=30)
return playlist_info
if playlist_info is not None:
Expand Down Expand Up @@ -651,6 +655,7 @@ def reimport(uuid):
constants.SAVED_GEN_SCHED_DEFAULT_VALUE)
return None


def get_tasks():
tasks = []
types = database.select_distinct_type_name()
Expand All @@ -660,18 +665,24 @@ def get_tasks():
task = {}
thread_name = job.id
task["type"] = type
task["type_desc"] = "Import " + string.capwords(type.replace("_", " "))
task["next_execution"] = job.next_run_time.strftime("%d/%m %H:%M:%S")
task["interval"] = str( math.trunc(job.trigger.interval_length / 60 / 60) ) + " hour(s)"
task["type_desc"] = "Import " + \
string.capwords(type.replace("_", " "))
task["next_execution"] = job.next_run_time.strftime(
"%d/%m %H:%M:%S")
task["interval"] = str(
math.trunc(
job.trigger.interval_length / 60 / 60)) + " hour(s)"
if len(job.args) > 0:
pl_info = database.select_playlist_info_by_uuid(str( job.args[0] ))
pl_info = database.select_playlist_info_by_uuid(
str(job.args[0]))
if pl_info is not None:
task["args"] = pl_info.subsonic_playlist_name
task["uuid"] = job.args[0]

else:
task["args"] = ""
task["running"] = "1" if utils.check_thread_running_by_init_name(thread_name) else "0"
task["running"] = "1" if utils.check_thread_running_by_init_name(
thread_name) else "0"
task["id"] = thread_name
tasks.append(task)

Expand All @@ -683,12 +694,14 @@ def get_tasks():
task["uuid"] = ""
task["next_execution"] = "Manual"
task["interval"] = ""
task["running"] = "1" if utils.check_thread_running_by_name(thread_name) else "0"
task["running"] = "1" if utils.check_thread_running_by_name(
thread_name) else "0"
task["id"] = thread_name
tasks.append(task)

return tasks


def poll_playlist():
uuids = []
types = database.select_distinct_type_name()
Expand Down Expand Up @@ -736,6 +749,7 @@ def scan_library():
scan_artists_top_tracks()
scan_user_playlists()


def reimport_all():
"""Used to reimport everything"""
if not utils.check_thread_running_by_name("reimport_all"):
Expand All @@ -745,6 +759,7 @@ def reimport_all():
return True
return False


def reimport_all_thread():
"""Used to reimport everything"""
import_all_user_saved_tracks()
Expand All @@ -753,36 +768,41 @@ def reimport_all_thread():
import_all_artists_recommendations()
import_all_artists_top_tracks()


def import_all_user_saved_tracks():
playlist_infos = database.select_playlist_info_by_type(
constants.JOB_ST_ID)
constants.JOB_ST_ID)
if len(playlist_infos) > 0:
get_user_saved_tracks_run(playlist_infos[0].uuid)


def import_all_my_recommendations():
playlist_infos = database.select_playlist_info_by_type(
constants.JOB_MR_ID)
constants.JOB_MR_ID)
if len(playlist_infos) > 0:
for playlist_info in playlist_infos:
my_recommendations_run(playlist_info.uuid)


def import_all_artists_recommendations():
playlist_infos = database.select_playlist_info_by_type(
constants.JOB_AR_ID)
constants.JOB_AR_ID)
if len(playlist_infos) > 0:
for playlist_info in playlist_infos:
show_recommendations_for_artist_run(playlist_info.uuid)


def import_all_artists_top_tracks():
playlist_infos = database.select_playlist_info_by_type(
constants.JOB_ATT_ID)
constants.JOB_ATT_ID)
if len(playlist_infos) > 0:
for playlist_info in playlist_infos:
artist_top_tracks_run(playlist_info.uuid)


def import_all_user_playlists():
playlist_infos = database.select_playlist_info_by_type(
constants.JOB_UP_ID)
constants.JOB_UP_ID)
if len(playlist_infos) > 0:
for playlist_info in playlist_infos:
get_user_playlists_run(playlist_info.uuid)
Expand Down
Loading

0 comments on commit c451e76

Please sign in to comment.