Advertisement
Guest User

path format

a guest
Aug 27th, 2020
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.73 KB | None | 0 0
  1. replace:
  2.     #fake comment and fake tab options
  3.     '\#.*zxc': ''
  4.     #fake tab (4+ spaces) to have tabs in paths. will still match to any path that really should have 4+ spaces in it. Ex. an album called "Trouble    Maker"    
  5.     ' {4,}': ''
  6.  
  7. paths:
  8.     #regex to match all items. (avoid having to separately define compilations and singletons.)
  9.     title::.*: "$i_test %if{\
  10.                   $alb_artist,\
  11.                       %the{\
  12.                             $alb_artist\
  13.                            } - ,\
  14.                   No Artist - \
  15.                 }\
  16.    %if{\
  17.      $alb_promo_boot,\
  18.      $alb_promo_boot%if{\
  19.                          $alb_exotic_type,\
  20.                          #add literal comma and space if promo_boot and exotic_type exist for the same album. zxc\
  21.                          #for example Promo comma Spoken Word zxc\
  22.                          $, , - \
  23.                        }\
  24.       }\
  25.    %if{\
  26.    $alb_exotic_type,\
  27.    $alb_exotic_type - \
  28.        }\
  29.    $alb_orig_year - \
  30.    $alb_title\
  31.    %aunique{\
  32.              album $alb_orig_year_mm_dd albumartist albumstatus albumtype,\
  33.              albumdisambig country label catalognum,\
  34.              ()\
  35.            }\
  36.    $i_cust_catalog%if{\
  37.                                   $alb_subset_bitrate, \
  38.                                   [$alb_subset_bitrate]\
  39.                      }\
  40.    /%if{\
  41.         $i_disc_layer,\
  42.         $i_disc_layer-\
  43.        }\
  44.    %if{\
  45.        $track,\
  46.        $i_track. ,\
  47.        [no track number]. \
  48.        }\
  49.    %if{\
  50.        $title,\
  51.        $title,\
  52.        [unknown]\
  53.        }"
  54.  
  55. album_fields:
  56.  
  57.     alb_promo_boot: |
  58.         #official, promo, bootleg, and pseudo-release. we only note the middle two. https://musicbrainz.org/doc/Release#Status
  59.         if 'Promo' in albumstatus:
  60.             return 'Promo'
  61.         elif 'Bootleg' in albumstatus:
  62.             return 'Bootleg'
  63.         else:
  64.             return ''
  65.     alb_exotic_type: |
  66.         #no special noting of albums, EPs, and soundtracks
  67.         if albumtype in {'album', 'ep', 'soundtrack'}:
  68.            return ''
  69.         #special case for proper spacing and caps
  70.         elif 'spokenword' in albumtype:
  71.            return 'Spoken Word'
  72.         else:
  73.            return str.title(albumtype)
  74.     alb_subset_bitrate: |
  75.         #return bitrate information for albums <150kbps.
  76.         #do nothing for higher-bitrate albums, because they are assumed to be perceptually lossless.
  77.         br_threshhold = 150
  78.         max_tracks_to_check = 10
  79.         def sample_tracks(tracks):
  80.             #reproducible randomness for debugging. should be excluded for optimal randomness from album to album.
  81.             #otherwise, any album with same number of tracks will get same sample of track numbers, I think
  82.             from random import seed, sample
  83.             seed(25)
  84.             num_items = len(tracks)
  85.             sample_size = min(max_tracks_to_check, num_items)
  86.             test_tracks = sample(tracks, sample_size)
  87.             return(test_tracks)
  88.         test_tracks = sample_tracks(items)
  89.         sample_size = len(test_tracks)
  90.         total = 0
  91.         for item in test_tracks:
  92.             total += item.bitrate
  93.         album_br_bits_ps = total / sample_size
  94.         # music bitrates are base 10:
  95.         # https://hydrogenaud.io/index.php/topic,12633.0.html
  96.         album_br_kbps = album_br_bits_ps / 1000
  97.         if album_br_kbps > br_threshhold:
  98.             out_text = ''
  99.         else:
  100.             #return Opus, MP3, "Mixed", etc.
  101.             #uses same test_tracks from earlier sample
  102.             alb_format = set()
  103.             for item in test_tracks[0:sample_size]:
  104.                 alb_format.add(item.format)        
  105.             if len(alb_format) != 1:
  106.                 alb_format = 'Mixed'
  107.             else:
  108.                 alb_format = alb_format.pop()
  109.             out_text = str(int(album_br_kbps)) + 'kbps ' + str(alb_format)
  110.         return out_text
  111.     alb_title: |
  112.         #convert long allcaps titles to title case, while leaving other titles alone
  113.         allowed_length = 3
  114.         allowed_allcaps_artists = ['573fd3e2-3f61-4329-a6c1-89e20620b0b9']
  115.         if album.isupper and len(album) > allowed_length:
  116.             if mb_albumartistid not in allowed_allcaps_artists:
  117.                 from titlecase import titlecase
  118.                 return titlecase(album)
  119.         if len(album) < 1:
  120.             return "[untitled]"
  121.         return album
  122.     alb_artist: |
  123.         VA_STR = "Various Artists"
  124.         if albumartist:
  125.             return albumartist
  126.         else:
  127.             # the album probably has no MBid
  128.             # return VA_STR if multiple artists are found on the album
  129.             my_artists = set()
  130.             for item in items:
  131.                 my_artists.add(item.artist)        
  132.                 if len(my_artists) > 1:
  133.                     return VA_STR
  134.             # every artist is the same
  135.             return my_artists.pop()
  136.  
  137. item_fields:
  138.  
  139.     i_track: |
  140.         # untested
  141.         if not track:
  142.             return None
  143.         # hotfix for beets' hardcoded 2-digit track numbers
  144.         # https://github.com/beetbox/beets/issues/3352
  145.         str_track = str(track)
  146.         # pad based on length of highest track number (per disc).
  147.         # may interact with per_disc_numbering, not sure
  148.         pad_length = len(str(tracktotal))
  149.         if pad_length < 2:
  150.             pad_length = 2
  151.         return str_track.zfill(pad_length)
  152.        
  153.     i_disc_layer: |
  154.         #do nothing for single-disc releases
  155.         if disctotal > 1:
  156.             if disc != '':
  157.                 str_disc = str(disc)
  158.                 #pad based on length of highest disc number.
  159.                 #ex. if total discs = 2 digits, pad 1 zero for discs 1-9 (01-09)
  160.                 legth_to_pad_to = len(str(disctotal))
  161.                 return str_disc.zfill(legth_to_pad_to)
  162.         return ''
  163.     i_condition: |
  164.         #set as a flex attribute(?) elsewhere
  165.         return ''
  166.     i_cust_catalog: |
  167.         #omit uninteresting formats
  168.         #these formats are bit-identical to CD
  169.         snake_oil_formats = ['Blu-spec CD', 'SHM-CD', 'HQCD']
  170.         media_types_to_omit = snake_oil_formats + ['CD', 'CD-R', 'Enhanced CD', 'CDDA', 'Digital Media', '']
  171.        
  172.         def item_cust_media():
  173.             #see https://musicbrainz.org/doc/Release/Format
  174.             if media in media_types_to_omit:
  175.                 return ''
  176.             #combine hybrid SACD with SACD, see https://en.wikipedia.org/wiki/Super_Audio_CD#Technology
  177.             elif 'SACD' in media:
  178.                 return 'SACD'
  179.             #combine all vinyl types into "Vinyl"
  180.             elif 'Vinyl' in media:
  181.                 #https://en.wikipedia.org/wiki/VinylDisc
  182.                 if media == 'VinylDisc':
  183.                     return 'VinylDisc'
  184.                 else:
  185.                     return 'Vinyl'
  186.             elif "USB" in media:
  187.                 return 'USB'
  188.             elif media == 'HD-DVD':
  189.                 return 'HD-DVD'
  190.             # note: DualDisc contains a DVD side and a CD side.
  191.             elif media == "DualDisc":
  192.                 return "DVD"
  193.             elif 'DVD' in media:
  194.                 return 'DVD'
  195.             else:
  196.                 return media
  197.            
  198.         def reissue():
  199.             if year > original_year:
  200.                 if original_year > 0:
  201.                     return str(year)
  202.             return ''
  203.         # condition = custom attribute to note (mostly) vinyl skips
  204.         # and other seriously noticable artifacts.
  205.         result = reissue() + ' ' + item_cust_media() # + i_condition()
  206.         result = result.strip(' ')
  207.         if result != '':
  208.             return ' (' + result + ')'
  209.         return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement