| 1 |
#! /usr/bin/env python |
|---|
| 2 |
# |
|---|
| 3 |
# This queries the tags a user has applied to an entity and submits a changed |
|---|
| 4 |
# list of tags to the MusicBrainz server. |
|---|
| 5 |
# |
|---|
| 6 |
# Usage: |
|---|
| 7 |
# python tag.py |
|---|
| 8 |
# |
|---|
| 9 |
# $Id$ |
|---|
| 10 |
# |
|---|
| 11 |
import getpass |
|---|
| 12 |
import sys |
|---|
| 13 |
import logging |
|---|
| 14 |
import musicbrainz2.webservice as mbws |
|---|
| 15 |
from musicbrainz2.model import Tag |
|---|
| 16 |
from musicbrainz2.utils import extractUuid |
|---|
| 17 |
|
|---|
| 18 |
MB_HOST = 'test.musicbrainz.org' |
|---|
| 19 |
|
|---|
| 20 |
logging.basicConfig() |
|---|
| 21 |
logger = logging.getLogger() |
|---|
| 22 |
logger.setLevel(logging.DEBUG) |
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
# Get the username and password |
|---|
| 26 |
username = raw_input('Username: ') |
|---|
| 27 |
password = getpass.getpass('Password: ') |
|---|
| 28 |
|
|---|
| 29 |
# Ask for a MBID to tag. |
|---|
| 30 |
mbid = raw_input('Enter an absolute MB ID: ') |
|---|
| 31 |
|
|---|
| 32 |
# Set the authentication for the webservice (only needed for tag submission). |
|---|
| 33 |
service = mbws.WebService(host=MB_HOST, username=username, password=password) |
|---|
| 34 |
|
|---|
| 35 |
# Create a new Query object which will provide |
|---|
| 36 |
# us an interface to the MusicBrainz web service. |
|---|
| 37 |
query = mbws.Query(service) |
|---|
| 38 |
|
|---|
| 39 |
# Read and print the current tags for the given MBID |
|---|
| 40 |
tags = query.getUserTags(mbid) |
|---|
| 41 |
print |
|---|
| 42 |
print 'Current tags: ' |
|---|
| 43 |
print ', '.join([tag.value for tag in tags]) |
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
# Ask the user for new tags and submit them |
|---|
| 47 |
tag_str = raw_input('Enter new tags: ') |
|---|
| 48 |
new_tags = [Tag(tag.strip()) for tag in tag_str.split(',')] |
|---|
| 49 |
|
|---|
| 50 |
query.submitUserTags(mbid, new_tags) |
|---|
| 51 |
|
|---|
| 52 |
print 'Tags submitted.' |
|---|
| 53 |
|
|---|
| 54 |
# EOF |
|---|