Skip to content

Commit 76b6d07

Browse files
committed
Merge branch 'monitor-artist-playlist' into beta
2 parents a8e03b2 + edf090f commit 76b6d07

File tree

5 files changed

+76
-26
lines changed

5 files changed

+76
-26
lines changed

deemon/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env python3
22
from deemon.utils import startup
33

4-
__version__ = '2.18b2'
5-
__dbversion__ = '3.6'
4+
__version__ = '2.18b3'
5+
__dbversion__ = '3.7'
66

77
appdata = startup.get_appdata_dir()
88
startup.init_appdata_dir(appdata)

deemon/cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,13 @@ def download_command(artist, artist_id, album_id, url, file, bitrate,
192192
@click.option('-I', '--import', 'im', metavar="PATH", help="Monitor artists/IDs from file or directory")
193193
@click.option('-i', '--artist-id', is_flag=True, help="Monitor artist by ID")
194194
@click.option('-p', '--playlist', is_flag=True, help='Monitor Deezer playlist by URL')
195+
@click.option('--include-artists', is_flag=True, help='Also monitor artists from playlist')
195196
@click.option('-u', '--url', is_flag=True, help='Monitor artist by URL')
196197
@click.option('-R', '--remove', is_flag=True, help='Stop monitoring an artist')
197198
@click.option('-s', '--search', 'search_flag', is_flag=True, help='Show similar artist results to choose from')
198199
@click.option('-T', '--time-machine', type=str, metavar="YYYY-MM-DD", help="Refresh newly added artists on this date")
199200
@click.option('-t', '--record-type', metavar="TYPE", type=str, help='Specify record types to download')
200-
def monitor_command(artist, im, playlist, bitrate, record_type, alerts, artist_id,
201+
def monitor_command(artist, im, playlist, include_artists, bitrate, record_type, alerts, artist_id,
201202
dl, remove, url, download_path, search_flag, time_machine):
202203
"""
203204
Monitor artist for new releases by ID, URL or name.
@@ -256,7 +257,7 @@ def monitor_command(artist, im, playlist, bitrate, record_type, alerts, artist_i
256257
if im:
257258
monitor.importer(im)
258259
elif playlist:
259-
monitor.playlists(playlist_id)
260+
monitor.playlists(playlist_id, include_artists)
260261
elif artist_id:
261262
monitor.artist_ids(dataprocessor.csv_to_list(artist))
262263
elif artist:

deemon/cmd/monitor.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,11 @@ def build_artist_query(self, api_result: list):
123123
self.db.commit()
124124
return True
125125

126-
def build_playlist_query(self, api_result: list):
126+
def build_playlist_query(self, api_result: list, include_artists: bool):
127+
128+
if include_artists:
129+
include_artists = '1'
130+
127131
existing = self.db.get_all_monitored_playlist_ids() or []
128132
playlists_to_add = []
129133
pbar = tqdm(api_result, total=len(api_result), desc="Setting up playlists for monitoring...", ascii=" #",
@@ -134,8 +138,16 @@ def build_playlist_query(self, api_result: list):
134138
if playlist['id'] in existing:
135139
logger.info(f" Already monitoring {playlist['title']}, skipping...")
136140
else:
137-
playlist.update({'bitrate': self.bitrate, 'alerts': self.alerts, 'download_path': self.download_path,
138-
'profile_id': config.profile_id(), 'trans_id': config.transaction_id()})
141+
playlist.update(
142+
{
143+
'bitrate': self.bitrate,
144+
'alerts': self.alerts,
145+
'download_path': self.download_path,
146+
'profile_id': config.profile_id(),
147+
'trans_id': config.transaction_id(),
148+
'monitor_artists': include_artists
149+
}
150+
)
139151
playlists_to_add.append(playlist)
140152
if len(playlists_to_add):
141153
logger.debug("New playlists have been monitored. Saving changes to the database...")
@@ -214,7 +226,7 @@ def importer(self, import_path: str):
214226
return
215227

216228
# @performance.timeit
217-
def playlists(self, playlists: list):
229+
def playlists(self, playlists: list, include_artists: bool):
218230
if self.remove:
219231
return self.purge_playlists(ids=playlists)
220232
ids = [int(x) for x in playlists]
@@ -225,7 +237,7 @@ def playlists(self, playlists: list):
225237
desc=f"Fetching playlist data for {len(ids):,} playlist(s), please wait...",
226238
ascii=" #", bar_format=ui.TQDM_FORMAT))
227239

228-
if self.build_playlist_query(api_result):
240+
if self.build_playlist_query(api_result, include_artists):
229241
self.call_refresh()
230242
else:
231243
print("")

deemon/cmd/refresh.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import re
3+
import time
34
from concurrent.futures import ThreadPoolExecutor
45
from datetime import datetime, timedelta
56

@@ -248,12 +249,19 @@ def run(self, artists: list = None, playlists: list = None):
248249
for payload in payload_container:
249250
self.prep_payload(payload)
250251

252+
playlist_monitor_artists = []
251253
for payload in api_result['playlists']:
252254
if len(payload):
253255
self.seen = self.db.get_playlist_tracks(payload['id'])
254256
payload['tracks'] = self.remove_existing_releases(payload, self.seen)
255257
self.filter_playlist_releases(payload)
256258

259+
if payload['monitor_artists']:
260+
logger.debug(f"Artists from this playlist ({payload['id']}) are to be monitored!")
261+
for track in payload['tracks']:
262+
playlist_monitor_artists.append(track['artist_id'])
263+
playlist_monitor_artists = list(set(playlist_monitor_artists))
264+
257265
if self.skip_download:
258266
logger.info(f" [!] You have opted to skip downloads, clearing {len(self.queue_list):,} item(s) from queue...")
259267
self.queue_list.clear()
@@ -263,7 +271,6 @@ def run(self, artists: list = None, playlists: list = None):
263271
dl = Download()
264272
dl.download_queue(self.queue_list)
265273

266-
267274
if len(self.new_playlist_releases) or len(self.new_releases):
268275
if len(self.new_playlist_releases):
269276
logger.debug("Updating playlist releases in database...")
@@ -284,6 +291,14 @@ def run(self, artists: list = None, playlists: list = None):
284291
notification = notifier.Notify(self.new_releases_alert)
285292
notification.send()
286293

294+
if playlist_monitor_artists:
295+
print("")
296+
logger.info(":: New artists to monitor, stand by...")
297+
time.sleep(2)
298+
from deemon.cmd.monitor import Monitor
299+
monitor = Monitor()
300+
monitor.artist_ids(playlist_monitor_artists)
301+
287302
def db_stats(self):
288303
artists = len(self.db.get_all_monitored_artist_ids())
289304
playlists = len(self.db.get_all_monitored_playlist_ids())

deemon/core/db.py

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ def create_new_database(self):
8282
"'profile_id' INTEGER DEFAULT 1,"
8383
"'download_path' TEXT,"
8484
"'refreshed' INTEGER DEFAULT 0,"
85-
"'trans_id' INTEGER)")
85+
"'trans_id' INTEGER,"
86+
"'monitor_artists' INTEGER DEFAULT 0)")
8687

8788
self.query("CREATE TABLE playlist_tracks ("
8889
"'track_id' INTEGER,"
@@ -169,19 +170,19 @@ def do_upgrade(self):
169170

170171
if current_ver < parse_version("3.5.2"):
171172
self.query("CREATE TABLE releases_tmp ("
172-
"'artist_id' INTEGER,"
173-
"'artist_name' TEXT,"
174-
"'album_id' INTEGER,"
175-
"'album_name' TEXT,"
176-
"'album_release' TEXT,"
177-
"'album_added' INTEGER,"
178-
"'explicit' INTEGER,"
179-
"'label' TEXT,"
180-
"'record_type' INTEGER,"
181-
"'profile_id' INTEGER DEFAULT 1,"
182-
"'future_release' INTEGER DEFAULT 0,"
183-
"'trans_id' INTEGER,"
184-
"unique(album_id, profile_id))")
173+
"'artist_id' INTEGER,"
174+
"'artist_name' TEXT,"
175+
"'album_id' INTEGER,"
176+
"'album_name' TEXT,"
177+
"'album_release' TEXT,"
178+
"'album_added' INTEGER,"
179+
"'explicit' INTEGER,"
180+
"'label' TEXT,"
181+
"'record_type' INTEGER,"
182+
"'profile_id' INTEGER DEFAULT 1,"
183+
"'future_release' INTEGER DEFAULT 0,"
184+
"'trans_id' INTEGER,"
185+
"unique(album_id, profile_id))")
185186
self.query("INSERT OR REPLACE INTO releases_tmp(artist_id, artist_name, "
186187
"album_id, album_name, album_release, album_added, "
187188
"explicit, label, record_type, profile_id, "
@@ -193,12 +194,33 @@ def do_upgrade(self):
193194
self.query("ALTER TABLE releases_tmp RENAME TO releases")
194195
self.query("INSERT OR REPLACE INTO 'deemon' ('property', 'value') VALUES ('version', '3.5.2')")
195196
self.commit()
196-
logger.debug(f"Database upgraded to version 3.5.2")
197197

198198
if current_ver < parse_version("3.6"):
199199
# album_release_ts REMOVED
200200
pass
201201

202+
if current_ver < parse_version("3.7"):
203+
self.query("CREATE TABLE playlists_tmp ("
204+
"'id' INTEGER UNIQUE,"
205+
"'title' TEXT,"
206+
"'url' TEXT,"
207+
"'bitrate' TEXT,"
208+
"'alerts' INTEGER,"
209+
"'profile_id' INTEGER DEFAULT 1,"
210+
"'download_path' TEXT,"
211+
"'refreshed' INTEGER DEFAULT 0,"
212+
"'trans_id' INTEGER,"
213+
"'monitor_artists' INTEGER DEFAULT 0)")
214+
self.query("INSERT OR REPLACE INTO playlists_tmp (id, title, url, bitrate, "
215+
"alerts, profile_id, download_path, refreshed, trans_id) SELECT "
216+
"id, title, url, bitrate, alerts, profile_id, download_path, "
217+
"refreshed, trans_id FROM playlists")
218+
self.query("DROP TABLE playlists")
219+
self.query("ALTER TABLE playlists_tmp RENAME TO playlists")
220+
self.query("INSERT OR REPLACE INTO 'deemon' ('property', 'value') VALUES ('version', '3.7')")
221+
self.commit()
222+
logger.debug(f"Database upgraded to version 3.7")
223+
202224
def query(self, query, values=None):
203225
if values is None:
204226
values = {}
@@ -530,7 +552,7 @@ def fast_monitor(self, values):
530552

531553
def fast_monitor_playlist(self, values):
532554
self.cursor.executemany(
533-
"INSERT OR REPLACE INTO playlists (id, title, url, bitrate, alerts, profile_id, download_path, trans_id) VALUES (:id, :title, :link, :bitrate, :alerts, :profile_id, :download_path, :trans_id)",
555+
"INSERT OR REPLACE INTO playlists (id, title, url, bitrate, alerts, profile_id, download_path, trans_id, monitor_artists) VALUES (:id, :title, :link, :bitrate, :alerts, :profile_id, :download_path, :trans_id, :monitor_artists)",
534556
values)
535557

536558
def insert_multiple(self, table, values):

0 commit comments

Comments
 (0)