From 3b79bf964c5eaedaab206242a876089cf316b8ea Mon Sep 17 00:00:00 2001 From: Kashirigi Date: Wed, 3 Jul 2019 11:14:10 -0700 Subject: [PATCH] Decorators and music tags --- Python/PropertyDecorator/property.py | 47 ++++++++++++++++++++++++++++ Python/mp3_m4a_tags/tagr.py | 18 +++++++++++ 2 files changed, 65 insertions(+) create mode 100644 Python/PropertyDecorator/property.py create mode 100644 Python/mp3_m4a_tags/tagr.py diff --git a/Python/PropertyDecorator/property.py b/Python/PropertyDecorator/property.py new file mode 100644 index 0000000..ee901a6 --- /dev/null +++ b/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 + + + + diff --git a/Python/mp3_m4a_tags/tagr.py b/Python/mp3_m4a_tags/tagr.py new file mode 100644 index 0000000..ec58608 --- /dev/null +++ b/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() + +