Skip to content

Commit 31f7561

Browse files
committed
fix format recognition and enforce tags
1 parent 0d3c934 commit 31f7561

1 file changed

Lines changed: 27 additions & 22 deletions

File tree

pythonbits/bb.py

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from collections import namedtuple, abc
1010
from concurrent.futures.thread import ThreadPoolExecutor
1111
from datetime import timedelta
12+
from mimetypes import guess_type
1213

1314
import pymediainfo
1415
import mutagen
@@ -850,7 +851,7 @@ def _render_form_description(self):
850851

851852

852853
class AudioSubmission(BbSubmission):
853-
default_fields = ("description", "form_tags", "year", "image", "artist",
854+
default_fields = ("description", "form_tags", "year", "cover", "artist",
854855
"title", "format", "bitrate", "media")
855856

856857
def subcategory(self):
@@ -867,7 +868,7 @@ def _render_remaster(self):
867868
# todo user input function/module to reduce boilerplating
868869
return bool(
869870
input('Is this a special/remastered edition? [y/N] ').lower()
870-
!= 'n')
871+
== 'y')
871872

872873
@form_field('remaster_year')
873874
def _render_remaster_year(self):
@@ -950,24 +951,23 @@ def _render_mediainfo_path(self):
950951
# get first file over 1 MiB
951952
for dp, dns, fns in os.walk(self['path']):
952953
for fn in fns:
953-
full_path = os.path.join(dp, fn)
954-
if os.path.getsize(full_path) > 1 * 2**20:
955-
return full_path
954+
if guess_type(fn)[0].startswith('audio'):
955+
return os.path.join(dp, fn) #return full path
956956
raise Exception('No media file found')
957957

958958
def _render_tracklist(self):
959959
release, _ = self['release']
960960
full_tracklist = []
961961
mediumlist = release['medium-list']
962962

963+
DEFAULT_FORMAT = 'CD'
963964
for medium in mediumlist:
964965
log.debug('medium {}', medium.keys())
966+
title = medium.get('format', DEFAULT_FORMAT)
965967
if len(mediumlist) > 1:
966-
title = "{} {}".format(medium['format'], medium['position'])
968+
title += " {}".format(format, medium['position'])
967969
if 'title' in medium:
968970
title += ": {}".format(medium['title'])
969-
else:
970-
title = medium['format']
971971

972972
tracklist = [
973973
(t['number'], t['recording']['title'],
@@ -1046,34 +1046,39 @@ def _render_summary(self):
10461046
'tags': [t['name'] for t in
10471047
sorted(rg.get('tag-list', []),
10481048
key=lambda t: int(t['count']))][-5:],
1049-
'media': [m['format'] for m in release['medium-list']],
1049+
'media': [m.get('format', 'CD') for m in release['medium-list']],
10501050
'cover': mb.get_artwork(rg['id']),
10511051
}
10521052

10531053
@finalize
10541054
@form_field('image')
1055-
def _render_image(self):
1056-
return self['summary']['cover']
1055+
def _render_cover(self):
1056+
cover = self['summary']['cover']
1057+
assert cover is not None
1058+
return cover
10571059

1058-
def _finalize_image(self):
1059-
return ImgurUploader().upload(self['image'])
1060+
def _finalize_cover(self):
1061+
return ImgurUploader().upload(self['cover'])
10601062

10611063
@form_field('year')
10621064
def _render_year(self):
10631065
return self['summary']['year']
10641066

10651067
@form_field('tags')
10661068
def _render_form_tags(self):
1067-
_defaults = ['acoustic', 'alternative', 'ambient', 'blues',
1068-
'classic.rock', 'classical', 'country', 'dance',
1069-
'dubstep', 'electronic', 'experimental', 'folk', 'funk',
1070-
'hardcore', 'heavy.metal', 'hip.hop', 'indie',
1071-
'indie.pop', 'instrumental', 'jazz', 'metal', 'pop',
1072-
'post.hardcore', 'post.rock', 'progressive.rock',
1073-
'psychedelic', 'punk', 'reggae', 'rock', 'soul', 'trance',
1074-
'trip.hop']
1069+
_defaults = {'acoustic', 'alternative', 'ambient', 'blues',
1070+
'classic.rock', 'classical', 'country', 'dance', 'dubstep',
1071+
'electronic', 'experimental', 'folk', 'funk', 'hardcore',
1072+
'heavy.metal', 'hip.hop', 'indie', 'indie.pop',
1073+
'instrumental', 'jazz', 'metal', 'pop', 'post.hardcore',
1074+
'post.rock', 'progressive.rock', 'psychedelic', 'punk',
1075+
'reggae', 'rock', 'soul', 'trance', 'trip.hop'}
10751076
tags = self['summary']['tags']
1076-
return list(set(format_tag(tag) for tag in tags))
1077+
if not tags:
1078+
tags = input('No tags found. Please enter tags:').split(',')
1079+
tags = set(format_tag(tag) for tag in tags)
1080+
assert tags & _defaults != set()
1081+
return list(tags)
10771082

10781083
def _render_section_information(self):
10791084
release, rg = self['release']

0 commit comments

Comments
 (0)