Example #1
0
def testRequire():
    from eyed3.info import VERSION_TUPLE
    MAJOR, MINOR, MAINT = VERSION_TUPLE

    def t2s(t):
        return ".".join([str(v) for v in t])

    # test this version, x.y.z ==> x.y.z OK
    assert_true(eyed3.require(VERSION_TUPLE) is None)
    assert_true(eyed3.require(t2s(VERSION_TUPLE)) is None)

    # x.y ==> x.y.z OK
    assert_true(eyed3.require(VERSION_TUPLE[:-1]) is None)
    assert_true(eyed3.require(t2s(VERSION_TUPLE[:-1])) is None)

    # x ==> x.y.z FAIL
    assert_raises(ValueError, eyed3.require, (MAJOR, ))
    assert_raises(ValueError, eyed3.require, str(MAJOR))

    # test this version++, FAIL
    assert_raises(eyed3.Error, eyed3.require, (MAJOR + 1, MINOR, MAINT))
    assert_raises(eyed3.Error, eyed3.require, (MAJOR + 1, MINOR))
    assert_raises(eyed3.Error, eyed3.require, (MAJOR, MINOR + 1, MAINT))
    assert_raises(eyed3.Error, eyed3.require, (MAJOR, MINOR + 1))
    assert_raises(eyed3.Error, eyed3.require, (MAJOR, MINOR, MAINT + 1))
    assert_raises(eyed3.Error, eyed3.require, t2s((MAJOR + 1, MINOR, MAINT)))
    assert_raises(eyed3.Error, eyed3.require, t2s((MAJOR, MINOR + 1, MAINT)))
    assert_raises(eyed3.Error, eyed3.require, t2s((MAJOR, MINOR, MAINT + 1)))

    # test x, y--, z (0.6.x, but 0.7 installed) FAIL
    assert_raises(eyed3.Error, eyed3.require, (MAJOR, MINOR - 1, MAINT))
    assert_raises(eyed3.Error, eyed3.require, (MAJOR, MINOR - 1))
    # test -x, y, z (0.6.x, but 1.0 installed) FAIL
    assert_raises(eyed3.Error, eyed3.require, (MAJOR - 1, MINOR, MAINT))
    assert_raises(eyed3.Error, eyed3.require, (MAJOR - 1, MINOR))
Example #2
0
def _main():
    """Entry point"""
    retval = 1

    # We should run against the same install
    eyed3.require(eyed3.version)

    try:
        args, _, config = parseCommandLine()

        eyed3.utils.console.AnsiCodes.init(not args.no_color)

        mainFunc = main if args.debug_profile is False else profileMain
        retval = mainFunc(args, config)
    except KeyboardInterrupt:
        retval = 0
    except (StopIteration, IOError) as ex:
        eyed3.utils.console.printError(UnicodeType(ex))
        retval = 1
    except Exception as ex:
        eyed3.utils.console.printError("Uncaught exception: %s\n" % str(ex))
        eyed3.log.exception(ex)

        if args.debug_pdb:
            try:
                with warnings.catch_warnings():
                    warnings.simplefilter("ignore", PendingDeprecationWarning)
                    # Must delay the import of ipdb as say as possible because
                    # of https://github.com/gotcha/ipdb/issues/48
                    import ipdb as pdb
            except ImportError:
                import pdb

            e, m, tb = sys.exc_info()
            pdb.post_mortem(tb)
    finally:
        sys.exit(retval)
Example #3
0
    # Reparse the command line including options from the config.
    args = parser.parse_args(args=cmd_line_args)

    args.plugin = plugin
    eyed3.log.debug("command line args: %s", args)
    eyed3.log.debug("plugin is: %s", plugin)

    return args, parser, config


if __name__ == "__main__":  # pragma: no cover
    retval = 1

    # We should run against the same install
    eyed3.require(eyed3.info.VERSION)

    try:
        args, _, config = parseCommandLine()

        eyed3.utils.console.AnsiCodes.init(not args.no_color)

        mainFunc = main if args.debug_profile is False else profileMain
        retval = mainFunc(args, config)
    except KeyboardInterrupt:
        retval = 0
    except (StopIteration, IOError) as ex:
        eyed3.utils.console.printError(unicode(ex))
        retval = 1
    except Exception as ex:
        eyed3.utils.console.printError("Uncaught exception: %s\n" % str(ex))
Example #4
0
    # Reparse the command line including options from the config.
    args = parser.parse_args(args=cmd_line_args)

    args.plugin = plugin
    eyed3.log.debug("command line args: %s", args)
    eyed3.log.debug("plugin is: %s", plugin)

    return args, parser, config


if __name__ == "__main__":  # pragma: no cover
    retval = 1

    # We should run against the same install
    eyed3.require(eyed3.info.VERSION)

    try:
        args, _, config = parseCommandLine()

        eyed3.utils.console.AnsiCodes.init(not args.no_color)

        mainFunc = main if args.debug_profile is False else profileMain
        retval = mainFunc(args, config)
    except KeyboardInterrupt:
        retval = 0
    except (StopIteration, IOError) as ex:
        eyed3.utils.console.printError(unicode(ex))
        retval = 1
    except Exception as ex:
        eyed3.utils.console.printError("Uncaught exception: %s\n" % str(ex))
Example #5
0
import copy
import datetime
import fnmatch
import os
import sys

import eyed3
from eyed3 import core, id3
from eyed3 import LOCAL_ENCODING
from eyed3.plugins import load, LoaderPlugin
from eyed3.utils.console import printMsg, printError, printWarning

eyed3.require((0, 7))

class AutotagPlugin(LoaderPlugin):
    SUMMARY = u'Automagically tag MP3s based on their filename and the parent folder name'
    DESCRIPTION = u"""
Description here
"""
    NAMES = ['autotag']

    def __init__(self, arg_parser):
        super(AutotagPlugin, self).__init__(arg_parser)
        g = self.arg_group

        self.meta = None

        def UnicodeArg(arg):
            return unicode(arg, LOCAL_ENCODING)

        # CLI options
Example #6
0
from __future__ import print_function
import eyed3
from eyed3.plugins import Plugin
from eyed3.utils import guessMimetype

eyed3.require((0, 7))


class EchoPlugin(eyed3.plugins.Plugin):
    NAMES = ["echo"]
    SUMMARY = u"Displays each filename and mime-type passed to the plugin"

    def handleFile(self, f):
        print("%s\t[ %s ]" % (f, guessMimetype(f)))
Example #7
0
#!/usr/bin/env python
# -*- coding: utf_8 -*-

import eyed3
import os
import sqlite3 as sl
import shutil

eyed3.require("0.7")

pod = '/media/ipod-backup'
dst = '/media/ipod-music-export'

dbf = '%s/iTunes_Control/iTunes/MediaLibrary.sqlitedb' % pod
print '>>> using database file %s' % dbf

con = sl.connect(dbf)
cur = con.cursor()
cur.execute('SELECT SQLITE_VERSION()')

data = cur.fetchone()
print 'SQLite version: %s' % data


def dict_factory(cursor, row):
    d = {}
    for idx, col in enumerate(cursor.description):
        d[col[0]] = row[idx]
    return d

Example #8
0
#!/usr/bin/env python2
# -> eyed3 is only tested with py2

from __future__ import print_function
import eyed3
eyed3.require('0.7.5')
import logging


class Mp3Tag:
    def __init__(self, fname):
        self.tag = eyed3.load(fname).tag

    def convert(self, encoding='utf-8', backup=True, preserve_file_time=True):
        self.tag.save(encoding=encoding,
                      backup=backup,
                      preserve_file_time=preserve_file_time)

    def getLyrics(self):
        return self.tag.lyrics[0].text

    def setLogLevel(self, level):
        # affecting eyed3's log level
        elog = eyed3.utils.log
        elog.log.setLevel(level)  ## e.g. logging.DEBUG
Example #9
0
from nicfit import Application, ConfigOpts
from sqlalchemy import exc as sql_exceptions


import eyed3

from eyed3.utils.console import AnsiCodes
from eyed3.utils.console import Fore as fg
from eyed3.utils.prompt import PromptExit

from .database import MissingSchemaException
from .config import DEFAULT_CONFIG, CONFIG_ENV_VAR, Config, MAIN_SECT, SA_KEY
from .commands.command import Command
from . import log

eyed3.require("0.8")


def _pErr(subject, msg):
    print(fg.red(subject) + ": %s" % str(msg))


def main(args):
    if "func" not in args:
        # No command was given.
        args.app.arg_parser.print_help()
        return 1

    logging.config.fileConfig(args.config)
    # In the case fileConfig undid the command line, typically not necessary.
    args.applyLoggingOpts(args.log_levels, args.log_files)
Example #10
0
#!/usr/bin/env python2
# -> eyed3 is only tested with py2

from __future__ import print_function
import eyed3
eyed3.require('0.7.5')
import logging


class Mp3Tag:
    def __init__(self, fname):
        self.tag = eyed3.load(fname).tag

    def convert(self, encoding='utf-8', backup=True, preserve_file_time=True):
        self.tag.save(encoding=encoding,
                      backup=backup,
                      preserve_file_time=preserve_file_time)

    def getLyrics(self):
        return self.tag.lyrics[0].text

    def setLogLevel(self, level):
        # affecting eyed3's log level
        elog = eyed3.utils.log
        elog.log.setLevel(level)    ## e.g. logging.DEBUG


Example #11
0
#!/usr/bin/env python
# -*- coding: utf_8 -*-

import eyed3
import os
import sqlite3 as sl
import shutil

eyed3.require("0.7")

pod = '/media/ipod-backup'
dst = '/media/ipod-music-export'

dbf = '%s/iTunes_Control/iTunes/MediaLibrary.sqlitedb' % pod
print '>>> using database file %s' % dbf

con = sl.connect(dbf)
cur = con.cursor()
cur.execute('SELECT SQLITE_VERSION()')

data = cur.fetchone()
print 'SQLite version: %s' % data

def dict_factory(cursor, row):
	d = {}
	for idx, col in enumerate(cursor.description):
		d[col[0]] = row[idx]
	return d
con.row_factory = dict_factory
con.text_factory = str
cur = con.cursor()