Skip to content

Commit

Permalink
Reformat a lot of things
Browse files Browse the repository at this point in the history
  • Loading branch information
palfrey committed Feb 3, 2022
1 parent 1c4caf5 commit 15bf7c0
Show file tree
Hide file tree
Showing 20 changed files with 209 additions and 172 deletions.
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 21.12b0
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 4.0.1
hooks:
- id: flake8
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Just like TagLib, TagPy can:
- access APE tags in Musepack and MP3 files.

All these have their own specific interfaces, but TagLib's generic tag
reading and writing mechanism is also supported.
reading and writing mechanism is also supported.

You can find examples in the test/ directory.

Expand Down Expand Up @@ -62,7 +62,7 @@ TagPy works for me with
- Boost.Python 1.33
- gcc 4.0

I have reason to believe that slightly older versions of gcc and
I have reason to believe that slightly older versions of gcc and
Boost.Python should be fine, but the 1.4 requirement for TagLib is
firm. Anything newer is also ok.

Expand Down Expand Up @@ -90,7 +90,7 @@ For details, you may consult the file `INSTALL' in the TagLib distribution.
Step 3: Installing TagPy
------------------------

Then, run
Then, run

python setup.py build

Expand All @@ -101,7 +101,7 @@ Finally, typing

su -c "python setup.py install"

will complete the installation.
will complete the installation.

Congratulations! You are now ready to use TagPy.

Expand All @@ -115,7 +115,7 @@ Using TagPy is as simple as this:
>>> f.tag().artist
u'Andreas'

The `test/` directory contains a few more examples.
The `test/` directory contains a few more examples.

In general, TagPy duplicates the TagLib API, with a few notable
exceptions:
Expand All @@ -126,7 +126,7 @@ exceptions:
- Enumerations form their own scope and are not part of any
enclosing class scope, if any.

For example, the value `TagLib::String::UTF16BE` from the
For example, the value `TagLib::String::UTF16BE` from the
enum `TagLib::String::Type` is now `tagpy.StringType.UTF16BE`.

- `TagLib::String` objects are mapped to and expected as Python
Expand Down
12 changes: 6 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
TagPy is a set of Python bindings for Scott Wheeler's
`TagLib <http://developer.kde.org/~wheeler/taglib.html>`_.
It builds upon `Boost.Python <http://www.boost.org/libs/python/doc/>`_,
a wrapper generation library which is part of the renowned Boost
TagPy is a set of Python bindings for Scott Wheeler's
`TagLib <http://developer.kde.org/~wheeler/taglib.html>`_.
It builds upon `Boost.Python <http://www.boost.org/libs/python/doc/>`_,
a wrapper generation library which is part of the renowned Boost
set of C++ libraries.

Just like TagLib, TagPy can:
Expand All @@ -11,6 +11,6 @@ Just like TagLib, TagPy can:
* access Xiph Comments in Ogg Vorbis Files and Ogg Flac Files,
* access APE tags in Musepack and MP3 files.

All these features have their own specific interfaces, but
TagLib's generic tag reading and writing mechanism is also
All these features have their own specific interfaces, but
TagLib's generic tag reading and writing mechanism is also
supported. It comes with a bunch of examples.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[flake8]
ignore = E126,E127,E128,E123,E226,E241,E242
max-line-length=85
max-line-length=88
89 changes: 45 additions & 44 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,51 +27,52 @@

def main():

INCLUDE_DIRS = "" # conf["TAGLIB_INC_DIR"] + conf["BOOST_INC_DIR"]
LIBRARY_DIRS = "" # conf["TAGLIB_LIB_DIR"] + conf["BOOST_LIB_DIR"]
LIBRARIES = "" # conf["TAGLIB_LIBNAME"] + conf["BOOST_PYTHON_LIBNAME"]
INCLUDE_DIRS = "" # conf["TAGLIB_INC_DIR"] + conf["BOOST_INC_DIR"]
LIBRARY_DIRS = "" # conf["TAGLIB_LIB_DIR"] + conf["BOOST_LIB_DIR"]
LIBRARIES = "" # conf["TAGLIB_LIBNAME"] + conf["BOOST_PYTHON_LIBNAME"]

setup(name="tagpy",
version="2018.1.1",
description="Python Bindings for TagLib",
long_description=open("README.rst", "rt").read(),
author="Andreas Kloeckner",
author_email="[email protected]",
classifiers=
[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Operating System :: POSIX",
"Operating System :: Unix",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Topic :: Multimedia :: Sound/Audio",
"Topic :: Multimedia :: Sound/Audio :: CD Audio :: CD Ripping",
"Topic :: Multimedia :: Sound/Audio :: Editors",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Utilities"],
license="MIT",
setup(
name="tagpy",
version="2018.1.1",
description="Python Bindings for TagLib",
long_description=open("README.rst", "rt").read(),
author="Andreas Kloeckner",
author_email="[email protected]",
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Operating System :: POSIX",
"Operating System :: Unix",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Topic :: Multimedia :: Sound/Audio",
"Topic :: Multimedia :: Sound/Audio :: CD Audio :: CD Ripping",
"Topic :: Multimedia :: Sound/Audio :: Editors",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Utilities",
],
license="MIT",
url="http://mathema.tician.de/software/tagpy",
packages=["tagpy", "tagpy.ogg"],
ext_modules=[
Extension(
"_tagpy",
[
"src/wrapper/basics.cpp",
"src/wrapper/id3.cpp",
"src/wrapper/rest.cpp",
],
include_dirs=INCLUDE_DIRS,
library_dirs=LIBRARY_DIRS,
libraries=LIBRARIES,
extra_compile_args="", # conf["CXXFLAGS"],
),
],
)

install_requires=["pytest"],

url="http://mathema.tician.de/software/tagpy",
packages=["tagpy", "tagpy.ogg"],
ext_modules=[
Extension("_tagpy",
["src/wrapper/basics.cpp",
"src/wrapper/id3.cpp",
"src/wrapper/rest.cpp"],
include_dirs=INCLUDE_DIRS,
library_dirs=LIBRARY_DIRS,
libraries=LIBRARIES,
extra_compile_args="", # conf["CXXFLAGS"],
),
]
)


if __name__ == '__main__':
if __name__ == "__main__":
main()
8 changes: 4 additions & 4 deletions src/wrapper/basics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
Expand Down Expand Up @@ -36,7 +36,7 @@



namespace
namespace
{
struct tlstring_to_unicode
{
Expand Down Expand Up @@ -159,7 +159,7 @@ BOOST_PYTHON_MODULE(_tagpy)
.add_property("genre", &cl::genre, &cl::setGenre)
.add_property("year", &cl::year, &cl::setYear)
.add_property("track", &cl::track, &cl::setTrack)

.DEF_VIRTUAL_METHOD(isEmpty)
.DEF_SIMPLE_METHOD(duplicate)
.staticmethod("duplicate")
Expand Down Expand Up @@ -187,7 +187,7 @@ BOOST_PYTHON_MODULE(_tagpy)

class_<FileWrap, boost::noncopyable>("File", no_init)
.def("name", &File::name)
.def("audioProperties", pure_virtual(&File::audioProperties),
.def("audioProperties", pure_virtual(&File::audioProperties),
return_internal_reference<>())
.def("tag", pure_virtual(&File::tag),
return_internal_reference<>())
Expand Down
8 changes: 3 additions & 5 deletions src/wrapper/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
Expand Down Expand Up @@ -59,7 +59,7 @@ using namespace std;
#warning !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#warning TagPy is meant to wrap TagLib 1.4 and above.
#warning !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#endif
#endif



Expand Down Expand Up @@ -101,7 +101,7 @@ namespace {
object Map_keys(Map<Key, Value> &m)
{
boost::python::list keys;

typedef Map<Key, Value> map;
typename map::Iterator first = m.begin(), last = m.end();
while (first != last)
Expand Down Expand Up @@ -221,5 +221,3 @@ namespace {
;
}
}


14 changes: 7 additions & 7 deletions src/wrapper/rest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
Expand Down Expand Up @@ -191,15 +191,15 @@ void exposeRest()
class_<cl, boost::noncopyable, bases<File> >("flac_File",
init<const char *, optional<bool, AudioProperties::ReadStyle> >())
.def(init<const char *, ID3v2::FrameFactory *, optional<bool, AudioProperties::ReadStyle> >())
.def("ID3v1Tag",
.def("ID3v1Tag",
(ID3v1::Tag *(FLAC::File::*)(bool))
&FLAC::File::ID3v1Tag,
ID3v1Tag_overloads()[return_internal_reference<>()])
.def("ID3v2Tag",
.def("ID3v2Tag",
(ID3v2::Tag *(FLAC::File::*)(bool))
&FLAC::File::ID3v2Tag,
ID3v2Tag_overloads()[return_internal_reference<>()])
.def("xiphComment",
.def("xiphComment",
(Ogg::XiphComment *(FLAC::File::*)(bool))
&FLAC::File::xiphComment,
xiphComment_overloads()[return_internal_reference<>()])
Expand All @@ -224,15 +224,15 @@ void exposeRest()
typedef MPC::File cl;
class_<MPC::File, bases<File>, boost::noncopyable>
("mpc_File", init<const char *, optional<bool, AudioProperties::ReadStyle> >())
.def("ID3v1Tag",
.def("ID3v1Tag",
(ID3v1::Tag *(cl::*)(bool))
&cl::ID3v1Tag,
ID3v1Tag_overloads()[return_internal_reference<>()])
.def("APETag",
.def("APETag",
(APE::Tag *(cl::*)(bool))
&cl::APETag,
APETag_overloads()[return_internal_reference<>()])
.def("remove",
.def("remove",
(void (cl::*)(int))
&cl::remove,
remove_overloads())
Expand Down
49 changes: 26 additions & 23 deletions tagpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,28 @@
# SOFTWARE.


import _tagpy
from _tagpy import Tag, File, AudioProperties, StringType, ReadStyle
#AudioProperties.ReadStyle = _tagpy.ReadStyle
from _tagpy import File, ReadStyle


class FileTypeResolver(object):
def createFile(self, fileName, readAudioProperties=True,
audioPropertiesStyle=ReadStyle.Average):
def createFile(
self, fileName, readAudioProperties=True, audioPropertiesStyle=ReadStyle.Average
):
raise NotImplementedError


class FileRef(object):
fileTypeResolvers = []

def __init__(self, f, readAudioProperties=True,
audioPropertiesStyle=ReadStyle.Average):
def __init__(
self, f, readAudioProperties=True, audioPropertiesStyle=ReadStyle.Average
):
if isinstance(f, FileRef):
self._file = f._file
elif isinstance(f, File):
self._file = f
else:
self._file = FileRef.create(f, readAudioProperties,
audioPropertiesStyle)
self._file = FileRef.create(f, readAudioProperties, audioPropertiesStyle)

def tag(self):
return self._file.tag()
Expand Down Expand Up @@ -75,33 +74,37 @@ def _getExtToModule():
import tagpy.flac
import tagpy.mpc

#import tagpy.wavpack, tagpy.ogg.speex, tagpy.trueaudio
# import tagpy.wavpack, tagpy.ogg.speex, tagpy.trueaudio

return {
"ogg": tagpy.ogg.vorbis,
"mp3": tagpy.mpeg,
"oga": tagpy.ogg.flac,
"flac": tagpy.flac,
"mpc": tagpy.mpc,
#".wv": tagpy.wavpack,
#".spx": tagpy.ogg.speex,
#".tta": tagpy.trueaudio,
}
"ogg": tagpy.ogg.vorbis,
"mp3": tagpy.mpeg,
"oga": tagpy.ogg.flac,
"flac": tagpy.flac,
"mpc": tagpy.mpc,
# ".wv": tagpy.wavpack,
# ".spx": tagpy.ogg.speex,
# ".tta": tagpy.trueaudio,
}

@classmethod
def create(cls, fileName, readAudioProperties=True,
audioPropertiesStyle=ReadStyle.Average):
def create(
cls, fileName, readAudioProperties=True, audioPropertiesStyle=ReadStyle.Average
):
for resolver in cls.fileTypeResolvers:
file = resolver.createFile(fileName, readAudioProperties,
audioPropertiesStyle)
file = resolver.createFile(
fileName, readAudioProperties, audioPropertiesStyle
)
if file:
return file

from os.path import exists

if not exists(fileName):
raise IOError("File does not exist")

from os.path import splitext

ext = splitext(fileName)[1][1:].lower()

try:
Expand Down
Loading

0 comments on commit 15bf7c0

Please sign in to comment.