Add release_date
This commit is contained in:
@@ -3,12 +3,14 @@ import re
|
|||||||
import struct
|
import struct
|
||||||
import shutil
|
import shutil
|
||||||
import itunespy
|
import itunespy
|
||||||
|
import datetime
|
||||||
import urllib.request
|
import urllib.request
|
||||||
from tempfile import NamedTemporaryFile
|
from tempfile import NamedTemporaryFile
|
||||||
|
|
||||||
from beets import config
|
from beets import config
|
||||||
from beets.autotag.hooks import AlbumInfo, TrackInfo, Distance
|
from beets.autotag.hooks import AlbumInfo, TrackInfo, Distance
|
||||||
from beets.plugins import BeetsPlugin, sanitize_choices
|
from beets.plugins import BeetsPlugin, sanitize_choices
|
||||||
|
from beets.dbcore import types
|
||||||
import beets.mediafile as mediafile
|
import beets.mediafile as mediafile
|
||||||
|
|
||||||
AVAILABLE_COUNTRIES = ['DE', 'US', 'GB', 'FR', 'AU', 'CA', 'IT', 'JP', 'DZ', 'AO', 'AI', 'AG', 'AR', 'AM', 'AT', 'AZ', 'BS', 'BH', 'BD', 'BB', 'BY', 'BE', 'BZ', 'BM', 'BO', 'BW', 'BR', 'BN', 'BG', 'CM', 'KY', 'CL', 'CN', 'CO', 'CR', 'CI', 'HR', 'CY', 'CZ', 'DK', 'DM', 'DO', 'EC', 'EG', 'SV', 'EE', 'ET', 'FI', 'GH', 'GR', 'GD', 'GT', 'GY', 'HN', 'HK', 'HU', 'IS', 'IN', 'ID', 'IE', 'IL', 'JM', 'JO', 'KZ', 'KE', 'KR', 'KW', 'LV', 'LB', 'LY', 'LI', 'LT', 'LU', 'MO', 'MK', 'MG', 'MY', 'MV', 'ML', 'MT', 'MU', 'MX', 'MD', 'MS', 'MM', 'NP', 'NL', 'NZ', 'NI', 'NE', 'NG', 'NO', 'OM', 'PK', 'PA', 'PY', 'PE', 'PH', 'PL', 'PT', 'QA', 'RO', 'RU', 'KN', 'LC', 'VC', 'SA', 'SN', 'RS', 'SG', 'SK', 'SI', 'ZA', 'ES', 'LK', 'SR', 'SE', 'CH', 'TW', 'TZ', 'TH', 'TT', 'TN', 'TR', 'TC', 'UG', 'UA', 'AE', 'UY', 'UZ', 'VE', 'VN', 'VG', 'YE']
|
AVAILABLE_COUNTRIES = ['DE', 'US', 'GB', 'FR', 'AU', 'CA', 'IT', 'JP', 'DZ', 'AO', 'AI', 'AG', 'AR', 'AM', 'AT', 'AZ', 'BS', 'BH', 'BD', 'BB', 'BY', 'BE', 'BZ', 'BM', 'BO', 'BW', 'BR', 'BN', 'BG', 'CM', 'KY', 'CL', 'CN', 'CO', 'CR', 'CI', 'HR', 'CY', 'CZ', 'DK', 'DM', 'DO', 'EC', 'EG', 'SV', 'EE', 'ET', 'FI', 'GH', 'GR', 'GD', 'GT', 'GY', 'HN', 'HK', 'HU', 'IS', 'IN', 'ID', 'IE', 'IL', 'JM', 'JO', 'KZ', 'KE', 'KR', 'KW', 'LV', 'LB', 'LY', 'LI', 'LT', 'LU', 'MO', 'MK', 'MG', 'MY', 'MV', 'ML', 'MT', 'MU', 'MX', 'MD', 'MS', 'MM', 'NP', 'NL', 'NZ', 'NI', 'NE', 'NG', 'NO', 'OM', 'PK', 'PA', 'PY', 'PE', 'PH', 'PL', 'PT', 'QA', 'RO', 'RU', 'KN', 'LC', 'VC', 'SA', 'SN', 'RS', 'SG', 'SK', 'SI', 'ZA', 'ES', 'LK', 'SR', 'SE', 'CH', 'TW', 'TZ', 'TH', 'TT', 'TN', 'TR', 'TC', 'UG', 'UA', 'AE', 'UY', 'UZ', 'VE', 'VN', 'VG', 'YE']
|
||||||
@@ -16,14 +18,20 @@ VA_ARTIST_ID = 120644327
|
|||||||
|
|
||||||
_track_ids = {}
|
_track_ids = {}
|
||||||
|
|
||||||
class SearchAPIPlugin(BeetsPlugin):
|
class iTunesPlugin(BeetsPlugin):
|
||||||
"""A beets plugin that adds the iTunes API as a metadata source.
|
"""A beets plugin that adds the iTunes API as a metadata source.
|
||||||
The plugin can also lookup song metadata of songs the have been
|
The plugin can also lookup song metadata of songs the have been
|
||||||
matched by iTunes Match.
|
matched by iTunes Match.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(SearchAPIPlugin, self).__init__()
|
super(iTunesPlugin, self).__init__()
|
||||||
|
self.add_media_field('release_date', mediafile.MediaField(
|
||||||
|
mediafile.MP3StorageStyle('TDRC'),
|
||||||
|
mediafile.MP4StorageStyle('\xa9day'),
|
||||||
|
mediafile.StorageStyle('DATE'),
|
||||||
|
mediafile.ASFStorageStyle('WM/Year')
|
||||||
|
))
|
||||||
self.add_media_field('title_sort', mediafile.MediaField(
|
self.add_media_field('title_sort', mediafile.MediaField(
|
||||||
mediafile.MP3StorageStyle('TSOT'),
|
mediafile.MP3StorageStyle('TSOT'),
|
||||||
mediafile.MP4StorageStyle('sonm'),
|
mediafile.MP4StorageStyle('sonm'),
|
||||||
@@ -36,6 +44,12 @@ class SearchAPIPlugin(BeetsPlugin):
|
|||||||
mediafile.StorageStyle('ALBUMSORT'),
|
mediafile.StorageStyle('ALBUMSORT'),
|
||||||
mediafile.ASFStorageStyle('WM/AlbumSortOrder')
|
mediafile.ASFStorageStyle('WM/AlbumSortOrder')
|
||||||
))
|
))
|
||||||
|
self.add_media_field('copyright', mediafile.MediaField(
|
||||||
|
mediafile.MP3StorageStyle('TCOP'),
|
||||||
|
mediafile.MP4StorageStyle('cprt'),
|
||||||
|
mediafile.StorageStyle('COPYRIGHT'),
|
||||||
|
mediafile.ASFStorageStyle('Copyright')
|
||||||
|
))
|
||||||
self.add_media_field('itunes_content_id', mediafile.MediaField(
|
self.add_media_field('itunes_content_id', mediafile.MediaField(
|
||||||
mediafile.MP4StorageStyle('cnID', as_type=int),
|
mediafile.MP4StorageStyle('cnID', as_type=int),
|
||||||
mediafile.StorageStyle(u'ITUNES_CONTENT_ID', as_type=int)
|
mediafile.StorageStyle(u'ITUNES_CONTENT_ID', as_type=int)
|
||||||
@@ -44,10 +58,6 @@ class SearchAPIPlugin(BeetsPlugin):
|
|||||||
mediafile.MP4StorageStyle('atID', as_type=int),
|
mediafile.MP4StorageStyle('atID', as_type=int),
|
||||||
mediafile.StorageStyle(u'ITUNES_ARTIST_ID', as_type=int)
|
mediafile.StorageStyle(u'ITUNES_ARTIST_ID', as_type=int)
|
||||||
))
|
))
|
||||||
self.add_media_field('itunes_genre_id', mediafile.MediaField(
|
|
||||||
mediafile.MP4StorageStyle('geID', as_type=int),
|
|
||||||
mediafile.StorageStyle('ITUNES_GENRE_ID', as_type=int)
|
|
||||||
))
|
|
||||||
self.add_media_field('itunes_advisory', mediafile.MediaField(
|
self.add_media_field('itunes_advisory', mediafile.MediaField(
|
||||||
mediafile.MP4StorageStyle('rtng', as_type=int),
|
mediafile.MP4StorageStyle('rtng', as_type=int),
|
||||||
mediafile.StorageStyle('ITUNES_ADVISORY', as_type=int)
|
mediafile.StorageStyle('ITUNES_ADVISORY', as_type=int)
|
||||||
@@ -206,18 +216,15 @@ class SearchAPIPlugin(BeetsPlugin):
|
|||||||
def apply_itunes_metadata(self, session, task):
|
def apply_itunes_metadata(self, session, task):
|
||||||
for item in task.imported_items():
|
for item in task.imported_items():
|
||||||
info = task.match.mapping[item]
|
info = task.match.mapping[item]
|
||||||
try:
|
for tag in ['genre', 'title_sort', 'album_sprt', 'itunes_content_id', 'itunes_artist_id', 'itunes_advisory']:
|
||||||
item.genre = info.genre
|
item[tag] = getattr(info, tag, None)
|
||||||
if not item.title == info.title_sort:
|
if task.is_album:
|
||||||
item.title_sort = info.title_sort
|
album_info = task.match.info
|
||||||
if not item.album == info.album_sort:
|
for tag in ['copyright']:
|
||||||
item.album_sort = info.album_sort
|
item[tag] = getattr(album_info, tag, None)
|
||||||
item.itunes_content_id = info.itunes_content_id
|
# Fix Release Date
|
||||||
item.itunes_artist_id = info.itunes_artist_id
|
item.release_date = "%04i-%02i-%02i" % (album_info.year, album_info.month, album_info.day)
|
||||||
item.itunes_advisory = info.itunes_advisory
|
item.itunes_media_type = 1 # Set media type to "Music"
|
||||||
item.itunes_media_type = 1 # Set media type to "Music"
|
|
||||||
except AttributeError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def fetch_artwork(self, session, task):
|
def fetch_artwork(self, session, task):
|
||||||
try:
|
try:
|
||||||
@@ -280,6 +287,7 @@ class SearchAPIPlugin(BeetsPlugin):
|
|||||||
info.genre = album.primary_genre_name
|
info.genre = album.primary_genre_name
|
||||||
info.itunes_advisory = decode_explicitness(album.collection_explicitness)
|
info.itunes_advisory = decode_explicitness(album.collection_explicitness)
|
||||||
info.itunes_artwork_url = decode_artwork_url(album.artwork_url_100)
|
info.itunes_artwork_url = decode_artwork_url(album.artwork_url_100)
|
||||||
|
info.copyright = album.copyright
|
||||||
return info
|
return info
|
||||||
|
|
||||||
def make_track_info(self, track, index):
|
def make_track_info(self, track, index):
|
||||||
|
|||||||
Reference in New Issue
Block a user