Commit 5df28917 authored by Sven Krohlas's avatar Sven Krohlas
Browse files

Amazon store: we now have our own .amz downloader :)

* requires clamz, qt -> portable and also interesting for other projects
* patch includes MIME-types for .amz files and hooks in .desktop files
so that a user just needs to click on an .amz file to make the magic
happen
* still a very basic app, but it works

FIXED-IN:2.7
FEATURE:288803
parent 8d9f1659
......@@ -9,11 +9,13 @@ VERSION 2.7-Beta 1
* Amazon store: It is now possible to add items to your shopping cart using amarok:// URLs.
* Amazon store: Use the context info applet to show further infos about a selected item.
* New argument --debug-audio to enable Phonon debugging.
* Amazon store: We now ship a utility to handle downloads from Amazon.
CHANGES:
* Last.fm Skip button removed; Last.fm API no longer provides it. (BR 305576)
* Optional liblastfm dependency raised to 1.0.0. (BR 302597)
* Add composer button to wikipedia applet (BR 272982)
* New optional dependency for Amazon downloads: clamz.
BUGFIXES:
* Repeat playlist correctly with a single track playlist. (BR 290955)
......
add_subdirectory( amzdownloader )
add_subdirectory( collectionscanner )
if( TAGLIB_FOUND )
......
/****************************************************************************************
* Copyright (c) 2012 Sven Krohlas <sven@getamarok.com> *
* *
* This program is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License as published by the Free Software *
* Foundation; either version 2 of the License, or (at your option) any later *
* version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along with *
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#include "AmzDownloader.h"
#include <QDesktopServices>
#include <QFileDialog>
#include <QMessageBox>
AmzDownloader::AmzDownloader( QWidget* parent ) :
QDialog( parent ),
ui( new Ui::AmzDownloader )
{
m_downloadDir = QDesktopServices::storageLocation( QDesktopServices::MusicLocation );
// parse arguments
QStringList arguments = QApplication::arguments();
if( arguments.contains( "--amz" ) )
{
int position = arguments.indexOf( "--amz" );
while( ( position + 1 < arguments.size() ) )
{
if( !arguments.at( position + 1 ).startsWith( "--" ) )
m_amzList += arguments.at( position + 1 );
else
break;
position++;
}
}
checkAmzList();
if( arguments.contains( "--output-dir" ) )
{
int position = arguments.indexOf( "--output-dir" );
if( ( position + 1 <= arguments.size() ) && !arguments.at( position + 1 ).startsWith( "--" ) && m_downloadDir.exists( arguments.at( position + 1 ) ) )
m_downloadDir = arguments.at( position + 1 );
}
ui->setupUi( this );
ui->downloadDirectoryEdit->setText( m_downloadDir.absolutePath() );
if( !m_amzList.isEmpty() )
ui->amzFileEdit->setText( m_amzList.at( 0 ) );
connect( ui->quitButton, SIGNAL( clicked() ), this, SLOT( quitClicked() ) );
connect( ui->selectAmzButton, SIGNAL( clicked() ), this, SLOT( selectAmzClicked() ) );
connect( ui->selectDirectoryButton, SIGNAL( clicked() ), this, SLOT( selectDirectoryClicked() ) );
connect( ui->startButton, SIGNAL( clicked() ), this, SLOT( startClicked() ) );
}
AmzDownloader::~AmzDownloader()
{
delete ui;
}
// public slots
void
AmzDownloader::quitClicked()
{
QApplication::quit();
}
void
AmzDownloader::selectAmzClicked()
{
QFileDialog fileDialog( this );
fileDialog.setAcceptMode( QFileDialog::AcceptOpen );
fileDialog.setFileMode( QFileDialog::ExistingFile );
fileDialog.setNameFilter( tr( "Amazon MP3 Purchase Playlist (*.amz)" ) );
if( !m_amzList.isEmpty() )
fileDialog.setDirectory( m_amzList.at( 0 ) );
if( fileDialog.exec() )
{
m_amzList = fileDialog.selectedFiles();
ui->amzFileEdit->setText( m_amzList.at( 0 ) );
}
}
void
AmzDownloader::selectDirectoryClicked()
{
QFileDialog fileDialog( this );
fileDialog.setAcceptMode( QFileDialog::AcceptOpen );
fileDialog.setFileMode( QFileDialog::Directory );
fileDialog.setOptions( QFileDialog::ShowDirsOnly );
fileDialog.setDirectory( m_downloadDir );
if( fileDialog.exec() )
{
m_downloadDir = fileDialog.selectedFiles().at( 0 );
ui->downloadDirectoryEdit->setText( m_downloadDir.absolutePath() );
}
}
void
AmzDownloader::startClicked()
{
QStringList arguments;
arguments << "-d" << m_downloadDir.absolutePath();
arguments << m_amzList;
m_clamzProcess.setProcessChannelMode( QProcess::MergedChannels );
m_clamzProcess.start( "clamz", arguments );
connect( &m_clamzProcess, SIGNAL( error() ), this, SLOT( clamzError() ) );
connect( &m_clamzProcess, SIGNAL( readyRead() ), this, SLOT( clamzOutputAvailable() ) );
connect( &m_clamzProcess, SIGNAL( finished(int,QProcess::ExitStatus) ), this, SLOT( clamzFinished(int,QProcess::ExitStatus) ) );
ui->selectAmzButton->setDisabled( true );
ui->startButton->setDisabled( true );
ui->selectDirectoryButton->setDisabled( true );
}
// private
void
AmzDownloader:: checkAmzList()
{
m_amzList.removeDuplicates();
QStringList errorList, tmpList = m_amzList;
for( int i = 0; i < m_amzList.size(); i++ )
{
if( !QFile::exists( m_amzList.at( i ) ) )
{
errorList << m_amzList.at( i );
tmpList.removeOne( m_amzList.at( i ) );
}
}
m_amzList = tmpList;
if( !errorList.isEmpty() )
{
QMessageBox errorBox;
QString errorMsg;
errorMsg = tr( "The following files do not exist: " );
for( int i = 0; i < errorList.size(); i++ )
errorMsg += "\n" + errorList.at( i );
errorBox.warning( this, tr( "Some files are not available" ), errorMsg );
}
}
// private slots
void
AmzDownloader::clamzError()
{
if( m_clamzProcess.error() == QProcess::FailedToStart )
QMessageBox::warning( this, tr( "Unable to start clamz" ), tr( "Unable to start clamz. has it been installed correctly?" ) );
else
QMessageBox::warning( this, tr( "Unexpected error" ), tr( "Unexpected error downloading with clamz. This should not have happened..." ) );
}
void
AmzDownloader::clamzFinished( int exitCode, QProcess::ExitStatus exitStatus )
{
Q_UNUSED( exitStatus );
if( exitCode == 0 )
QMessageBox::information( this, tr( "Download finished" ), tr( "Download finished successfully. Have fun listening to your music." ) );
else
QMessageBox::warning( this, tr( "Download failed" ), tr( "Please check the progress output for further infos." ) );
ui->selectAmzButton->setDisabled( false );
ui->startButton->setDisabled( false );
ui->selectDirectoryButton->setDisabled( false );
}
void
AmzDownloader::clamzOutputAvailable()
{
ui->progressBrowser->append( m_clamzProcess.readAll() );
}
/****************************************************************************************
* Copyright (c) 2012 Sven Krohlas <sven@getamarok.com> *
* *
* This program is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License as published by the Free Software *
* Foundation; either version 2 of the License, or (at your option) any later *
* version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along with *
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#ifndef AMZDOWNLOADER_H
#define AMZDOWNLOADER_H
#include "ui_AmzDownloader.h"
#include <QDialog>
#include <QDir>
#include <QProcess>
class AmzDownloader : public QDialog
{
Q_OBJECT
public:
explicit AmzDownloader( QWidget *parent = 0 );
~AmzDownloader();
public slots:
void selectAmzClicked();
void selectDirectoryClicked();
void startClicked();
void quitClicked();
private:
void checkAmzList();
Ui::AmzDownloader* ui;
QStringList m_amzList;
QDir m_downloadDir;
QProcess m_clamzProcess;
private slots:
void clamzError();
void clamzFinished( int exitCode, QProcess::ExitStatus exitStatus );
void clamzOutputAvailable();
};
#endif // AMZDOWNLOADER_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AmzDownloader</class>
<widget class="QDialog" name="AmzDownloader">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>348</width>
<height>387</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>AMZ Downloader</string>
</property>
<property name="locale">
<locale language="English" country="UnitedStates"/>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Download directory:</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="downloadDirectoryEdit">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="selectDirectoryButton">
<property name="text">
<string>Select </string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>AMZ file:</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLineEdit" name="amzFileEdit">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="selectAmzButton">
<property name="text">
<string>Select</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Download progress:</string>
</property>
</widget>
</item>
<item>
<widget class="QTextBrowser" name="progressBrowser"/>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="startButton">
<property name="text">
<string>Start</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="quitButton">
<property name="text">
<string>Quit</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
include_directories( ../
${CMAKE_SOURCE_DIR}
${QT_INCLUDES}
${CMAKE_CURRENT_BINARY_DIR}
)
########### next target ###############
set( amzdownloader_UI
AmzDownloader.ui
)
set( amzdownloader_SRCS
main.cpp
AmzDownloader.cpp
)
set( amzdownloader_MOC_HDRS
AmzDownloader.h
)
qt4_wrap_ui( amzdownloader_SRCS ${amzdownloader_UI} )
qt4_wrap_cpp( amzdownloader_MOC ${amzdownloader_MOC_HDRS} )
add_executable( amzdownloader ${amzdownloader_SRCS} ${amzdownloader_MOC})
target_link_libraries( amzdownloader
${QT_QTGUI_LIBRARY}
${QT_QTCORE_LIBRARY}
)
install( TARGETS amzdownloader RUNTIME DESTINATION ${BIN_INSTALL_DIR} )
find_program( XDG-MIME_EXECUTABLE xdg-mime )
find_program( XDG-DESKTOP-MENU_EXECUTABLE xdg-desktop-menu )
execute_process( COMMAND ${XDG-MIME_EXECUTABLE} install --novendor ${CMAKE_CURRENT_LIST_DIR}/amzdownloader.xml )
execute_process( COMMAND ${XDG-DESKTOP-MENU_EXECUTABLE} install --novendor ${CMAKE_CURRENT_LIST_DIR}/amzdownloader.desktop )
execute_process( COMMAND ${XDG-MIME_EXECUTABLE} default amzdownloader.desktop "audio/x-amzxml" )
[Desktop Entry]
Type=Application
Name=AMZ Downloader
Comment=Download with AMZ Downloader
ServiceTypes=audio/x-amzxml,audio/x-amzaudio
Exec=amzdownloader --amz %f
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="audio/x-amzxml">
<comment xml:lang="en">Amazon MP3 Purchase Playlist</comment>
<glob pattern="*.amz"/>
</mime-type>
</mime-info>
/****************************************************************************************
* Copyright (c) 2012 Sven Krohlas <sven@getamarok.com> *
* *
* This program is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License as published by the Free Software *
* Foundation; either version 2 of the License, or (at your option) any later *
* version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along with *
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#include "AmzDownloader.h"
#include <QApplication>
int
main( int argc, char *argv[] )
{
QApplication a( argc, argv );
// let's rock!
AmzDownloader w;
w.show();
return a.exec();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment