summaryrefslogtreecommitdiff
path: root/src/findsubtitles
diff options
context:
space:
mode:
authorMaia Kozheva <sikon@ubuntu.com>2012-04-09 13:30:23 +0700
committerMaia Kozheva <sikon@ubuntu.com>2012-04-09 13:30:23 +0700
commit69d32924ffbfe2bb05d881a23af13b6070b9a9bd (patch)
tree15d9f808ef672e21bcf2da9b6c9fc8e48e157eff /src/findsubtitles
parent65a64d260e05c7bf8d3bdf82e796637dc820e574 (diff)
Imported Upstream version 0.8.0
Diffstat (limited to 'src/findsubtitles')
-rw-r--r--src/findsubtitles/filedownloader/filedownloader.cpp4
-rw-r--r--src/findsubtitles/findsubtitles.pro4
-rw-r--r--src/findsubtitles/findsubtitlesconfigdialog.cpp8
-rw-r--r--src/findsubtitles/findsubtitlesconfigdialog.h4
-rw-r--r--src/findsubtitles/findsubtitlesconfigdialog.ui155
-rw-r--r--src/findsubtitles/findsubtitleswindow.cpp59
-rw-r--r--src/findsubtitles/findsubtitleswindow.h6
-rw-r--r--src/findsubtitles/fixsubs.cpp51
-rw-r--r--src/findsubtitles/fixsubs.h (renamed from src/findsubtitles/simplehttp.h)32
-rw-r--r--src/findsubtitles/osparser.cpp40
-rw-r--r--src/findsubtitles/osparser.h2
-rw-r--r--src/findsubtitles/simplehttp.cpp94
12 files changed, 233 insertions, 226 deletions
diff --git a/src/findsubtitles/filedownloader/filedownloader.cpp b/src/findsubtitles/filedownloader/filedownloader.cpp
index 88c213e..101c974 100644
--- a/src/findsubtitles/filedownloader/filedownloader.cpp
+++ b/src/findsubtitles/filedownloader/filedownloader.cpp
@@ -56,12 +56,12 @@ void FileDownloader::setProxy(QNetworkProxy proxy) {
void FileDownloader::download(QUrl url) {
QHttp::ConnectionMode mode = url.scheme().toLower() == "https" ? QHttp::ConnectionModeHttps : QHttp::ConnectionModeHttp;
http->setHost(url.host(), mode, url.port() == -1 ? 0 : url.port());
-
+
if (!url.userName().isEmpty())
http->setUser(url.userName(), url.password());
http_request_aborted = false;
- http_get_id = http->get(url.path());
+ http_get_id = http->get(url.path());
setLabelText(tr("Downloading %1").arg(url.toString()));
}
diff --git a/src/findsubtitles/findsubtitles.pro b/src/findsubtitles/findsubtitles.pro
index ad414ff..ffe65c1 100644
--- a/src/findsubtitles/findsubtitles.pro
+++ b/src/findsubtitles/findsubtitles.pro
@@ -10,17 +10,21 @@ DEPENDPATH += ..
HEADERS += simplehttp.h \
osparser.h \
+ ../filehash.h \
../lineedit_with_icon.h \
../filechooser.h \
../languages.h \
+ fixsubs.h \
findsubtitlesconfigdialog.h \
findsubtitleswindow.h
SOURCES += simplehttp.cpp \
osparser.cpp \
+ ../filehash.cpp \
../lineedit_with_icon.cpp \
../filechooser.cpp \
../languages.cpp \
+ fixsubs.cpp \
findsubtitlesconfigdialog.cpp \
findsubtitleswindow.cpp \
main.cpp
diff --git a/src/findsubtitles/findsubtitlesconfigdialog.cpp b/src/findsubtitles/findsubtitlesconfigdialog.cpp
index a06c00b..97c01b4 100644
--- a/src/findsubtitles/findsubtitlesconfigdialog.cpp
+++ b/src/findsubtitles/findsubtitlesconfigdialog.cpp
@@ -42,6 +42,14 @@ FindSubtitlesConfigDialog::FindSubtitlesConfigDialog( QWidget* parent, Qt::Windo
FindSubtitlesConfigDialog::~FindSubtitlesConfigDialog() {
}
+void FindSubtitlesConfigDialog::setServer(QString server) {
+ server_edit->setText(server);
+}
+
+QString FindSubtitlesConfigDialog::server() {
+ return server_edit->text();
+}
+
void FindSubtitlesConfigDialog::setUseProxy(bool b) {
use_proxy_check->setChecked(b);
}
diff --git a/src/findsubtitles/findsubtitlesconfigdialog.h b/src/findsubtitles/findsubtitlesconfigdialog.h
index c496e0e..33ea105 100644
--- a/src/findsubtitles/findsubtitlesconfigdialog.h
+++ b/src/findsubtitles/findsubtitlesconfigdialog.h
@@ -29,6 +29,10 @@ public:
FindSubtitlesConfigDialog( QWidget* parent = 0, Qt::WindowFlags f = 0 );
~FindSubtitlesConfigDialog();
+ // Server
+ void setServer(QString server);
+ QString server();
+
// Proxy
void setUseProxy(bool b);
bool useProxy();
diff --git a/src/findsubtitles/findsubtitlesconfigdialog.ui b/src/findsubtitles/findsubtitlesconfigdialog.ui
index 5653626..4420b5f 100644
--- a/src/findsubtitles/findsubtitlesconfigdialog.ui
+++ b/src/findsubtitles/findsubtitlesconfigdialog.ui
@@ -1,119 +1,142 @@
-<ui version="4.0" >
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
<class>FindSubtitlesConfigDialog</class>
- <widget class="QDialog" name="FindSubtitlesConfigDialog" >
- <property name="geometry" >
+ <widget class="QDialog" name="FindSubtitlesConfigDialog">
+ <property name="geometry">
<rect>
<x>0</x>
<y>0</y>
- <width>489</width>
- <height>271</height>
+ <width>493</width>
+ <height>335</height>
</rect>
</property>
- <property name="windowTitle" >
+ <property name="windowTitle">
<string>Advanced options</string>
</property>
- <layout class="QVBoxLayout" >
+ <layout class="QVBoxLayout">
<item>
- <widget class="QGroupBox" name="groupBox" >
- <property name="title" >
+ <widget class="QGroupBox" name="groupBox_2">
+ <property name="title">
+ <string>Server</string>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>&amp;Opensubtitles server:</string>
+ </property>
+ <property name="buddy">
+ <cstring>server_edit</cstring>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="server_edit"/>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="groupBox">
+ <property name="title">
<string>Proxy</string>
</property>
- <layout class="QVBoxLayout" >
+ <layout class="QVBoxLayout">
<item>
- <widget class="QCheckBox" name="use_proxy_check" >
- <property name="text" >
+ <widget class="QCheckBox" name="use_proxy_check">
+ <property name="text">
<string>&amp;Enable proxy</string>
</property>
</widget>
</item>
<item>
- <widget class="QWidget" native="1" name="proxy_container" >
- <property name="enabled" >
+ <widget class="QWidget" name="proxy_container" native="true">
+ <property name="enabled">
<bool>false</bool>
</property>
- <layout class="QGridLayout" >
- <item row="0" column="0" >
- <widget class="QLabel" name="label_2" >
- <property name="text" >
+ <layout class="QGridLayout">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
<string>&amp;Host:</string>
</property>
- <property name="buddy" >
+ <property name="buddy">
<cstring>proxy_hostname_edit</cstring>
</property>
</widget>
</item>
- <item row="0" column="1" colspan="2" >
- <widget class="QLineEdit" name="proxy_hostname_edit" />
+ <item row="0" column="1" colspan="2">
+ <widget class="QLineEdit" name="proxy_hostname_edit"/>
</item>
- <item row="0" column="3" >
- <widget class="QLabel" name="label_3" >
- <property name="text" >
+ <item row="0" column="3">
+ <widget class="QLabel" name="label_3">
+ <property name="text">
<string>&amp;Port:</string>
</property>
- <property name="alignment" >
+ <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
- <property name="buddy" >
+ <property name="buddy">
<cstring>proxy_port_spin</cstring>
</property>
</widget>
</item>
- <item row="0" column="4" >
- <widget class="QSpinBox" name="proxy_port_spin" >
- <property name="maximum" >
+ <item row="0" column="4">
+ <widget class="QSpinBox" name="proxy_port_spin">
+ <property name="maximum">
<number>65535</number>
</property>
</widget>
</item>
- <item row="1" column="0" >
- <widget class="QLabel" name="label_4" >
- <property name="text" >
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_4">
+ <property name="text">
<string>&amp;Username:</string>
</property>
- <property name="buddy" >
+ <property name="buddy">
<cstring>proxy_username_edit</cstring>
</property>
</widget>
</item>
- <item row="1" column="1" colspan="4" >
- <widget class="QLineEdit" name="proxy_username_edit" />
+ <item row="1" column="1" colspan="4">
+ <widget class="QLineEdit" name="proxy_username_edit"/>
</item>
- <item row="2" column="0" >
- <widget class="QLabel" name="label_5" >
- <property name="text" >
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_5">
+ <property name="text">
<string>Pa&amp;ssword:</string>
</property>
- <property name="buddy" >
+ <property name="buddy">
<cstring>proxy_password_edit</cstring>
</property>
</widget>
</item>
- <item row="2" column="1" colspan="4" >
- <widget class="QLineEdit" name="proxy_password_edit" >
- <property name="echoMode" >
+ <item row="2" column="1" colspan="4">
+ <widget class="QLineEdit" name="proxy_password_edit">
+ <property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
- <item row="3" column="0" >
- <widget class="QLabel" name="label_6" >
- <property name="text" >
+ <item row="3" column="0">
+ <widget class="QLabel" name="label_6">
+ <property name="text">
<string>&amp;Type:</string>
</property>
- <property name="buddy" >
+ <property name="buddy">
<cstring>proxy_type_combo</cstring>
</property>
</widget>
</item>
- <item row="3" column="1" >
- <widget class="QComboBox" name="proxy_type_combo" />
+ <item row="3" column="1">
+ <widget class="QComboBox" name="proxy_type_combo"/>
</item>
- <item row="3" column="2" colspan="3" >
+ <item row="3" column="2" colspan="3">
<spacer>
- <property name="orientation" >
+ <property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
- <property name="sizeHint" >
+ <property name="sizeHint" stdset="0">
<size>
<width>261</width>
<height>20</height>
@@ -128,17 +151,27 @@
</widget>
</item>
<item>
- <widget class="QDialogButtonBox" name="buttonBox" >
- <property name="orientation" >
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
- <property name="standardButtons" >
- <set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
+ <tabstops>
+ <tabstop>server_edit</tabstop>
+ <tabstop>use_proxy_check</tabstop>
+ <tabstop>proxy_hostname_edit</tabstop>
+ <tabstop>proxy_port_spin</tabstop>
+ <tabstop>proxy_username_edit</tabstop>
+ <tabstop>proxy_password_edit</tabstop>
+ <tabstop>proxy_type_combo</tabstop>
+ <tabstop>buttonBox</tabstop>
+ </tabstops>
<resources/>
<connections>
<connection>
@@ -147,11 +180,11 @@
<receiver>FindSubtitlesConfigDialog</receiver>
<slot>accept()</slot>
<hints>
- <hint type="sourcelabel" >
+ <hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
- <hint type="destinationlabel" >
+ <hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
@@ -163,11 +196,11 @@
<receiver>FindSubtitlesConfigDialog</receiver>
<slot>reject()</slot>
<hints>
- <hint type="sourcelabel" >
+ <hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
- <hint type="destinationlabel" >
+ <hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
@@ -179,11 +212,11 @@
<receiver>proxy_container</receiver>
<slot>setEnabled(bool)</slot>
<hints>
- <hint type="sourcelabel" >
+ <hint type="sourcelabel">
<x>260</x>
<y>91</y>
</hint>
- <hint type="destinationlabel" >
+ <hint type="destinationlabel">
<x>260</x>
<y>179</y>
</hint>
diff --git a/src/findsubtitles/findsubtitleswindow.cpp b/src/findsubtitles/findsubtitleswindow.cpp
index 662a746..fa3e33c 100644
--- a/src/findsubtitles/findsubtitleswindow.cpp
+++ b/src/findsubtitles/findsubtitleswindow.cpp
@@ -20,6 +20,7 @@
#include "findsubtitlesconfigdialog.h"
#include "simplehttp.h"
#include "osparser.h"
+#include "filehash.h"
#include "languages.h"
#include <QStandardItemModel>
#include <QSortFilterProxyModel>
@@ -38,6 +39,7 @@
#include "subchooserdialog.h"
#include "quazip.h"
#include "quazipfile.h"
+#include "fixsubs.h"
#include <QTemporaryFile>
#include <QBuffer>
#endif
@@ -128,11 +130,13 @@ FindSubtitlesWindow::FindSubtitlesWindow( QWidget * parent, Qt::WindowFlags f )
include_lang_on_filename = true;
file_downloader = new FileDownloader(this);
- file_downloader->setModal(false);
+ file_downloader->setModal(false);
connect( file_downloader, SIGNAL(downloadFailed(QString)),
this, SLOT(showError(QString)), Qt::QueuedConnection );
connect( file_downloader, SIGNAL(downloadFinished(const QByteArray &)),
this, SLOT(archiveDownloaded(const QByteArray &)), Qt::QueuedConnection );
+ connect( this, SIGNAL(subtitleDownloaded(const QString &)),
+ this, SLOT(fixSubtitles(const QString &)) );
#endif
// Actions
@@ -152,6 +156,9 @@ FindSubtitlesWindow::FindSubtitlesWindow( QWidget * parent, Qt::WindowFlags f )
language_filter->setCurrentIndex(0);
+ // Opensubtitles server
+ os_server = "http://www.opensubtitles.org";
+
// Proxy
use_proxy = false;
proxy_type = QNetworkProxy::HttpProxy;
@@ -199,14 +206,31 @@ void FindSubtitlesWindow::retranslateStrings() {
QString current_language = language_filter->itemData(language_filter->currentIndex()).toString();
language_filter->clear();
- QMap<QString,QString> l = Languages::list();
- QMapIterator<QString, QString> i(l);
- while (i.hasNext()) {
- i.next();
- language_filter->addItem( i.value() + " (" + i.key() + ")", i.key() );
+ QMap<QString,QString> l1 = Languages::most_used_list();
+ QMapIterator<QString, QString> i1(l1);
+ while (i1.hasNext()) {
+ i1.next();
+ language_filter->addItem( i1.value() + " (" + i1.key() + ")", i1.key() );
}
+ language_filter->addItem( tr("Portuguese - Brasil") + " (pb)", "pb");
language_filter->model()->sort(0);
+ #if QT_VERSION >= 0x040400
+ language_filter->insertSeparator(language_filter->count());
+ #endif
+
+ QMap<QString,QString> l2 = Languages::list();
+ QMapIterator<QString, QString> i2(l2);
+ while (i2.hasNext()) {
+ i2.next();
+ if (language_filter->findData(i2.key()) == -1) {
+ language_filter->addItem( i2.value() + " (" + i2.key() + ")", i2.key() );
+ }
+ }
+ //language_filter->model()->sort(0);
language_filter->insertItem( 0, tr("All"), "*" );
+ #if QT_VERSION >= 0x040400
+ language_filter->insertSeparator(1);
+ #endif
//language_filter->setCurrentIndex(language_index);
language_filter->setCurrentIndex(language_filter->findData(current_language));
@@ -240,11 +264,11 @@ void FindSubtitlesWindow::setMovie(QString filename) {
file_chooser->setText(filename);
table->setRowCount(0);
- QString hash = OSParser::calculateHash(filename);
+ QString hash = FileHash::calculateHash(filename);
if (hash.isEmpty()) {
qWarning("FindSubtitlesWindow::setMovie: hash invalid. Doing nothing.");
} else {
- QString link = "http://www.opensubtitles.org/search/sublanguageid-all/moviehash-" + hash + "/simplexml";
+ QString link = os_server + "/search/sublanguageid-all/moviehash-" + hash + "/simplexml";
qDebug("FindSubtitlesWindow::setMovie: link: '%s'", link.toLatin1().constData());
downloader->download(link);
last_file = filename;
@@ -541,7 +565,7 @@ bool FindSubtitlesWindow::uncompressZip(const QString & filename, const QString
qDebug("FindSubtitlesWindow::uncompressZip: extracted %s ok: %d", file.toUtf8().constData(), ok);
if (ok) extracted_count++;
}
- status->setText(tr("%1 subtitle(s) extracted","", extracted_count).arg(extracted_count));
+ status->setText(tr("%n subtitle(s) extracted","", extracted_count));
if (extracted_count > 0) {
emit subtitleDownloaded( output_path +"/"+ files_to_extract[0] );
}
@@ -593,6 +617,19 @@ bool FindSubtitlesWindow::extractFile(QuaZip & zip, const QString & filename, co
return true;
}
+void FindSubtitlesWindow::fixSubtitles(const QString & filename) {
+ qDebug("FindSubtitlesWindow::fixSubtitles: %s", filename.toUtf8().constData());
+
+ QFileInfo fi(filename);
+ if (fi.suffix().toLower() == "sub") {
+ qDebug("FindSubtitlesWindow::fixSubtitles: fixing end of lines");
+ if (FixSubtitles::fix(filename) != FixSubtitles::NoError) {
+ status->setText( tr("Error fixing the subtitle lines") );
+ qDebug("FindSubtitlesWindow::fixSubtitles: error fixing the subtitles");
+ }
+ }
+}
+
#endif
void FindSubtitlesWindow::on_configure_button_clicked() {
@@ -600,6 +637,7 @@ void FindSubtitlesWindow::on_configure_button_clicked() {
FindSubtitlesConfigDialog d(this);
+ d.setServer( os_server );
d.setUseProxy( use_proxy );
d.setProxyHostname( proxy_host );
d.setProxyPort( proxy_port );
@@ -608,6 +646,7 @@ void FindSubtitlesWindow::on_configure_button_clicked() {
d.setProxyType( proxy_type );
if (d.exec() == QDialog::Accepted) {
+ os_server = d.server();
use_proxy = d.useProxy();
proxy_host = d.proxyHostname();
proxy_port = d.proxyPort();
@@ -646,6 +685,7 @@ void FindSubtitlesWindow::saveSettings() {
set->beginGroup("findsubtitles");
+ set->setValue("server", os_server);
set->setValue("language", language());
#ifdef DOWNLOAD_SUBS
set->setValue("include_lang_on_filename", includeLangOnFilename());
@@ -665,6 +705,7 @@ void FindSubtitlesWindow::loadSettings() {
set->beginGroup("findsubtitles");
+ os_server = set->value("server", os_server).toString();
setLanguage( set->value("language", language()).toString() );
#ifdef DOWNLOAD_SUBS
setIncludeLangOnFilename( set->value("include_lang_on_filename", includeLangOnFilename()).toBool() );
diff --git a/src/findsubtitles/findsubtitleswindow.h b/src/findsubtitles/findsubtitleswindow.h
index 1ae2e49..1fbc11f 100644
--- a/src/findsubtitles/findsubtitleswindow.h
+++ b/src/findsubtitles/findsubtitleswindow.h
@@ -103,6 +103,9 @@ signals:
protected:
bool uncompressZip(const QString & filename, const QString & output_path, const QString & preferred_output_name);
bool extractFile(QuaZip & zip, const QString & filename, const QString & output_name);
+
+protected slots:
+ void fixSubtitles(const QString & filename);
#endif
protected:
@@ -120,6 +123,9 @@ protected:
bool include_lang_on_filename;
#endif
+ // Opensubtitles server
+ QString os_server;
+
// Proxy
bool use_proxy;
int proxy_type;
diff --git a/src/findsubtitles/fixsubs.cpp b/src/findsubtitles/fixsubs.cpp
new file mode 100644
index 0000000..f797847
--- /dev/null
+++ b/src/findsubtitles/fixsubs.cpp
@@ -0,0 +1,51 @@
+/* smplayer, GUI front-end for mplayer.
+ Copyright (C) 2006-2012 Ricardo Villalba <rvm@users.sourceforge.net>
+
+ 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, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include "fixsubs.h"
+#include <QFile>
+
+FixSubtitles::ErrorCode FixSubtitles::fix(const QString & in_file, const QString & out_file) {
+ QFile file(in_file);
+ QByteArray result;
+
+ if (!file.open(QIODevice::ReadOnly)) {
+ return ReadError;
+ }
+
+ while (!file.atEnd()) {
+ QByteArray line = file.readLine().replace("\r\n", "\n").replace("\r", "\n").replace("\n", "\r\n");
+ //qDebug("l: '%s'", line.constData());
+ result += line;
+ }
+ file.close();
+ //qDebug("r: '%s'", result.constData());
+
+ QString out = out_file;
+ if (out.isEmpty()) out = in_file;
+ file.setFileName(out);
+
+ if (!file.open(QIODevice::WriteOnly)) {
+ return WriteError;
+ }
+
+ file.write(result);
+ file.close();
+
+ return NoError;
+}
+
diff --git a/src/findsubtitles/simplehttp.h b/src/findsubtitles/fixsubs.h
index 9b57526..58d00bb 100644
--- a/src/findsubtitles/simplehttp.h
+++ b/src/findsubtitles/fixsubs.h
@@ -16,36 +16,16 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef _SIMPLEHTTP_H_
-#define _SIMPLEHTTP_H_
+#ifndef FIXSUBS_H
+#define FIXSUBS_H
-#include <QHttp>
+#include <QString>
-class QHttp;
-class QHttpResponseHeader;
-
-class SimpleHttp : public QHttp
+class FixSubtitles
{
- Q_OBJECT
-
public:
- SimpleHttp( QObject* parent = 0 );
- ~SimpleHttp();
-
- void download(const QString & url);
-
-signals:
- void connecting(QString host);
- void downloadFinished(QByteArray downloaded_text);
- void downloadFailed(QString error);
-
-protected slots:
- void readResponseHeader(const QHttpResponseHeader &responseHeader);
- void httpRequestFinished(int request_id, bool error);
-
-protected:
- QByteArray downloaded_text;
- int http_get_id;
+ enum ErrorCode { NoError = 0, ReadError = 1, WriteError = 2 };
+ static ErrorCode fix(const QString & in_file, const QString & out_file = QString::null);
};
#endif
diff --git a/src/findsubtitles/osparser.cpp b/src/findsubtitles/osparser.cpp
index f526007..3708704 100644
--- a/src/findsubtitles/osparser.cpp
+++ b/src/findsubtitles/osparser.cpp
@@ -18,8 +18,8 @@
#include "osparser.h"
#include <QDomDocument>
-#include <QFile>
-#include <QDataStream>
+//#include <QFile>
+//#include <QDataStream>
OSParser::OSParser() {
}
@@ -54,7 +54,12 @@ bool OSParser::parseXml(QByteArray text) {
OSSubtitle sub;
sub.releasename = subtitle.firstChildElement("releasename").text();
- sub.link = base_url + subtitle.firstChildElement("download").text();
+ QString path = subtitle.firstChildElement("download").text();
+ if (path.contains("http://")) {
+ sub.link = subtitle.firstChildElement("download").text();
+ } else {
+ sub.link = base_url + subtitle.firstChildElement("download").text();
+ }
sub.detail = subtitle.firstChildElement("detail").text();
sub.date = subtitle.firstChildElement("subadddate").text();
sub.rating = subtitle.firstChildElement("subrating").text();
@@ -75,32 +80,3 @@ bool OSParser::parseXml(QByteArray text) {
return true;
}
-// From the patch by Kamil Dziobek turbos11(at)gmail.com
-// (c) Kamil Dziobek turbos11(at)gmail.com | BSD or GPL or public domain
-QString OSParser::calculateHash(QString filename) {
- QFile file(filename);
-
- if (!file.exists()) {
- qWarning("OSParser:calculateHash: error hashing file. File doesn't exist.");
- return QString();
- }
-
- file.open(QIODevice::ReadOnly);
- QDataStream in(&file);
- in.setByteOrder(QDataStream::LittleEndian);
- quint64 size=file.size ();
- quint64 hash=size;
- quint64 a;
- for(int i = 0; i < 8192; i++) {
- in >> a ; hash += a;
- };
- file.seek(size-65536);
- for(int i = 0; i < 8192; i++) {
- in >> a ; hash += a;
- };
-
- QString hexhash = QString("%1").arg(hash, 16, 16, QChar('0'));
-
- return hexhash;
-}
-
diff --git a/src/findsubtitles/osparser.h b/src/findsubtitles/osparser.h
index 90edc7f..c8af8c9 100644
--- a/src/findsubtitles/osparser.h
+++ b/src/findsubtitles/osparser.h
@@ -40,8 +40,6 @@ public:
QList<OSSubtitle> subtitleList() { return s_list; };
- static QString calculateHash(QString filename);
-
protected:
QDomDocument dom_document;
QList <OSSubtitle> s_list;
diff --git a/src/findsubtitles/simplehttp.cpp b/src/findsubtitles/simplehttp.cpp
deleted file mode 100644
index 9624519..0000000
--- a/src/findsubtitles/simplehttp.cpp
+++ /dev/null
@@ -1,94 +0,0 @@
-/* smplayer, GUI front-end for mplayer.
- Copyright (C) 2006-2012 Ricardo Villalba <rvm@users.sourceforge.net>
-
- 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, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*/
-
-#include "simplehttp.h"
-#include <QUrl>
-
-SimpleHttp::SimpleHttp( QObject * parent ) : QHttp(parent)
-{
- http_get_id = -1;
-
- connect( this, SIGNAL(requestFinished(int, bool)),
- this, SLOT(httpRequestFinished(int, bool)) );
-
- connect( this, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)),
- this, SLOT(readResponseHeader(const QHttpResponseHeader &)) );
-}
-
-SimpleHttp::~SimpleHttp() {
-}
-
-void SimpleHttp::download(const QString & url) {
- qDebug("SimpleHttp::download: %s", url.toLatin1().constData());
-
- downloaded_text.clear();
-
- QUrl u(url);
- setHost( u.host() );
-
- /*
- qDebug("u.path: %s", u.path().toLatin1().constData());
- qDebug("u.query: %s", u.encodedQuery().constData());
- */
-
- QString p = u.path();
- if (!u.encodedQuery().isEmpty()) p += "?" + u.encodedQuery();
-
- http_get_id = get( p );
-
- emit connecting(u.host());
-}
-
-void SimpleHttp::readResponseHeader(const QHttpResponseHeader &responseHeader) {
- qDebug("SimpleHttp::readResponseHeader: statusCode: %d", responseHeader.statusCode());
-
- if (responseHeader.statusCode() == 301) {
- QString new_url = responseHeader.value("Location");
- qDebug("SimpleHttp::readResponseHeader: Location: '%s'", new_url.toLatin1().constData());
- download(new_url);
- }
- else
- if (responseHeader.statusCode() == 302) {
- QString location = responseHeader.value("Location");
- qDebug("SimpleHttp::readResponseHeader: Location: '%s'", location.toLatin1().constData());
- http_get_id = get( location );
- }
- else
- if (responseHeader.statusCode() != 200) {
- qDebug("SimpleHttp::readResponseHeader: error: '%s'", responseHeader.reasonPhrase().toLatin1().constData());
- emit downloadFailed(responseHeader.reasonPhrase());
- abort();
- }
-}
-
-void SimpleHttp::httpRequestFinished(int request_id, bool error) {
- qDebug("SimpleHttp::httpRequestFinished: http_get_id: %d request_id: %d, error: %d", http_get_id, request_id, error);
-
- if (request_id != http_get_id) return;
-
- downloaded_text += readAll();
-
- //qDebug("downloaded_text: '%s'", downloaded_text.constData());
-
- if ((!error) && (!downloaded_text.isEmpty())) {
- emit downloadFinished(downloaded_text);
- }
-}
-
-#include "moc_simplehttp.cpp"
-