-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
7,426 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,99 @@ | ||
import sys | ||
import os | ||
import unicodedata | ||
from PyQt5.QtWidgets import QMainWindow, QApplication, QPushButton, QFileDialog, QLineEdit | ||
|
||
class App(QMainWindow): | ||
|
||
def __init__(self): | ||
super().__init__() | ||
self.title = 'M3U Generator' | ||
self.left = 10 | ||
self.top = 10 | ||
self.width = 400 | ||
self.height = 140 | ||
self.initUI() | ||
|
||
def initUI(self): | ||
self.setWindowTitle(self.title) | ||
self.setGeometry(self.left, self.top, self.width, self.height) | ||
|
||
self.textbox = QLineEdit(self) | ||
self.textbox.move(20, 20) | ||
self.textbox.resize(280, 40) | ||
self.textbox.setReadOnly(True) | ||
|
||
self.selectbutton = QPushButton("Select", self) | ||
self.selectbutton.clicked.connect(self.getDir) | ||
self.selectbutton.move(20, 80) | ||
|
||
self.gobutton = QPushButton("Go", self) | ||
self.gobutton.clicked.connect(self.genM3U) | ||
self.gobutton.move(120, 80) | ||
|
||
self.show() | ||
|
||
def getDir(self): | ||
dlg = QFileDialog() | ||
dlg.setFileMode(QFileDialog.Directory) | ||
|
||
if dlg.exec_(): | ||
files = dlg.selectedFiles() | ||
if len(files) < 1: | ||
return | ||
self.textbox.setText(dlg.selectedFiles()[0]) | ||
|
||
def genM3U(self): | ||
selectDir = self.textbox.text() | ||
if not os.path.isdir(selectDir): | ||
import remi.gui as gui | ||
from remi import start, App | ||
|
||
class M3uGenerator(App): | ||
def __init__(self, *args): | ||
super(M3uGenerator, self).__init__(*args) | ||
|
||
def on_select_btn_pressed(self, widget): | ||
self.folder_selection_dialog = gui.FileSelectionDialog('Folder Selection Dialog', | ||
'Select folder to generate m3u', False, | ||
'.', False) | ||
self.folder_selection_dialog.confirm_value.do( | ||
self.on_fileselection_dialog_confirm) | ||
|
||
# here is returned the Input Dialog widget, and it will be shown | ||
self.folder_selection_dialog.show(self) | ||
|
||
def on_fileselection_dialog_confirm(self, widget, filelist): | ||
if len(filelist) == 0: | ||
self.lbl.set_text('Please choose a folder') | ||
else: | ||
self.lbl.set_text(filelist[0]) | ||
|
||
def on_go_btn_pressed(self, widget): | ||
doing_dialog = gui.GenericDialog("", "Doing", width=500, height=100) | ||
doing_dialog.show(self) | ||
m3u_path = self.gen_m3u() | ||
doing_dialog.hide() | ||
done_dialog = gui.GenericDialog("", "m3u created at [{}]".format(m3u_path), width=500, height=100) | ||
done_dialog.show(self) | ||
|
||
def gen_m3u(self): | ||
select_dir = self.lbl.get_text() | ||
if not os.path.isdir(select_dir): | ||
return | ||
|
||
def isMusic(path): | ||
supportExtension = ['.mp3', '.m3u', '.wma', '.flac', '.wav', '.mc', '.aac', '.m4a', '.ape', '.dsf', '.dff'] | ||
filename, fileExtension = os.path.splitext(path) | ||
if fileExtension.lower() in supportExtension: | ||
def is_music(path): | ||
support_extension = ['.mp3', '.m3u', '.wma', '.flac', | ||
'.wav', '.mc', '.aac', '.m4a', | ||
'.ape', '.dsf', '.dff'] | ||
filename, extension = os.path.splitext(path) | ||
if extension.lower() in support_extension: | ||
return True | ||
return False | ||
|
||
def createPlayList(selectDir): | ||
m3uList = [] | ||
for root, subdirs, files in os.walk(selectDir): | ||
def create_playList(select_dir): | ||
m3u_list = [] | ||
for root, subdirs, files in os.walk(select_dir): | ||
for filename in files: | ||
relDir = os.path.relpath(root, selectDir) | ||
if relDir == ".": | ||
rel_dir = os.path.relpath(root, select_dir) | ||
if rel_dir == ".": | ||
path = filename | ||
else: | ||
path = os.path.join(relDir, filename) | ||
if isMusic(path): | ||
m3uList.append(path) | ||
return m3uList | ||
path = os.path.join(rel_dir, filename) | ||
if is_music(path): | ||
m3u_list.append(path) | ||
return m3u_list | ||
|
||
m3uPath = os.path.join(selectDir, os.path.basename(selectDir) + ".m3u8") | ||
m3u_path = os.path.join(select_dir, os.path.basename(select_dir) + ".m3u8") | ||
|
||
if os.path.exists(m3uPath): | ||
os.remove(m3uPath) | ||
if os.path.exists(m3u_path): | ||
os.remove(m3u_path) | ||
|
||
m3uList = createPlayList(selectDir) | ||
m3u_list = create_playList(select_dir) | ||
|
||
f = open(m3uPath, 'w', encoding='utf-8') | ||
for music in m3uList: | ||
f = open(m3u_path, 'w', encoding='utf-8') | ||
for music in m3u_list: | ||
f.write(unicodedata.normalize('NFC', music) + '\n') | ||
f.close() | ||
print("finish") | ||
|
||
return m3u_path | ||
|
||
def main(self): | ||
body = gui.VBox(width='100%', height='100%') | ||
main_container = gui.VBox(width=400, height=140, | ||
style={'align': 'center', 'border': '5px #FFAC55 solid'}) | ||
btn_container = gui.HBox(width=300, height=30) | ||
|
||
self.lbl = gui.Label('Please choose a folder') | ||
self.select_bt = gui.Button('Select folder', width=100, height=30) | ||
self.go_bt = gui.Button('Go', width=100, height=30) | ||
|
||
self.select_bt.onclick.do(self.on_select_btn_pressed) | ||
self.go_bt.onclick.do(self.on_go_btn_pressed) | ||
|
||
btn_container.append(self.select_bt) | ||
btn_container.append(self.go_bt) | ||
|
||
main_container.append(self.lbl) | ||
main_container.append(btn_container) | ||
body.append(main_container) | ||
|
||
return body | ||
|
||
if __name__ == '__main__': | ||
app = QApplication(sys.argv) | ||
ex = App() | ||
sys.exit(app.exec_()) | ||
start(M3uGenerator) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from .gui import Widget, Button, TextInput, \ | ||
SpinBox, Label, GenericDialog, InputDialog, ListView, ListItem, DropDown, DropDownItem, \ | ||
Image, Table, TableRow, TableItem, TableTitle, Input, Slider, ColorPicker, Date, GenericObject, \ | ||
FileFolderNavigator, FileFolderItem, FileSelectionDialog, Menu, MenuItem, FileUploader, FileDownloader, VideoPlayer | ||
|
||
from .server import App, Server, start |
Oops, something went wrong.