#!/usr/bin/env python # -*- coding: utf-8 -*- from urllib import urlretrieve import pygtk pygtk.require('2.0') import gtk import threading def threaded(f): def wrapper(*args): t = threading.Thread(target=f, args=args) t.start() return wrapper class Wrzuter: def delete_event(self, widget, event, data=None): gtk.main_quit() return False def getinput(self, widget): def download(fakepath, filename): gtk.gdk.threads_enter() self.StatusBar.push(self.StatusBar.get_context_id("Splitting"), "Wydobywanie ścieżki do pliku...") gtk.gdk.threads_leave() truepath = fakepath.split("/audio/")[0] + "/sr/f/" + fakepath.split("/audio/")[1] gtk.gdk.threads_enter() self.StatusBar.push(self.StatusBar.get_context_id("Downloading"), "Pobieranie pliku %s... Proszę czekać. Program może nie reagować." %filename) gtk.gdk.threads_leave() urlretrieve(truepath, filename) fakepath = self.FakePathInput.get_text() filename = self.FilenameInput.get_text() fakepath_table = fakepath.split(";") filename_table = filename.split(";") for i in range(len(fakepath_table)): filename_table[i] = filename_table[i] + ".mp3" download(fakepath_table[i], filename_table[i]) gtk.gdk.threads_enter() self.StatusBar.push(self.StatusBar.get_context_id("Downloaded"), "Plik %s został pobrany." %filename_table[i]) gtk.gdk.threads_leave() def __init__(self): gtk.gdk.threads_init() #budujemy okienko self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.set_title("wrzuter 0.4.1") self.window.connect("delete_event", self.delete_event) self.window.set_border_width(15) #budujemy głównego boxa self.MainBox = gtk.VBox(False, 5) self.window.add(self.MainBox) self.MainBox.show() #budujemy tytuł self.Title = gtk.Label("Wrzuter, skrypt pobierający pliki audio z wrzuta.pl") self.MainBox.pack_start(self.Title, True, True, 0) self.Title.show() #dalsze info self.Info = gtk.Label("Można pobierać więcej plików naraz - adresy i nazwy oddzielić średnikiem.") self.MainBox.pack_start(self.Info, True, True, 0) self.Info.show() #box na adres na wrzucie self.AddressBox = gtk.HBox(True, 3) self.MainBox.pack_start(self.AddressBox, True, True, 0) self.AddressBox.show() #tekst odnośnie wpisywania self.GiveAddressLabel = gtk.Label("Podaj adres pliku na wrzuta.pl") self.AddressBox.pack_start(self.GiveAddressLabel, True, True, 0) self.GiveAddressLabel.show() #input na adres self.FakePathInput = gtk.Entry() self.AddressBox.pack_start(self.FakePathInput, True, True, 0) self.FakePathInput.show() #box na nazwę pliku self.FilenameBox = gtk.HBox(True, 3) self.MainBox.pack_start(self.FilenameBox, True, True, 0) self.FilenameBox.show() #tekst odnośnie nazwy pliku self.FilenameLabel = gtk.Label("Podaj, jak ma nazywać się plik [bez .mp3 na końcu]") self.FilenameBox.pack_start(self.FilenameLabel, True, True, 0) self.FilenameLabel.show() #input na nazwę pliku self.FilenameInput = gtk.Entry() self.FilenameBox.pack_start(self.FilenameInput, True, True, 0) self.FilenameInput.show() #button do pobierania self.DownloadButton = gtk.Button("Pobierz", None, False) self.MainBox.pack_start(self.DownloadButton, True, True, 0) self.DownloadButton.show() #statusbar self.StatusBar = gtk.Statusbar() self.MainBox.pack_start(self.StatusBar, True, True, 0) self.StatusBar.show() #podłączamy buttona do funkcji pobierania self.DownloadButton.connect("clicked", threaded(self.getinput)) #pokazujemy wszystko self.window.show() def main(): gtk.main() if __name__ == "__main__": wrzuter = Wrzuter() main()