Add buttons for Wikipedia and Songfacts
This commit is contained in:
parent
74eac83c82
commit
cc9b168e81
@ -362,6 +362,12 @@ class Tracks(Base):
|
||||
|
||||
return [a[0] for a in session.query(Tracks.path).all()]
|
||||
|
||||
@classmethod
|
||||
def get_all_tracks(cls):
|
||||
"Return a list of all tracks"
|
||||
|
||||
return session.query(cls).all()
|
||||
|
||||
@staticmethod
|
||||
def get_path(id):
|
||||
try:
|
||||
|
||||
@ -1,11 +1,14 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import webbrowser
|
||||
import os
|
||||
import sys
|
||||
import urllib.parse
|
||||
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
from log import DEBUG, EXCEPTION
|
||||
from slugify import slugify
|
||||
|
||||
from PyQt5.QtCore import Qt, QTimer
|
||||
from PyQt5.QtWidgets import (
|
||||
@ -129,10 +132,10 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
self.btnDatabase.clicked.connect(self.search_database)
|
||||
self.btnFade.clicked.connect(self.fade)
|
||||
self.btnPlay.clicked.connect(self.play_next)
|
||||
self.btnPrevious.clicked.connect(self.play_previous)
|
||||
self.btnSetNext.clicked.connect(self.set_next_track)
|
||||
self.btnSkipNext.clicked.connect(self.play_next)
|
||||
self.btnSongfacts.clicked.connect(self.songfacts_search)
|
||||
self.btnStop.clicked.connect(self.stop)
|
||||
self.btnWikipedia.clicked.connect(self.wikipedia_search)
|
||||
self.spnVolume.valueChanged.connect(self.change_volume)
|
||||
self.tabPlaylist.currentChanged.connect(self.tab_change)
|
||||
|
||||
@ -301,6 +304,15 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
|
||||
QMessageBox.warning(None, title, msg, buttons=QMessageBox.Cancel)
|
||||
|
||||
def songfacts_search(self):
|
||||
"Open a browser window in Songfacts searching for selected title"
|
||||
|
||||
title = self.current_playlist().get_selected_title()
|
||||
if title:
|
||||
slug = slugify(title, replacements=([["'", ""]]))
|
||||
url = f"https://www.songfacts.com/search/songs/{slug}"
|
||||
webbrowser.open(url, new=2)
|
||||
|
||||
def stop(self):
|
||||
"Stop playing immediately"
|
||||
|
||||
@ -432,6 +444,15 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
except AttributeError:
|
||||
self.hdrNextTrack.setText("")
|
||||
|
||||
def wikipedia_search(self):
|
||||
"Open a browser window in Wikipedia searching for selected title"
|
||||
|
||||
title = self.current_playlist().get_selected_title()
|
||||
if title:
|
||||
str = urllib.parse.quote_plus(title)
|
||||
url = f"https://www.wikipedia.org/w/index.php?search={str}"
|
||||
webbrowser.open(url, new=2)
|
||||
|
||||
|
||||
class DbDialog(QDialog):
|
||||
def __init__(self, parent=None):
|
||||
|
||||
@ -263,6 +263,15 @@ class Playlist(QTableWidget):
|
||||
next_row = self._meta_get_next()
|
||||
return self._get_row_id(next_row)
|
||||
|
||||
def get_selected_title(self):
|
||||
"Return title of selected row or None"
|
||||
|
||||
if self.selectionModel().hasSelection():
|
||||
row = self.currentRow()
|
||||
return self.item(row, self.COL_TITLE).text()
|
||||
else:
|
||||
return None
|
||||
|
||||
def load_playlist(self, plid):
|
||||
"""
|
||||
Load tracks and notes from playlist id.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user