Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

m3uupdate plugin #23

Merged
merged 1 commit into from Mar 18, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 52 additions & 0 deletions beetsplug/m3uupdate.py
@@ -0,0 +1,52 @@
# This file is part of beets.
# Copyright 2012, Adrian Sampson.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.

"""Write paths of imported files in a m3u file to ease later import in a music
player.
"""

from __future__ import with_statement
import os

from beets import ui
from beets.plugins import BeetsPlugin
from beets.util import normpath

class m3uPlugin(BeetsPlugin):
def configure(self, config):
global M3U_FILENAME
M3U_FILENAME = ui.config_val(config, 'm3uupdate', 'm3u', None)

if not M3U_FILENAME:
M3U_FILENAME = os.path.join(
ui.config_val(config, 'beets', 'directory', '.'),
'imported.m3u')
M3U_FILENAME = normpath(M3U_FILENAME)
m3u_dir = os.path.dirname(M3U_FILENAME)
if not os.path.exists(m3u_dir):
os.makedirs(m3u_dir)

@m3uPlugin.listen('album_imported')
def album_imported(lib, album, config):
with open(M3U_FILENAME, 'a') as f:
for item in album.items():
f.write(os.path.relpath(item.path,
os.path.dirname(M3U_FILENAME)) + '\n')

@m3uPlugin.listen('item_imported')
def item_imported(lib, item, config):
with open(M3U_FILENAME, 'a') as f:
f.write(os.path.relpath(item.path,
os.path.dirname(M3U_FILENAME)) + '\n')