# Is there a hook event for successful imports only?

**URL:** <https://discourse.beets.io/t/is-there-a-hook-event-for-successful-imports-only/2322>\
**Category:** Help\
**Created:** [April 14, 2023, 12:01am UTC](https://discourse.beets.io/t/is-there-a-hook-event-for-successful-imports-only/2322 "2023-04-14T00:01:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![apetresc](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/apetresc/32/749_2.png) [@apetresc](https://discourse.beets.io/u/apetresc)\
**Post date:** [April 14, 2023, 12:01am UTC](https://discourse.beets.io/t/is-there-a-hook-event-for-successful-imports-only/2322/1 "2023-04-14T00:01:32Z")

</div>

I want to write a hook that can “clean up” imported albums after they’re successfully imported (for various reasons, I _don’t_ want to just let beet move the files; I’d rather beet do a copy and then let me clean up the old files myself).

However, I can’t seem to find a hook event that fits this fairly basic use-case.

- The `import` event seemed like the most promising option, since the documentation says:

- `album_imported` also seemed promising, since it does correctly fire only after an album is actually imported, but unfortunately there’s nothing in the `lib` or `album` parameters that tells me which path was actually being imported, so the hook has no way to clean up just those files.

- `import_task_apply` also seemed relevant but it doesn’t seem to fire at all, my test command wasn’t firing after an import whether successful or not; and anyway even if it had, it wasn’t clear whether any of its parameters would include the path being imported anyway.

Short of writing a full plugin with a new pipeline stage, is there any way for `hook` to accomplish what I’m trying to do here? And if not, would it be possible to add some sort of new parameter to the `import` callback that itemizes whether each item in `paths` was _actually_ imported or not? That seems like a pretty generically useful thing to have.

Thanks!

---

<div class="post-metadata">

**Author:** ![apetresc](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/apetresc/32/749_2.png) [@apetresc](https://discourse.beets.io/u/apetresc)\
**Post date:** [April 14, 2023, 1:17am UTC](https://discourse.beets.io/t/is-there-a-hook-event-for-successful-imports-only/2322/2 "2023-04-14T01:17:14Z")

</div>

Okay with a bit more experimentation, I think I’ve found it; `import_task_files` seems to fire at the right time, and `task.paths` is a list containing the precise paths that were imported, one task at a time. Excellent!

My only remaining question is, given whatever format-string syntax Beets is using, is there a way for me to easily do the equivalent of `" ".join(task.paths)` in the hook’s `command`? The usual `{*task.paths}` doesn’t appear to work. For now I’m just doing `{task.paths[0]}` which is good enough for most cases since most album imports are from a single path, but I can imagine scenarios where `task.paths` might have length greater than 1.

---

<div class="post-metadata">

**Author:** ![adrian](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/adrian/32/4_2.png) [@adrian](https://discourse.beets.io/u/adrian)\
**Post date:** [April 16, 2023, 4:45pm UTC](https://discourse.beets.io/t/is-there-a-hook-event-for-successful-imports-only/2322/3 "2023-04-16T16:45:37Z")

</div>

Cool! FWIW, those templates use [Python’s str.format templates](https://docs.python.org/3/tutorial/inputoutput.html#the-string-format-method). Unfortunately, that system can only really do simple lookups and (while I would be happy to be proven wrong) I don’t think there is a way to invoke `str.join` from there.
