Skip to content

Commit

Permalink
Split out single release import to separate command
Browse files Browse the repository at this point in the history
- dsc import release ID -> Import a single release to DiscoBASE. When
  used with -a, also to Discogs online collection.
- dsc import details -> Enrich with --tracks and --brainz stuff, as we
  had it in the import command before.
- Todo: Split out "initial/basic" minimal but whole collection import
  into separate command.
  • Loading branch information
Johannes Tiefenbacher committed Oct 27, 2024
1 parent ac22ae3 commit 8fbf962
Showing 1 changed file with 78 additions and 72 deletions.
150 changes: 78 additions & 72 deletions discodos/cmd23/import_.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,7 @@ def import_group():


@import_group.command(name='details')
@click.argument('import_id', metavar='RELEASE_ID', required=False,
type=int, default='0')
@optgroup.group("Actions", cls=MutuallyExclusiveOptionGroup)
@optgroup.option(
'--add-to-collection', '-a', 'import_add_coll', is_flag=True,
help='''The recommended and fastest way of adding newly gained releases to
your collection. The given release ID is added to your Discogs collection
(equal to clicking "Add to collection" on the Discogs webinterface as well
as added to the local DiscoBASE. For performance's sake though, we don't do
a time-consuming check whether or not the release is in the (online)
collection via the Discogs API, we just do a quick check for the presence
of the ID in the (local) DiscoBASE. This safes us a lot of time and is a
good enough solution to prevent duplicates.''')
@optgroup.option(
'--tracks', '-u', 'import_tracks', is_flag=True,
help='''extends the Discogs import (releases and also tracks will be
Expand Down Expand Up @@ -65,65 +53,37 @@ def import_group():
ID already saved in the DiscoBASE), are tried to be matched and updated.
''')
@click.pass_obj
def import_cmd(helper, import_id, import_add_coll, import_tracks,
import_brainz, import_offset, import_brainz_force,
import_brainz_skip_unmatched):
"""Imports a Discogs collection or adds single releases to the collection.
The local database is referred to as DiscoBASE. RELEASE_ID is the Discogs
release ID you want to import to the DiscoBASE. If left out, the whole
collection will be imported. Option -a adds the release to the Discogs
collection _and_ additionally imports it to the DiscoBASE.
Note that a regular import of a given release ID (import RELEASE_ID) is
rather slow: Technical limitations that are out of our hands require us to
run through all of the releases in the collection via the Discogs API.
Unfortunately Discogs does not allow us to search for release IDs in the
user collection directly.
That is the reason why the recommended way of adding newly gained releases
is using the -a option (import -a RELEASE_ID).
def import_cmd(helper, import_tracks, import_brainz, import_offset,
import_brainz_force, import_brainz_skip_unmatched):
"""Initially imports a Discogs collection or enriches it with more details.
"""
def update_user_interaction_helper(user):
log.debug("Entered import mode.")
if import_id != 0 and import_add_coll:
user.WANTS_TO_ADD_AND_IMPORT_RELEASE = True
elif import_id == 0 and import_add_coll:
log.error("Release ID missing. Which release should be added and "
"imported?")
raise SystemExit(1)
elif import_id == 0:
if import_tracks:
user.WANTS_TO_IMPORT_COLLECTION_WITH_TRACKS = True
if import_offset > 0:
user.RESUME_OFFSET = import_offset
m_r ='Resuming is not possible in combination with '
m_r+='"import -u/--discogs-update". Try it with '
m_r+='"mix -u/--discogs-update". Also it works '
m_r+='together with "import -zz/brainz-update" '
m_r+='and "mix -zz/--brainz-update"'
log.error(m_r)
raise SystemExit(1)
elif import_brainz:
user.WANTS_TO_IMPORT_COLLECTION_WITH_BRAINZ = True
user.BRAINZ_SEARCH_DETAIL = import_brainz
if import_brainz > 1:
user.BRAINZ_SEARCH_DETAIL = 2
if import_brainz_force:
user.BRAINZ_FORCE_UPDATE = True
if import_brainz_skip_unmatched:
user.BRAINZ_SKIP_UNMATCHED = True
if import_offset > 0:
user.RESUME_OFFSET = import_offset
else:
user.WANTS_TO_IMPORT_COLLECTION = True
else:
if import_brainz or import_tracks:
log.error("You can't combine a single release import with "
"-z or -u.")
log.debug("Entered collection and details import mode.")
if import_tracks:
user.WANTS_TO_IMPORT_COLLECTION_WITH_TRACKS = True
if import_offset > 0:
user.RESUME_OFFSET = import_offset
m_r ='Resuming is not possible in combination with '
m_r+='"import -u/--discogs-update". Try it with '
m_r+='"mix -u/--discogs-update". Also it works '
m_r+='together with "import -zz/brainz-update" '
m_r+='and "mix -zz/--brainz-update"'
log.error(m_r)
raise SystemExit(1)
else:
user.WANTS_TO_IMPORT_RELEASE = True
elif import_brainz:
user.WANTS_TO_IMPORT_COLLECTION_WITH_BRAINZ = True
user.BRAINZ_SEARCH_DETAIL = import_brainz
if import_brainz > 1:
user.BRAINZ_SEARCH_DETAIL = 2
if import_brainz_force:
user.BRAINZ_FORCE_UPDATE = True
if import_brainz_skip_unmatched:
user.BRAINZ_SKIP_UNMATCHED = True
if import_offset > 0:
user.RESUME_OFFSET = import_offset
else:
user.WANTS_TO_IMPORT_COLLECTION = True
return user

user = update_user_interaction_helper(helper)
Expand All @@ -135,10 +95,6 @@ def update_user_interaction_helper(user):

if user.WANTS_TO_IMPORT_COLLECTION:
coll_ctrl.import_collection()
if user.WANTS_TO_IMPORT_RELEASE:
coll_ctrl.import_release(import_id)
if user.WANTS_TO_ADD_AND_IMPORT_RELEASE:
coll_ctrl.add_release(import_id)
if user.WANTS_TO_IMPORT_COLLECTION_WITH_TRACKS:
coll_ctrl.import_collection(tracks=True)
if user.WANTS_TO_IMPORT_COLLECTION_WITH_BRAINZ:
Expand All @@ -147,3 +103,53 @@ def update_user_interaction_helper(user):
offset=user.RESUME_OFFSET,
force=user.BRAINZ_FORCE_UPDATE,
skip_unmatched=user.BRAINZ_SKIP_UNMATCHED)


@import_group.command(name='release')
@click.argument('import_id', metavar='RELEASE_ID', type=int)
@click.option(
'--add-to-collection', '-a', 'import_add_coll', is_flag=True,
help='''The fastest way of adding newly gained releases to your collection.
The given release ID is added to your Discogs collection (equal to clicking
"Add to collection" on the Discogs webinterface) as well as added to the
local DiscoBASE.
For performance's sake though, we don't do a time-consuming check whether or
not the release is in the (online) collection via the Discogs API, we just
do a quick check for the presence of the ID in the (local) DiscoBASE. This
safes us a lot of time and is a good enough solution to prevent
duplicates.''')
@click.pass_obj
def import_release_cmd(helper, import_id, import_add_coll):
"""Imports a single release to the DiscoBASE.
Note that currently this is a rather time consuming process: Technical
limitations that are out of our hands require running through all of the
releases in the collection via the Discogs API. Unfortunately Discogs does
not allow us to search for release IDs in the user collection directly.
The recommended way of adding newly gained releases is using the -a option
(import release -a RELEASE_ID) which is much faster. Using this flag, the
release is added to Discogs collection and additionally added to the local
DiscoBASE.
"""

def update_user_interaction_helper(user):
log.debug("Entered single release import mode.")
if import_id != 0 and import_add_coll:
user.WANTS_TO_ADD_AND_IMPORT_RELEASE = True
else:
user.WANTS_TO_IMPORT_RELEASE = True
return user

user = update_user_interaction_helper(helper)
log.info("user.WANTS_ONLINE: %s", user.WANTS_ONLINE)
coll_ctrl = Coll_ctrl_cli(
False, user, user.conf.discogs_token, user.conf.discogs_appid,
user.conf.discobase, user.conf.musicbrainz_user,
user.conf.musicbrainz_password)

if user.WANTS_TO_IMPORT_RELEASE:
coll_ctrl.import_release(import_id)
if user.WANTS_TO_ADD_AND_IMPORT_RELEASE:
coll_ctrl.add_release(import_id)

0 comments on commit 8fbf962

Please sign in to comment.