Browse Source

Decorators and music tags

master
Kashirigi 5 years ago
parent
commit
3b79bf964c
  1. 47
      Python/PropertyDecorator/property.py
  2. 18
      Python/mp3_m4a_tags/tagr.py

47
Python/PropertyDecorator/property.py

@ -0,0 +1,47 @@
class TestThis(object):
'''Demonstrates how to use property() as a decorator
The power of this will be in declaring essentially private variables
Property has built in property.setter, property.getter, property.deleter'''
def __init__(self):
self.voltage = 0
@property
def voltage(self):
return self._voltage
@voltage.setter
def voltage(self, value):
'''Variables inherit name of function, clearly. Can place tests on things here, if desired'''
if value < 0:
print('Voltage can not be negative')
self._voltage=0
else:
self._voltage = value
@voltage.deleter
def voltage(self):
print('Deleting voltage')
del self._voltage
@property
def higher(self):
self._higher = self.voltage*3
return self._higher
@higher.deleter
def higher(self):
print('deleted higher')
del self._higher
if __name__=='__main__':
x = TestThis()
x.voltage = -217
print(x.voltage)
print(x.higher)
x.voltage = 3
print(x.higher)
del x.higher

18
Python/mp3_m4a_tags/tagr.py

@ -0,0 +1,18 @@
import sys
from mutagen.mp4 import MP4
#print(sys.argv[1:])
# https://mutagen.readthedocs.io/en/latest/api/mp4.html#id1
conv=sys.argv[1:]
for item in conv:
if item.endswith('m4a'):
names=item.split('-')
# File names have the metadata in this case:
# 00-Song Title-Artist-Album-otherinfo.m4a
audio=MP4(item)
audio['\xa9nam']=[names[1]]
audio['\xa9ART']=[names[2]]
audio['\xa9alb']=[names[3]]
audio['\xa9gen']=['Electronic']
audio.save()
Loading…
Cancel
Save