# -*- coding: utf-8 -*-
from PyQt4 import QtGui
from PyQt4.QtCore import *
import sys
import os
class VideosToMp3(QtGui.QWidget):
def __init__(self, parent = None):
super(VideosToMp3, self).__init__(parent)
''' Labels and GUI '''
extension = QtGui.QWidget()
download_label = QtGui.QLabel("Enter YouTube video URL:")
self.download_line_edit = QtGui.QLineEdit()
file_label = QtGui.QLabel("Enter file name (optional):")
self.file_line_edit = QtGui.QLineEdit()
mp3_filename_label = QtGui.QLabel("MP3 file name:")
self.filename_line_edit = QtGui.QLineEdit()
download_button = QtGui.QPushButton("Download in URL")
download_file_button = QtGui.QPushButton("Download in file")
cancel_button = QtGui.QPushButton("Cancel")
spacer = QtGui.QSpacerItem(10, 20, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
gridLayout = QtGui.QGridLayout()
gridLayout.addWidget(download_label, 0, 0)
gridLayout.addWidget(self.download_line_edit, 0, 1)
gridLayout.addWidget(mp3_filename_label, 1, 0)
gridLayout.addWidget(self.filename_line_edit, 1, 1)
gridLayout.addWidget(file_label, 2, 0)
gridLayout.addWidget(self.file_line_edit, 2, 1)
gridLayout.addWidget(download_button, 3, 0)
gridLayout.addWidget(cancel_button, 3, 1)
gridLayout.addWidget(download_file_button, 4, 0)
gridLayout.addItem(spacer)
mainLayout = QtGui.QVBoxLayout()
mainLayout.setSizeConstraint(QtGui.QLayout.SetFixedSize)
mainLayout.addLayout(gridLayout)
self.setLayout(mainLayout)
''' Connect '''
#self.connect(download_button, SIGNAL('clicked()'), self.download_video)
self.connect(cancel_button, SIGNAL('clicked()'), self.close)
self.connect(download_file_button, SIGNAL('clicked()'), self.download_videos)
class Download_in_url():
def __init__(self):
def download_video_in_url(url):
os.system('python youtube-dl' + url)
class Download_in_file():
def __init__(self):
print "Creating folder 'music'"
os.system('mkdir -p music')
download_videos()
def check_file_format(file_name):
if file_name.endswith('.flv'):
return str(file_name)
else:
return str(file_name + '.flv')
def download_videos():
list_videos = []
list_music = []
try:
input_file = open('videos.txt')
for line in input_file:
(name, address) = line.split('||')
name = name.replace(' ', '_')
if name.startswith('[olemas]') or os.path.exists(str(os.getcwd()) + '/music/' + name.rstrip('.flv') + '.mp3'):
print name, "is exists! Ignoring!"
else:
check_name = check_file_format(name)
download = 'python youtube-dl -o ' + check_name + ' ' + address
convert = 'ffmpeg -i ' + check_name + ' -y -f mp3 -vn -acodec copy ' + check_name.rstrip('.flv') + '.mp3'
list_videos.append(download)
list_music.append(convert)
except IOError:
pass
print "Downloading all videos"
for download_videos in list_videos:
os.system(download_videos)
print "Creating all mp3's"
for create_music in list_music:
os.system(create_music)
print "Moving music to directory 'music'"
os.system('mv *.mp3 ' + os.getcwd() + '/music')
print "Removing unused videos"
os.system('rm *.flv')
def main():
aplication = QtGui.QApplication(sys.argv)
window = VideosToMp3()
window.setWindowTitle("YouTube To MP3 Downloader")
window.show()
program = aplication.exec_()
sys.exit(program)
if __name__ == "__main__":
main()
Moving music to directory 'music'
mv: stat `*.mp3' ei õnnestu: No such file or directory
Removing unused videos
rm: `*.flv' ei saa kustutada: No such file or directory
Traceback (most recent call last):
File "DownloadYouTubeVideos.py", line 105, in <module>
main()
File "DownloadYouTubeVideos.py", line 97, in main
window = VideosToMp3()
File "DownloadYouTubeVideos.py", line 43, in __init__
self.connect(download_file_button, SIGNAL('clicked()'), self.download_videos)
AttributeError: 'VideosToMp3' object has no attribute 'download_videos'
How to use the classes and Qt threads, because the user interface is not running properly at the time of when download videos and converts them to mp3.