dotfiles

config files and scripts at HOME.
git clone git://git.ricketyspace.net/dotfiles.git
Log | Files | Refs

commit b76a89ec661d3b72b221a2029e392c1aac5663ba
parent 975bec7a362e237e03dd789e212764fc6d1bd015
Author: rsiddharth <s@ricketyspace.net>
Date:   Sat, 24 Feb 2018 02:25:05 +0000

.bin: Remove tagmp3album.

Diffstat:
.bin/tagmp3album | 140-------------------------------------------------------------------------------
1 file changed, 0 insertions(+), 140 deletions(-)

diff --git a/.bin/tagmp3album b/.bin/tagmp3album @@ -1,140 +0,0 @@ -#!/usr/bin/env python3 -# -# Copyright © 2016-2017 rsiddharth <s@ricketyspace.net> -# -# Licensed under the GNU General Public License version 3 or higher. See -# <https://www.gnu.org/licenses/gpl-3.0.txt> - -import json -import os - -import eyed3 - -from argparse import ArgumentParser -from collections import OrderedDict -from os import path -from sys import exit - - -def read_file(filename): - """Read file and return it as a string. - - :param str filename: pathname of the file. - - """ - content = '' - - try: - with open(filename, 'r') as f: - for line in f: - content = content + line - except IOError: - print('Error: unable to open {}'.format(filename)) - - return content - - -def json_read(filename): - """Deserialize JSON formatted `str` from `filename` into Python object. - """ - if not path.isfile(filename): - print('{} not found. Quitting'.format(filename)) - exit(1) - - return json.loads(read_file(filename), - object_pairs_hook=OrderedDict) - - -def contains_all_words(filename, words): - """Returns True if filename contains all `words`. - """ - matches = 0 - - for word in words: - if word in filename: - matches +=1 - - return matches == len(words) - - -def print_tracks_not_found(tracks): - """Print tracks whose file where not found. - """ - print('Track(s) not found:') - - for track in tracks: - print(track) - - -def track_path(dir_path, title): - """Return track `title`'s path; False otherwise. - """ - words = title.split() - - for dirpath, dirnames, filenames in os.walk(dir_path): - for filename in filenames: - if contains_all_words(filename, words): - return path.join(dirpath, filename) - - return False - - -def tag_track(path, artist, album, title, track_num, num_of_tracks): - """Tag track. - - """ - print('Tagging - {} - {} - {} - {} - {}'.format(path, track_num, - artist, album, - title)) - - track = eyed3.load(path) - track.initTag() - - track.tag.artist = artist - track.tag.album = album - track.tag.title = title - track.tag.track_num = (track_num, num_of_tracks) - - track.tag.save() - - -def tag_album(album_info_file): - """Tag the whole album - """ - abs_path = path.abspath(album_info_file) - dir_path = path.dirname(abs_path) - album_info = json_read(album_info_file) - - not_found = [] - - artist = album_info['artist'] - album = album_info['album'] - track_num = 0 - - for track_title in album_info['tracks']: - track_num += 1 - t_path = track_path(dir_path, track_title) - - if not t_path: - not_found.append(track_title) - continue - - tag_track(t_path, artist, album, track_title, track_num, - len(album_info['tracks'])) - - if not_found: - print_tracks_not_found(not_found) - - -def main(): - parser = ArgumentParser() - - help_text = "Path to file containing album info in JSON format" - parser.add_argument("album_info_file", - help=help_text) - args = parser.parse_args() - - tag_album(args.album_info_file) - -if __name__ == "__main__": - main()