<commit_before>import os
import Tkinter as tk
import ttk
import pafy
import re
import threading
import logging
import platform
import ConfigParser
from settings import YtSettings
from tkFileDialog import askdirectory
from converter import Converter
import tkMessageBox

logging.basicConfig(level=logging.DEBUG,
                    filename='y2m.log',
                    format='%(asctime)s %(levelname)-8s %(message)s',
                    datefmt='%a, %d %b %Y %H:%M:%S',
                    filemode='w')
logging.getLogger(__name__)

Settings = ConfigParser.ConfigParser()
Parse = ConfigParser.SafeConfigParser()

N = tk.N
S = tk.S
E = tk.E
W = tk.W
END = tk.END

new = YtSettings()

# Linux - local destination for ffmpeg
#if platform.system() == 'Linux':
#    print('l')
#    AudioSegment.converter = \
#        "/home/dev/Apps/ffmpeg-git-20150826-64bit-static/ffmpeg"
#    fc = Converter()
if platform.system() == 'Darwin':
    fc = Converter(ffmpeg_path='/usr/local/bin/ffmpeg',
                   ffprobe_path='/usr/local/bin/ffprobe')
else:
    fc = Converter()

fc_options = {
    'format': 'mp3',
    'audio': {
        'codec': 'mp3',
        'bitrate': '44100',
        'channels': 2
    }
}


class Setting(tk.Frame):
    """Settings window"""

    def __init__(self, parent):
        tk.Frame.__init__(self, parent)
        self.parent = parent
        self.dl_loc = None
        try:
            Parse.readfp(open('./config.ini'))
            self.dl_loc = Parse.get('download', 'directory')
        except IOError:
            logging.error('Unable to locate config file', exc_info=True)
            tkMessageBox.showwarning('Warning', 'no directory saved')
        except Exception as e:
            print(e)

        self.download_dir = self.dl_loc
        self.download_loc_display = tk.StringVar()
        self.default_result_amt = tk.StringVar()
        self.default_result_amt.set('25')
        self.download_loc_display.set(self.download_dir)

        self.settings_win = tk.Toplevel(self.parent, width=120,
                                        height=50,
                                        bg='gray93',
                                        padx=10, pady=10)

        self.main_settings_fr = tk.Frame(self.settings_win,
                                      bg='gray93', padx=10,
                                      pady=20)
        self.settings_win_btns = tk.Frame(self.settings_win, bg='gray93')
        self.main_settings_fr.grid(row=0)
        self.settings_win_btns.grid(row=1, sticky=S + E)

        self.location_label = ttk.Label(self.main_settings_fr, text='Current '
                                                                 'download '
                                                                 'location: ')
        self.location_display = tk.Label(self.main_settings_fr, width=60,
                                         textvariable=self.download_loc_display)
        self.location_change = ttk.Button(self.main_settings_fr, text='Change',
                                          command=self.set_directory)

        self.max_result_lbl = ttk.Label(self.main_settings_fr, text='Number of '
                                                                 'results (Max '
                                                                 '50): ')
        self.max_number = tk.Spinbox(self.main_settings_fr, from_=1, to=50,
                                     textvariable=self.default_result_amt,
                                     width=10)
        self.save_settings = ttk.Button(self.settings_win_btns, text='Apply',
                                        command=self.set_search_max)
        self.cancel_settings = ttk.Button(self.settings_win_btns, text='Cancel',
                                          command=self.settings_win.destroy)
        self.close_settings = ttk.Button(self.settings_win_btns, text='OK',
                                         command=self.settings_win.destroy)

        self.location_label.grid(row=0, column=0, padx=2)
        self.location_display.grid(row=0, column=1, padx=2)
        self.location_change.grid(row=0, column=2, padx=2)
        self.max_result_lbl.grid(row=1, column=0)
        self.max_number.grid(row=1, column=1)
        self.cancel_settings.grid(row=0, column=0, sticky=E, padx=2)
        self.save_settings.grid(row=0, column=1, sticky=E, padx=2)
        self.close_settings.grid(row=0, column=2, sticky=E, padx=2)

    def set_directory(self):
        """
        User selects directory they wish to download to.
        This function will set the download location to the chosen
        destination and write the location into a settings file.
        """
        user_dir = askdirectory()
        try:
            self.download_dir = user_dir + '/YT2Mp3/'
            os.mkdir(self.download_dir)
            self.download_loc_display.set(self.download_dir)

        # ConfigParser
            dldir_conf = open('./config.ini', 'w')
            Settings.add_section('download')
            Settings.set('download', 'directory', self.download_dir)
            Settings.write(dldir_conf)
            dldir_conf.close()

            tkMessageBox.showinfo('Download directory saved', 'Please restart the '
                                                 'application for the '
                                                 'directory settings to take '
                                                          'effect.')<commit_msg>add settings widgets for ffmpeg<commit_after>import os
import Tkinter as tk
import ttk
import pafy
import re
import threading
import logging
import platform
import ConfigParser
from settings import YtSettings
from tkFileDialog import askdirectory
from converter import Converter
import tkMessageBox

logging.basicConfig(level=logging.DEBUG,
                    filename='y2m.log',
                    format='%(asctime)s %(levelname)-8s %(message)s',
                    datefmt='%a, %d %b %Y %H:%M:%S',
                    filemode='w')
logging.getLogger(__name__)

Settings = ConfigParser.ConfigParser()
Parse = ConfigParser.SafeConfigParser()

N = tk.N
S = tk.S
E = tk.E
W = tk.W
END = tk.END

new = YtSettings()

if platform.system() == 'Darwin':
    fc = Converter(ffmpeg_path='/usr/local/bin/ffmpeg',
                   ffprobe_path='/usr/local/bin/ffprobe')
else:
    fc = Converter()

fc_options = {
    'format': 'mp3',
    'audio': {
        'codec': 'mp3',
        'bitrate': '44100',
        'channels': 2
    }
}


class Setting(tk.Frame):
    """Settings window"""

    def __init__(self, parent):
        tk.Frame.__init__(self, parent)
        self.parent = parent
        self.dl_loc = None
        try:
            Parse.readfp(open('./config.ini'))
            self.dl_loc = Parse.get('download', 'directory')
        except IOError:
            logging.error('Unable to locate config file', exc_info=True)
            tkMessageBox.showwarning('Warning', 'no directory saved')
        except Exception as e:
            print(e)

        self.download_dir = self.dl_loc
        self.ffmpeg_path = tk.StringVar()
        self.ffprobe_path = tk.StringVar()
        self.download_loc_display = tk.StringVar()
        self.default_result_amt = tk.StringVar()
        self.default_result_amt.set('25')
        self.download_loc_display.set(self.download_dir)

        self.settings_win = tk.Toplevel(self.parent, width=120,
                                        height=50,
                                        bg='gray93',
                                        padx=10, pady=10)

        self.main_settings_fr = tk.Frame(self.settings_win,
                                      bg='gray93', padx=10,
                                      pady=20)
        self.settings_win_btns = tk.Frame(self.settings_win, bg='gray93')
        self.main_settings_fr.grid(row=0)
        self.settings_win_btns.grid(row=1, sticky=S + E)

        self.location_label = ttk.Label(self.main_settings_fr, text='Current '
                                                                 'download '
                                                                 'location: ')
        self.location_display = tk.Label(self.main_settings_fr, width=60,
                                         textvariable=self.download_loc_display)
        self.location_change = ttk.Button(self.main_settings_fr, text='Change',
                                          command=self.set_directory)
        self.ffmpeg_path_lbl = ttk.Label(self.main_settings_fr, text='FFMpeg '
                                                                'location: ')
        self.ffmpeg_path_entry = ttk.Entry(self.main_settings_fr,
                                           textvariable=self.ffmpeg_path,
                                           width=30)
        self.ffprobe_path_lbl = ttk.Label(self.main_settings_fr,
                                          text='FFprobe '
                                                                 'location: ')
        self.ffprobe_path_entry = ttk.Entry(self.main_settings_fr,
                                            textvariable=self.ffprobe_path,
                                            width=30)
        self.max_result_lbl = ttk.Label(self.main_settings_fr, text='Number of '
                                                                 'results (Max '
                                                                 '50): ')
        self.max_number = tk.Spinbox(self.main_settings_fr, from_=1, to=50,
                                     textvariable=self.default_result_amt,
                                     width=10)
        self.save_settings = ttk.Button(self.settings_win_btns, text='Apply',
                                        command=self.set_search_max)
        self.cancel_settings = ttk.Button(self.settings_win_btns, text='Cancel',
                                          command=self.settings_win.destroy)
        self.close_settings = ttk.Button(self.settings_win_btns, text='OK',
                                         command=self.settings_win.destroy)

        self.location_label.grid(row=0, column=0, padx=2)
        self.location_display.grid(row=0, column=1, padx=2)
        self.location_change.grid(row=0, column=2, padx=2)
        self.max_result_lbl.grid(row=1, column=0)
        self.max_number.grid(row=1, column=1)
        self.ffmpeg_path_lbl.grid(row=2, column=0)
        self.ffmpeg_path_entry.grid(row=2, column=1)
        self.ffprobe_path_lbl.grid(row=3, column=0)
        self.ffprobe_path_entry.grid(row=3, column=1)
        self.cancel_settings.grid(row=0, column=0, sticky=E, padx=2)
        self.save_settings.grid(row=0, column=1, sticky=E, padx=2)
        self.close_settings.grid(row=0, column=2, sticky=E, padx=2)

    def set_directory(self):
        """
        User selects directory they wish to download to.
        This function will set the download location to the chosen
        destination and write the location into a settings file.
        """
        user_dir = askdirectory()
        try:
            self.download_dir = user_dir + '/YT2Mp3/'
            os.mkdir(self.download_dir)
            self.download_loc_display.set(self.download_dir)

        # ConfigParser
            dldir_conf = open('./config.ini', 'w')
            Settings.add_section('download')
            Settings.set('download', 'directory', self.download_dir)
            Settings.write(dldir_conf)
            dldir_conf.close()

            tkMessageBox.showinfo('Download directory saved', 'Please restart the '
                                                 'application for the '
                                                 'directory settings to take '
                                                          'effect.')
{'fraction_non_alphanumeric': 0.1011541072640869, 'fraction_numerical': 0.01306856754921928, 'mean_word_length': 1.5986769570011026, 'pattern_counts': {'":': 0, '<': 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': 112, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3040169', 'n_tokens_mistral': 3309, 'n_tokens_neox': 3200, 'n_words': 578}