Add script for searching for a song on youtube.
This commit is contained in:
parent
d6e6a72250
commit
3df5906250
Binary file not shown.
After Width: | Height: | Size: 71 KiB |
|
@ -0,0 +1,9 @@
|
|||
[Script]
|
||||
name=YouTube
|
||||
description=Finds songs on YouTube
|
||||
author=John Maguire <john.maguire@gmail.com>
|
||||
url=http://www.clementine-player.org
|
||||
icon=YouTube.png
|
||||
|
||||
language=python
|
||||
script_file=youtube.py
|
|
@ -0,0 +1,41 @@
|
|||
import clementine
|
||||
|
||||
from PythonQt.Qt import QUrl
|
||||
from PythonQt.QtGui import QAction
|
||||
from PythonQt.QtGui import QDesktopServices
|
||||
from PythonQt.QtNetwork import QNetworkRequest
|
||||
|
||||
import json
|
||||
|
||||
class Plugin:
|
||||
def __init__(self):
|
||||
self.action = QAction("Find on YouTube", None)
|
||||
self.action.connect("activated()", self.SearchYoutube)
|
||||
clementine.ui.AddAction("song_menu", self.action)
|
||||
self.network = clementine.NetworkAccessManager()
|
||||
|
||||
def SearchYoutube(self):
|
||||
selection = clementine.playlists.current_selection().indexes()
|
||||
title = selection[clementine.Playlist.Column_Title].data()
|
||||
artist = selection[clementine.Playlist.Column_Artist].data()
|
||||
query = title + ' ' + artist
|
||||
url = QUrl('https://gdata.youtube.com/feeds/api/videos')
|
||||
url.addQueryItem('q', query)
|
||||
url.addQueryItem('alt', 'json')
|
||||
url.addQueryItem('max-results', 1)
|
||||
reply = self.network.get(QNetworkRequest(url))
|
||||
|
||||
def SearchFinished():
|
||||
data = json.loads(str(reply.readAll()))
|
||||
feed = data['feed']
|
||||
try:
|
||||
print feed['entry'][0]['media$group']['media$player'][0]['url']
|
||||
youtube_url = feed['entry'][0]['media$group']['media$player'][0]['url']
|
||||
QDesktopServices.openUrl(QUrl.fromEncoded(str(youtube_url)))
|
||||
except Exception, e:
|
||||
print e
|
||||
|
||||
reply.connect("finished()", SearchFinished)
|
||||
|
||||
|
||||
plugin = Plugin()
|
|
@ -42,8 +42,12 @@
|
|||
#include "ui/settingsdialog.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QModelIndex>
|
||||
#include <QtDebug>
|
||||
|
||||
Q_DECLARE_METATYPE(QModelIndex)
|
||||
Q_DECLARE_METATYPE(QList<QModelIndex>)
|
||||
|
||||
const char* PythonEngine::kClementineModuleName = "clementine";
|
||||
const char* PythonEngine::kScriptModulePrefix = "clementinescripts";
|
||||
PythonEngine* PythonEngine::sInstance = NULL;
|
||||
|
@ -121,6 +125,7 @@ bool PythonEngine::EnsureInitialised() {
|
|||
RegisterListConverter<Directory>("QList<Directory>");
|
||||
RegisterListConverter<CoverSearchResult>("QList<CoverSearchResult>");
|
||||
RegisterListConverter<PlaylistItemPtr>("QList<PlaylistItemPtr>");
|
||||
RegisterListConverter<QModelIndex>("QList<QModelIndex>");
|
||||
|
||||
// Connect stdout, stderr
|
||||
connect(python_qt, SIGNAL(pythonStdOut(QString)), SLOT(PythonStdOut(QString)));
|
||||
|
|
|
@ -676,6 +676,8 @@ MainWindow::MainWindow(
|
|||
scripts_->ui()->RegisterActionLocation("help_menu", ui_->menu_help, NULL);
|
||||
scripts_->ui()->RegisterActionLocation("playlist_menu", ui_->menu_playlist, NULL);
|
||||
|
||||
scripts_->ui()->RegisterActionLocation("song_menu", playlist_menu_, NULL);
|
||||
|
||||
// Load theme
|
||||
StyleSheetLoader* css_loader = new StyleSheetLoader(this);
|
||||
css_loader->SetStyleSheet(this, ":mainwindow.css");
|
||||
|
|
Loading…
Reference in New Issue