Пример #1
0
    def getfilenames(self, infile):
        outfile = infile.replace(
            self.inputdir, self.outputdir + "/",
            1)  #Replace source directory in the output file name
        fileext = utils.getfileext(outfile)
        if fileext in convertable:
            outfile = outfile.replace(fileext, self.outformat, 1)
            toprint = "Converting " + infile.replace(os.getcwd(), "", 1)
        else:
            toprint = "Copying " + infile.replace(os.getcwd(), "", 1)

        outfile = utils.cleanstr(outfile)  #Add \ for special characters
        infile = utils.cleanstr(infile)
        return [infile, outfile, toprint]
Пример #2
0
 def normalize(self):
     tonormalize = [
         os.path.join(root, name)
         for root, dirs, files in os.walk(os.getcwd() + "/" +
                                          self.outputdir) for name in files
         if name.endswith(tuple(convertable))
     ]
     i = 0
     for f in tonormalize:
         f = utils.cleanstr(f)
         tonormalize[i] = f
         i += 1
     utils.action("Normalizing files.")
     try:
         if self.verbosity == False:
             os.system("mp3gain -k -r -d " + str(self.decibel) + " " +
                       " ".join(tonormalize) + " >/dev/null 2>&1")
         else:
             os.system("mp3gain -k -r -d " + str(self.decibel) + " " +
                       " ".join(tonormalize))
     except:
         utils.alert("Error during normalizing files.")
Пример #3
0
def main():

    #Arg parser
    parser = argparse.ArgumentParser(
        description=
        'This is a little python script which converts any file whose format is accepted by ffmpeg ( also mp4, mov... ) into a desired format, keeping metadatas, editing bitrate, audio channels, and even normalizing them using mp3gain.'
    )
    parser.add_argument('-i',
                        '--input',
                        nargs='+',
                        metavar='My Music',
                        type=str,
                        help='Input directory name ( No / ).',
                        required=True)
    parser.add_argument('-o',
                        '--output',
                        nargs='+',
                        metavar='My Converted Music',
                        type=str,
                        help='Output directory name ( No / ).',
                        required=True)
    parser.add_argument('-f',
                        '--format',
                        metavar='mp3',
                        type=str,
                        help="Output file format (mp3,flac,wav ... ) .",
                        required=True)
    parser.add_argument(
        '-b',
        '--bitrate',
        metavar='320',
        type=int,
        help="Change the bitrate of the output file (128kbps by default ).",
        required=False)
    parser.add_argument('-c',
                        '--channels',
                        metavar='2',
                        type=int,
                        help="Output audio channels (Stereo by default).",
                        required=False)
    parser.add_argument(
        '-t',
        '--threads',
        metavar='10',
        type=int,
        help=
        "Set number of thread to use while converting a file, be careful with this setting, it's suggested not to use higher value than 10 (1 By default ) .",
        required=False)
    parser.add_argument(
        '-d',
        '--decibel',
        metavar='1.0',
        help=
        "Modify suggested dB gain of the normalization ( Works only if normalization is enabled, 1.0 by default ).",
        required=False)
    parser.add_argument(
        '-n',
        '--normalize',
        help=
        "Enable normalization of converted files using mp3gain ( Disabled by default ).",
        action='store_true',
        required=False)
    parser.add_argument(
        '-v',
        '--verbosity',
        help=
        "Increase verbosity if toggled, show ffmpeg and mp3gain commands output ( Disabled by default ).",
        action='store_true',
        required=False)
    args = parser.parse_args()

    #Load args into variables
    inputdir = ' '.join(args.input)
    outputdir = ' '.join(args.output)
    outformat = args.format

    #Check if non required args are not empty, and if yes set a default value
    if args.bitrate != None:
        bitrate = args.bitrate
    else:
        bitrate = "128"

    if args.verbosity != None:
        verbosity = args.verbosity
    else:
        verbosity = False

    if args.threads != None:
        threads = args.threads
    else:
        threads = "1"

    if args.channels != None:
        channels = args.channels
    else:
        channels = "2"

    if args.normalize != None:
        normalize = args.normalize
    else:
        normalize = False

    if args.decibel != None:
        decibel = float(args.decibel)
    else:
        decibel = 1.0

    utils.init()
    if normalize == True:
        if utils.mp3gain() == False:
            utils.alert(
                "In order to normalize your files you need to install mp3gain."
            )
            return
    if utils.ffmpeg() == False:
        return

    #Check if input directory exists
    if not os.path.exists(inputdir):
        utils.alert("Input directory doesn't exist, quitting...")
        return

    #If the directory doesn't exist create it
    if not os.path.exists(outputdir):
        os.system("mkdir " + utils.cleanstr(outputdir))

    #Load files to be converted in a list
    toconvert = [
        os.path.join(root, name)
        for root, dirs, files in os.walk(os.getcwd() + "/" + inputdir)
        for name in files if name.endswith(tuple(all_files))
    ]  #http://stackoverflow.com/questions/5817209/browse-files-and-subfolders-in-python

    #Load the new files to be converted in a list
    new = utils.alreadyConverted(inputdir, outputdir, outformat)

    mans = ''
    if new != -1:
        while mans != 'no' and mans != 'yes' and mans != 'y' and mans != 'n':
            mans = utils.input(
                "Found " + str(len(new) - 1) +
                " new files to be converted. Would you like to convert only the new ones?(y/n): "
            )
        if mans == 'y' or mans == 'yes':
            new.pop()
            toconvert = new

    #Create Converter instance
    MyConverter = Converter(toconvert, outformat, inputdir, outputdir, threads,
                            channels, bitrate, normalize, decibel, verbosity)

    utils.action(str(len(toconvert)) + " files loaded.")
    utils.action("Size of files to be converted: " +
                 str(utils.getdirsize(inputdir)) + " MB.")
    utils.action("Estimated conversion time (normalization not included): " +
                 str((utils.getdirsize(inputdir) * cspeed / 60) /
                     int(threads)) + " minutes.")
    MyConverter.getSettings()
    ans = ''
    while ans != 'no' and ans != 'yes' and ans != 'y' and ans != 'n':
        ans = utils.input(
            "These are your settings, would you like to continue?(y/n): ")
        if ans == 'no' or ans == 'n':
            utils.action("Quitting.")
            return

    start_time = timeit.default_timer()
    try:
        conv = MyConverter.convert()
    except KeyboardInterrupt:
        return

    if normalize == True:
        MyConverter.normalize()
    elapsed = timeit.default_timer() - start_time

    utils.action("Converted " + str(conv) + "/" + str(len(toconvert)) +
                 " files in " + str(int(elapsed) / 60) + " minutes.")
Пример #4
0
def get(tweet, inventory, id, position):
    rend = re.sub(r'http\S+', '', tweet).lower().split() # remove articles here?
    if (rend[0] == 'drop') and (len(rend) >= 2): # drop(0) banana(1) # drop(0) the(1) dawn(2) porter(3)
        quantity = None
        if (len(rend) >= 3) and (rend[1] == 'all'): # or check if it can be converted to a valid int
            quantity = 'all'
            drop_item = cleanstr(' '.join(rend[2:len(rend)]))
        elif (len(rend) >= 3) and ((rend[1] == 'the') or (rend[1] == 'a') or (rend[1] == 'an') or (rend[1] == 'some')):
            drop_item = cleanstr(' '.join(rend[2:len(rend)]))
        else:
            drop_item = cleanstr(' '.join(rend[1:len(rend)]))
        if db.select('name', 'items', 'name', drop_item) != None:
            return (True, item.drop(drop_item, inventory, id, quantity=quantity))
    elif (rend[0] == 'give') and (len(rend) >= 3): # give(0) @benlundsten(1) the(2) dawn(3) porter()
        if (len(rend) >= 4) and ((rend[2] == 'the') or (rend[2] == 'a') or (rend[2] == 'an') or (rend[2] == 'some')):
            give_item = cleanstr(' '.join(rend[3:len(rend)]))
        else:
            give_item = cleanstr(' '.join(rend[2:len(rend)]))
        if db.select('name', 'items', 'name', give_item) != None:
            return (True, item.give(give_item, inventory, id, position, rend[1][1:].lower()))
    elif (rend[0] == 'inventory') or (' '.join(rend) == 'check inventory') or (' '.join(rend) == 'what am i holding'):
        if inventory == {}:
            return (True, 'Your inventory is empty at the moment.')
        else:
            return (True, invbuild(inventory))
    elif (' '.join(rend) == 'delete me from lilt') or (rend[0] == u'💀💀💀'):
        db.delete('users', 'id', id)
        return (True, 'You\'ve been removed from Lilt. Thanks for playing!')
    elif ((rend[0] == 'liltadd') or (rend[0] == 'la')) and ((id == '15332057') or (id == '724754312757272576') or (id == '15332062')):
        dbrend = str(' '.join(rend[1:len(rend)])).split('~')
        if len(dbrend) >= 2:
            if dbrend[0] == 'item':
                # liltadd item~n|paste~m|10
                traits = dict(trait.split('|') for trait in dbrend[1:len(dbrend)])
                for trait in traits:
                    if trait == 'n':
                        traits['name'] = traits['n']
                        del traits['n']
                    if trait == 'm':
                        traits['max'] = traits['m']
                        del traits['m']
                db.newitem(traits)
                return (True, traits['name'].capitalize() + ' was added to Lilt.')
            elif dbrend[0] == 'copy':
                if len(dbrend) == 3:
                    db.copymove(dbrend[1], dbrend[2], position)
                    return (True, '\'' + dbrend[2] + '\' was added to Lilt as a copy of \'' + dbrend[1] + '\'.')
            elif dbrend[0] == 'do':
                # la do~insert~moves~move|look at cat~response|It's sassy.~c|box^open~t|cat^sighted
                # la do~update~moves~c|cat^spotted~move|look at cat~response|It's sassy.~c|box^open~t|cat^sighted
                if dbrend[1] == 'select':
                    dbval = dbrend[3]
                    data = dict(key.split('|') for key in dbrend[4:len(dbrend)])
                elif dbrend[1] == 'update':
                    dbval = dict(key.split('|') for key in dbrend[3:4])
                    data = dict(key.split('|') for key in dbrend[4:len(dbrend)])
                    for key in dbval:
                        if len((dbval[key]).split('^')) >= 2:
                            dbval[key] = dict(k.split('^') for k in (dbval[key]).split('~'))
                else: # insert/delete
                    dbval = None
                    data = dict(key.split('|') for key in dbrend[3:len(dbrend)])
                for key in data: #shorthands
                    if key == 'n':
                        data['name'] = data['n']
                        del data['n']
                    if key == 'mx':
                        data['max'] = data['mx']
                        del data['mx']
                    if key == 'm':
                        data['move'] = data['m']
                        del data['m']
                    if key == 'p':
                        data['position'] = data['p']
                        del data['p']
                    if key == 'i':
                        data['item'] = data['i']
                        del data['i']
                    if key == 'd':
                        data['drop'] = data['d']
                        del data['d']
                    if key == 'c':
                        data['condition'] = data['c']
                        del data['c']
                    if key == 't':
                        data['trigger'] = data['t']
                        del data['t']
                    if key == 'tr':
                        data['travel'] = data['tr']
                        del data['tr']
                for key in data: # convert condition/trigger to dicts
                    if len((data[key]).split('^')) >= 2:
                        data[key] = dict(k.split('^') for k in (data[key]).split('~'))
                dbfetch = db.do(dbrend[1], dbrend[2], data, val=dbval)
                if dbrend[1] == 'insert':
                    if dbrend[2] == 'moves':
                        return (True, '\'' + str(data['move']) + '\' was added to ' + dbrend[2].capitalize() + '.')
                    elif dbrend[2] == 'items':
                        return (True, '\'' + str(data['name']) + '\' was added to ' + dbrend[2].capitalize() + '.')
                    else:
                        return (True, 'That was added to ' + dbrend[2].capitalize() + '.')
                elif dbrend[1] == 'select':
                    if len(dbfetch) < 1:
                        return (True, 'Nothing was selected from ' + str(dbval) + '.')
                    elif len(dbfetch) == 1:
                        return (True, '\'' + str(dbfetch[0][0]) + '\' was fetched from ' + str(dbval) + ' in ' + dbrend[2].capitalize() + '.')
                    elif len(dbfetch) == 2:
                        return (True, '\'' + str(dbfetch[0][0]) + '\' was fetched from ' + str(dbval) + ' in ' + dbrend[2].capitalize() + ', along with ' + str(len(dbfetch) - 1) + ' other.')
                    else:
                        return (True, '\'' + str(dbfetch[0][0]) + '\' was fetched from ' + str(dbval) + ' in ' + dbrend[2].capitalize() + ', along with ' + str(len(dbfetch) - 1) + ' others.')
                elif dbrend[1] == 'update':
                    return (True, dbrend[2].capitalize() + ' was updated with ' + str(dbval) + '.')
                elif dbrend[1] == 'delete':
                    return (True, '\'' + str(data) + '\' was deleted from ' + dbrend[2].capitalize() + '.')
            else: # newmove
                # la(rend[0]) eat meat cake(1)~It looks pretty nasty! But you eat it...(2)~c|meat cake^inventory(3)~d|meat cake(4)
                if len(dbrend) >= 3:
                    traits = dict(trait.split('|') for trait in dbrend[2:len(dbrend)]) # this right?
                    for trait in traits: # update shorthand keys
                        if trait == 'i':
                            traits['item'] = traits['i']
                            del traits['i']
                        if trait == 'd':
                            traits['drop'] = traits['d']
                            del traits['d']
                        if trait == 'c':
                            traits['condition'] = traits['c']
                            del traits['c']
                        if trait == 't':
                            traits['trigger'] = traits['t']
                            del traits['t']
                        if trait == 'tr':
                            traits['travel'] = traits['tr']
                            del traits['tr']
                    for trait in traits: # convert condition/trigger to dicts
                        if len((traits[trait]).split('^')) >= 2:
                            traits[trait] = dict(t.split('^') for t in (traits[trait]).split('~'))
                else:
                    traits = None
                db.newmove(dbrend[0], dbrend[1], position, traits)
                return (True, '\'' + dbrend[0] + '\' was added to Lilt.')
    return (False, '')
Пример #5
0
        try:
            user = {}
            user['screen_name'] = mention['screen_name'].lower()
            user['id'] = str(mention['user_id'])
            user['text'] = mention['text']
            user['tweet_id'] = str(mention['tweet_id'])

            reply = True if debug == True else False
            cmdreply = False # these may be unnecessary
            cmd = ''

            # gets tweet user['text'] sans @familiarlilt - removes @lilt_bird (or other @xxxxx) if included in tweet
            tweet = '' if len((user['text']).split()) == 1 else (user['text']).split(' ',1)[1]
            if (tweet).split(' ',1)[0][0] == '@':
                tweet = (tweet).split(' ',1)[1]
            move = cleanstr(tweet)

            # converts synonyms to common word
            if move.startswith(('inspect', 'examine', 'check', 'scan')):
                move = 'look at ' + move.split(' ', 1)[1]
            elif move.startswith(('check out')):
                move = 'look at ' + move.split(' ', 2)[2]
            elif move.startswith(('grab', 'get')):
                move = 'take ' + move.split(' ', 1)[1]
            elif move.startswith(('pick up')):
                move = 'take ' + move.split(' ', 2)[2]
            elif move.startswith(('shut')):
                move = 'close ' + move.split(' ', 1)[1]

            move = move.replace('liltbluebird', 'bird')
            move = move.replace('blue bird', 'bird')