Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1b3aabb

Browse files
committed
Add fix-music-tags script.
1 parent e530c46 commit 1b3aabb

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ This script computes the mean of a directory of images for Caffe.
7474

7575

7676

77+
## [python2.7/fix-music-tags.py](https://github.com/bamos/python-scripts/blob/master/python2.7/fix-music-tags.py)
78+
+ Authors: [Brandon Amos](http://bamos.github.io)
79+
+ Created: 2015.12.30
80+
81+
82+
This script (fix-music-tags.py) mass-removes unwanted music tags.
83+
84+
85+
7786
## [python2.7/mt.py](https://github.com/bamos/python-scripts/blob/master/python2.7/mt.py)
7887
+ Authors: [Brandon Amos](http://bamos.github.io)
7988
+ Created: 2014.11.30
@@ -345,8 +354,8 @@ and I'm happy to merge pull requests of other projects.
345354

346355
Name | Stargazers | Description
347356
----|----|----
348-
[averagesecurityguy/Python-Examples](https://github.com/averagesecurityguy/Python-Examples) | 20 | Example scripts for common python tasks
349-
[ClarkGoble/Scripts](https://github.com/ClarkGoble/Scripts) | 28 | My scripts - primarily using python and appscript
350-
[computermacgyver/twitter-python](https://github.com/computermacgyver/twitter-python) | 50 | Simple example scripts for Twitter data collection with Tweepy in Python
357+
[averagesecurityguy/Python-Examples](https://github.com/averagesecurityguy/Python-Examples) | 22 | Example scripts for common python tasks
358+
[ClarkGoble/Scripts](https://github.com/ClarkGoble/Scripts) | 29 | My scripts - primarily using python and appscript
359+
[computermacgyver/twitter-python](https://github.com/computermacgyver/twitter-python) | 62 | Simple example scripts for Twitter data collection with Tweepy in Python
351360
[gpambrozio/PythonScripts](https://github.com/gpambrozio/PythonScripts) | 38 | A bunch of Python scripts I made and that might interest somebody else
352-
[realpython/python-scripts](https://github.com/realpython/python-scripts) | 67 | because i'm tired of gists
361+
[realpython/python-scripts](https://github.com/realpython/python-scripts) | 549 | because i'm tired of gists

python2.7/fix-music-tags.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env python2
2+
3+
__author__ = ['[Brandon Amos](http://bamos.github.io)']
4+
__date__ = '2015.12.30'
5+
6+
"""
7+
This script (fix-music-tags.py) mass-removes unwanted music tags.
8+
"""
9+
10+
from mutagen.easyid3 import EasyID3
11+
import argparse
12+
import glob
13+
14+
15+
def fixTags(fname, keep):
16+
audio = EasyID3(fname)
17+
artist = audio['artist']
18+
title = audio['title']
19+
album = audio['album']
20+
21+
delKeys = []
22+
for k, v in audio.items():
23+
if k not in keep:
24+
delKeys.append(k)
25+
26+
for k in delKeys:
27+
del audio[k]
28+
audio.save()
29+
30+
if __name__ == '__main__':
31+
parser = argparse.ArgumentParser()
32+
parser.add_argument('directory', help='Directory with mp3 files to fix.')
33+
parser.add_argument('--keep', default=['title', 'artist', 'album', 'genre'],
34+
type=str, nargs='+', metavar='TAG',
35+
help="Tags to keep. Default: title, artist, album, genre")
36+
args = parser.parse_args()
37+
38+
for fname in glob.glob("{}/*.mp3".format(args.directory)):
39+
print("Fixing tags for {}".format(fname))
40+
fixTags(fname, args.keep)

0 commit comments

Comments
 (0)