<commit_before>#! /usr/bin/env python

import ConfigParser
import argparse
from datetime import datetime

from jamendoapi import jamendo

import random


def parseArgs():
    parser = argparse.ArgumentParser(description='Stretch track for Tumblr')
    parser.add_argument('config', help='The config file')
    args = parser.parse_args()

    config = ConfigParser.SafeConfigParser()
    config.read(args.config)

    return (args, config)


def main():

    print('###################')
    print('#      Dronr      #')
    print('###################')
    print('\n')
    print(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
    args, config = parseArgs()
    #consumerKey = config.get('consumer', 'key')
    #consumerSecret = config.get('consumer', 'secret')
    #oauthToken = config.get('oauth', 'key')
    #oauthSecret = config.get('oauth', 'secret')

    jamendo_client_id = config.get('jamendo', 'clientid')

    track_ordering = config.get('jamendo', 'track_ordering')
    audio_format = config.get('audio', 'format')

    j = jamendo(jamendo_client_id)

    top100_args = {
        "limit": 100,
        "order": track_ordering,
        "ccsa": 1
    }
    top100 = j.get("tracks", top100_args)

    track = random.choice(top100)

    print(track)

    download_track(j, track["id"], track["name"], audio_format)


def download_track(jamendo, track_id, track_name, file_format):

    print("Downloading %s" % track_name)
    dl_request_args = {
        "audioformat": file_format
    }

    filename = track_name.lower().replace(' ', '_') + "." + file_format

    with open(filename, "w") as fp:
        raw_response = jamendo.download_track(track_id, dl_request_args)
        fp.write(raw_response.read())


if __name__ == "__main__":
    main()<commit_msg>Using audio processor class to do the audio processing<commit_after>#! /usr/bin/env python

import ConfigParser
import argparse
from datetime import datetime

from jamendoapi import jamendo

from audioprocessor import AudioProcessor

import random


def parseArgs():
    parser = argparse.ArgumentParser(description='Stretch track for Tumblr')
    parser.add_argument('config', help='The config file')
    args = parser.parse_args()

    config = ConfigParser.SafeConfigParser()
    config.read(args.config)

    return (args, config)


def main():

    print('###################')
    print('#      Dronr      #')
    print('###################')
    print('\n')
    print(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
    args, config = parseArgs()
    #consumerKey = config.get('consumer', 'key')
    #consumerSecret = config.get('consumer', 'secret')
    #oauthToken = config.get('oauth', 'key')
    #oauthSecret = config.get('oauth', 'secret')

    jamendo_client_id = config.get('jamendo', 'clientid')

    audio = AudioProcessor()

    track_ordering = config.get('jamendo', 'track_ordering')
    audio_format = config.get('audio', 'format')

    j = jamendo(jamendo_client_id)

    top100_args = {
        "limit": 100,
        "order": track_ordering,
        "ccsa": 1
    }
    top100 = j.get("tracks", top100_args)

    track = random.choice(top100)

    print(track)

    track_name = track["name"].lower().replace(' ', '_')
    track_file = track_name + "." + audio_format

    wave_name = track_name + ".wav"
    stretched_wave = track_name + "-stretched.wav"
    final_file = track_name + "-stretched.mp3"

    download_track(j, track["id"], track_file, audio_format)

    audio.decode(track_file, wave_name)
    audio.stretch(wave_name, stretched_wave)
    audio.encode(stretched_wave, final_file)


def download_track(jamendo, track_id, track_name, file_format):

    print("Downloading %s" % track_name)
    dl_request_args = {
        "audioformat": file_format
    }

    with open(track_name, "w") as fp:
        raw_response = jamendo.download_track(track_id, dl_request_args)
        fp.write(raw_response.read())


if __name__ == "__main__":
    main()
{'fraction_non_alphanumeric': 0.15800152168399695, 'fraction_numerical': 0.008369261983261477, 'mean_word_length': 3.64, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2379473', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1240, 'n_words': 260}