Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Drive and Dropbox resolvers #41

Open
wants to merge 139 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
139 commits
Select commit Hold shift + click to select a range
b60bdc9
Merge pull request #34 from tomahawk-player/scriptcollection-ng
teo Feb 8, 2013
0c31e05
Merge pull request #35 from tomahawk-player/scriptcollection-ng-ampache
teo Feb 8, 2013
f759f91
Show the correct URL for recent ownCloud instances.
teo Feb 11, 2013
5210570
Merge branch 'master', remote-tracking branch 'upstream/master'
AltarBeastiful Feb 12, 2013
e7286be
Don't fail if the server doesn't fill out album["album"].
teo Feb 12, 2013
e94fd59
Add empty resolver for Dropbox.
AltarBeastiful Feb 13, 2013
8f91227
Add collection info support to Subsonic.
teo Feb 17, 2013
215967a
Add collection info support to Ampache.
teo Feb 17, 2013
3a7188e
adding musicManager, on working version
Knarf64 Feb 17, 2013
90a5572
Add Oauth authentification to Dropbox resolver.
AltarBeastiful Feb 19, 2013
ca6f80a
Rewrite of the oauth in Dropbox resolver.
AltarBeastiful Feb 19, 2013
f6751b1
Minor correction when deleting the association in Dropbox resolver
AltarBeastiful Feb 20, 2013
fd7815f
Add Google drive resolver with OAuth manager and changes.list request.
AltarBeastiful Feb 20, 2013
d635ec2
Add oauth managment in google drive resolver.
AltarBeastiful Feb 21, 2013
006b53b
Added client_id param for ex.fm calls.
muesli Feb 21, 2013
fc0480f
Intercept session error on every API call and reauth as needed.
teo Feb 22, 2013
82487a7
Fix in the musicManager.js
Knarf64 Feb 22, 2013
e10bfe2
Merge branch 'master' of https://github.com/ISI-Peasy/tomahawk-resolvers
Knarf64 Feb 22, 2013
7bcb6c0
Actually store the new auth token, and use it.
teo Feb 24, 2013
8d7f0c9
Remove commented-out code.
teo Feb 24, 2013
7b0a779
Fix callbacks in google drive (use bind function).
AltarBeastiful Feb 24, 2013
cd5a252
working version of music Manager
Knarf64 Feb 24, 2013
f1dbfaf
merged
Knarf64 Feb 24, 2013
63433ec
Add license to Google drive, dropbox and musicManager.js
AltarBeastiful Feb 24, 2013
905d7ca
Asyncify.
teo Feb 24, 2013
b1efc86
Merge pull request #36 from tomahawk-player/ampache-reauth
teo Feb 24, 2013
ed8afb1
Added track count support to Ampache.
teo Feb 26, 2013
53ccdf7
DRY in Ampache handshake processing.
teo Feb 26, 2013
db1b2aa
Cursor support and multiple delta pages on Google drive resolver.
AltarBeastiful Feb 26, 2013
5a38139
Add ID music Manager
Knarf64 Feb 26, 2013
38a034f
Merge branch 'master' of https://github.com/ISI-Peasy/tomahawk-resolvers
Knarf64 Feb 26, 2013
a47a28a
Google drive : add itself inside scriptcollection ,
Knarf64 Feb 26, 2013
d7488b2
MusicManager of dropbox updated from google'one
Knarf64 Feb 26, 2013
dfeeb91
Add custom url handler for google drive resolver.
AltarBeastiful Feb 26, 2013
9a535d1
Dropbox resolver:
AltarBeastiful Feb 26, 2013
8e174af
Merge branch 'master' of github.com:ISI-Peasy/tomahawk-resolvers
AltarBeastiful Feb 26, 2013
88bf984
Log info for ID3 tags in dropbox and google drive.
AltarBeastiful Feb 26, 2013
469f974
Add reportCapabilities to resolvers.
AltarBeastiful Feb 26, 2013
54682f4
Add the parsing of id3 tags.
AltarBeastiful Feb 27, 2013
07374f2
ca marche avec la downloadUrl + le token
loclamor Feb 27, 2013
576e63a
ajout du parametre ID lors de l'appel a readCloudFile
loclamor Feb 28, 2013
5c763c7
Make token refresh synchronous in googleDrive.
AltarBeastiful Feb 28, 2013
5042c0c
Update README
jherskowitz Mar 3, 2013
d8d940c
Auto refresh token in Google drive resolver.
AltarBeastiful Mar 4, 2013
dd3fdc4
Set a prettyName for Subsonic/Runners-ID.
teo Mar 4, 2013
93301c9
Add different text/icon support to Ampache resolver for ownCloud.
teo Mar 5, 2013
e625a9d
Add different text/icon support to Subsonic resolver for Runners-ID i.e.
teo Mar 5, 2013
5deb9a5
Oops, forgot the icon.
teo Mar 5, 2013
c1aa0d2
Use new Ampache logo in resolver config dialog.
teo Mar 5, 2013
166efe4
Resize a bit.
teo Mar 5, 2013
b853e0a
Made it transparent with the apex of my GIMP skills.
teo Mar 5, 2013
daac349
Add tracks tags in musicManager DB for google drive resolver.
AltarBeastiful Mar 5, 2013
a42410e
Cahnge custom url handler to show a hostname.
AltarBeastiful Mar 5, 2013
2ff8dfd
Fix if not all tags are given when adding track.
AltarBeastiful Mar 5, 2013
a0f379f
--
Knarf64 Mar 6, 2013
4081cd6
Merge branch 'master' of https://github.com/ISI-Peasy/tomahawk-resolv…
Knarf64 Mar 6, 2013
fa3531e
Use downloadLink to play google drive files
AltarBeastiful Mar 6, 2013
1a3cc80
Merge branch 'master' of github.com:tomahawk-player/tomahawk-resolvers
AltarBeastiful Mar 6, 2013
656ee8d
Merge branch 'master' of github.com:ISI-Peasy/tomahawk-resolvers
AltarBeastiful Mar 6, 2013
8218484
Merge branch 'feature/id3tag'
AltarBeastiful Mar 6, 2013
7340dcf
Safer Addtrack and test to proove it
Knarf64 Mar 6, 2013
0466358
Test scenario DuplicateInsertion add
Knarf64 Mar 6, 2013
9c0a318
Enable add results in GD
AltarBeastiful Mar 6, 2013
8c17523
Test scenario Insertion without the core information track add
Knarf64 Mar 6, 2013
4867a37
ajout fonction collection dans gd.js
Mar 6, 2013
646240a
Merge branch 'master' of https://github.com/ISI-Peasy/tomahawk-resolvers
Mar 6, 2013
4b80285
Test scenario : delition without key add and some corrections
Knarf64 Mar 6, 2013
87dc694
Complete ID3Tag callback in Dropbox.
AltarBeastiful Mar 6, 2013
f1a4957
Merge branch 'master' of https://github.com/ISI-Peasy/tomahawk-resolvers
Knarf64 Mar 6, 2013
f6c1490
Unsloppify string in Ampache config ui.
teo Mar 6, 2013
dc5ef92
Consistency++
teo Mar 6, 2013
c767bc0
Merge branch 'feature/id3tag'
AltarBeastiful Mar 7, 2013
e18d935
Add log message in track function
AltarBeastiful Mar 7, 2013
d985a71
adding fixed : wrong row title instead of track
Knarf64 Mar 7, 2013
0797495
Merge branch 'master' of https://github.com/ISI-Peasy/tomahawk-resolvers
Knarf64 Mar 7, 2013
be2d491
Removing buggy log
AltarBeastiful Mar 7, 2013
0d39d08
Changed Title to Track to add into database
Knarf64 Mar 7, 2013
2f7ebcc
Dropbox music manager adapted from the newest version of GD music man…
Knarf64 Mar 7, 2013
5968b1d
Little corrections on music manager et the concat bug of googledrive.js
Knarf64 Mar 7, 2013
8f70b22
add fonction collection to dropbox.js
Mar 7, 2013
359b73e
Merge branch 'master' of https://github.com/ISI-Peasy/tomahawk-resolvers
Mar 7, 2013
81a5330
[beets] Bundlify
xhochy Mar 17, 2013
2c1a136
[beets] Load config on startup.
xhochy Mar 17, 2013
051a4fa
[beets] jslint coding style
xhochy Mar 17, 2013
088d4cc
Add copyright information
xhochy Mar 17, 2013
326ae9d
Fix YouTube parsing.
rotzbouw Mar 21, 2013
fcd6f03
Change Googledrive incon to SVG.
AltarBeastiful Mar 22, 2013
71fb450
Change Dropbox incon to svg.
AltarBeastiful Mar 22, 2013
6231447
Change config.ui of dropbox and google drive with SVG icon
AltarBeastiful Mar 22, 2013
fd58e5a
Merge pull request #32 from hades/master
muesli Mar 24, 2013
6749b80
Rearrange Subsonic directory structure as a bundle.
teo Mar 9, 2013
d2a81ff
Added script to convert JSON resolver config into desktop file format.
teo Mar 13, 2013
6336023
Replace desktop file with JSON config.
teo Mar 13, 2013
1e17d11
Whitespace--
teo Mar 13, 2013
81b983d
Bundlify Ampache!
teo Mar 14, 2013
3ad2807
Move scripts around a bit.
teo Mar 15, 2013
981e9c8
We actually don't need any gems for this script.
teo Mar 15, 2013
84be58c
Use UTC in json2desktop.rb output timestamp.
teo Mar 15, 2013
3028ddc
New script to create resolver bundles (axes).
teo Mar 15, 2013
90e61b5
JSON doesn't want comments, d'oh.
teo Mar 15, 2013
e22b0e0
Add --release switch to makeaxe.rb avoid inclusion of revision hash.
teo Mar 17, 2013
fb77aeb
Bundlify 4shared.
teo Mar 18, 2013
8d7f443
Bundlify Dilandau.
teo Mar 18, 2013
d5fcd69
Bundlify Grooveshark.
teo Mar 18, 2013
66db813
License headers.
teo Mar 18, 2013
75b0d57
Fix indentation. Sorry.
teo Mar 18, 2013
f861ee4
Fix indentation again.
teo Mar 18, 2013
ebb6ea2
Bundlify Jamendo.
teo Mar 18, 2013
e9d4291
Bundlify Last.fm.
teo Mar 18, 2013
ebc8073
Initial documentation.
teo Mar 18, 2013
11b90e1
Added HACKING file contents.
teo Mar 18, 2013
637cd40
Bundlify Official.fm.
teo Mar 18, 2013
ea89200
Bundlify Qobuz.
teo Mar 19, 2013
e9455bb
Bundlify SoundCloud.
teo Mar 19, 2013
58ab806
Bundlify 8tracks.
teo Mar 19, 2013
0dea9b7
Bundlify VKontakte.
teo Mar 19, 2013
8228750
Bundlify YouTube.
teo Mar 19, 2013
01a8832
Add licensing information.
teo Mar 19, 2013
a47c79a
Improve wording in HACKING.
teo Mar 19, 2013
9b2a972
Merge pull request #38 from tomahawk-player/resolverbundles
teo Mar 24, 2013
5133062
Merge pull request #39 from xhochy/feature/bundle-beets
teo Mar 24, 2013
71e3c9b
Add images dir for compatibility reasons.
teo Mar 24, 2013
67e38a1
Merge branch 'master' of github.com:tomahawk-player/tomahawk-resolvers
AltarBeastiful Mar 24, 2013
38425a0
Make custom url handler asynchronous in Google Drive.
AltarBeastiful Mar 24, 2013
97101ba
update to allow cloudstream to ask a new streamUrl
loclamor Mar 25, 2013
8dba55e
Merge branch 'master' of https://github.com/ISI-Peasy/tomahawk-resolvers
loclamor Mar 25, 2013
5ecd12d
Flush track DB when deleting association.
AltarBeastiful Mar 27, 2013
8091d38
Flush DB when deleting association in google drive.
AltarBeastiful Mar 27, 2013
ea28e7a
Bundle Google Drive and Dropbox resolvers.
AltarBeastiful Mar 24, 2013
f2f8905
Handle case when querying the musicManager DB.
AltarBeastiful Mar 27, 2013
7cfa33d
Better Handle of resolve in musicManager.
AltarBeastiful Mar 27, 2013
b80ba8c
Add error handling when executing SQL in musicManagers.
AltarBeastiful Mar 28, 2013
43583b5
Update readCloudUrl function name.
AltarBeastiful Mar 28, 2013
c95ab93
Handling undefined album insertion into database, with bunch of test …
Knarf64 Mar 29, 2013
d979229
Remove OAuth App key and secret from resolvers.
AltarBeastiful Mar 29, 2013
27912d0
Remove call to addLocalJSFil. Now using resolver bundle.
AltarBeastiful Apr 9, 2013
52977ca
Encode url when the custom url handler is called.
AltarBeastiful Apr 10, 2013
3d4d3c3
Update track database when artists() is called.
AltarBeastiful Apr 10, 2013
8b3b891
Change function name to asyncFormPostRequest.
AltarBeastiful Apr 11, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
/*
* (c) 2011 lasconic <lasconic@gmail.com>
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2011, lasconic <lasconic@gmail.com>
*
* Tomahawk 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 3 of the License, or
* (at your option) any later version.
*
* Tomahawk 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 Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/

var FSharedResolver = Tomahawk.extend(TomahawkResolver, {
settings: {
name: '4shared',
Expand Down
Binary file added 4shared/content/contents/images/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions 4shared/content/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "4Shared",
"pluginName": "4shared",
"author": "lasconic",
"email": "lasconic@gmail.com",
"version": "0.1.5",
"website": "http://gettomahawk.com",
"description": "Looks for tracks to play from www.4shared.com",
"type": "resolver/javascript",
"manifest": {
"main": "contents/code/4shared-resolver.js",
"scripts": [],
"icon": "contents/images/icon.png",
"resources": [
"contents/code/4shared-icon.png"
]
}
}
21 changes: 18 additions & 3 deletions 8tracks/8tracks.js → 8tracks/content/contents/code/8tracks.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
/*
* (c) 2011 Janez Troha (https://github.com/dz0ny)
* (c) 2011 Leo Franchi <lfranchi@kde.org)
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2011, Janez Troha (https://github.com/dz0ny)
* Copyright 2011, Leo Franchi <lfranchi@kde.org>
*
* Tomahawk 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 3 of the License, or
* (at your option) any later version.
*
* Tomahawk 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 Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/

var EightTracksResolver = Tomahawk.extend(TomahawkResolver, {
settings: {
name: '8tracks Resolver',
Expand Down
Binary file added 8tracks/content/contents/images/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions 8tracks/content/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "8tracks",
"pluginName": "8tracks",
"author": "Janez and Leo",
"email": "lfranchi@kde.org",
"version": "0.1",
"website": "http://gettomahawk.com",
"description": "Looks for tracks to play from 8tracks.com",
"type": "resolver/javascript",
"manifest": {
"main": "contents/code/8tracks.js",
"scripts": [],
"icon": "contents/images/icon.png",
"resources": []
}
}
114 changes: 114 additions & 0 deletions HACKING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Tomahawk Resolvers Developer Documentation

## Developing resolvers

The Tomahawk resolver API is currently still in flux. It is probably a good idea to use the existing resolvers as example.

The API you should develop against is defined in [`tomahawk.js`](https://github.com/tomahawk-player/tomahawk/blob/master/data/js/tomahawk.js) and [`QtScriptResolverHelper`](https://github.com/tomahawk-player/tomahawk/blob/master/src/libtomahawk/resolvers/QtScriptResolver.h) in the Tomahawk main repo.

If you have questions, look for us in #tomahawk on irc.freenode.net.

### Licensing

Tomahawk resolvers are considered derivative works of Tomahawk, specifically through the previously mentioned `tomahawk.js` and `QtScriptResolver.h` files. These files are released under a GNU General Public License, version 3 or later.

Thus, developers who release a resolver are expected to
* release the resolver code they produce under a license compatible with Tomahawk, and specifically with Tomahawk's resolver interface, and
* add a copyright and licensing statement at the beginning of those resolver file(s) that interface with Tomahawk, with a wording that makes their licensing (and compatibility) clear.

Exceptions to this requirement can be evaluated upon request by the Tomahawk team.

## Packaging resolvers

### Structure overview

Starting with Tomahawk 0.7, all resolver directories must be structured as follows.

Mandatory:
```
content/
+ metadata.json
```
Suggested:
```
content/
+ metadata.json
+ contents/
+ code/
+ <resolver script>.js
+ config.ui
+ <everything else>
+ images/
+ icon.png
```

This structure is commonly referred to as a resolver bundle, i.e. a resolver script with all related files and metadata.

A bundle can be packaged or unpackaged (i.e. as it is in this repo), thus resolvers can be installed manually in two ways:
* from an unpackaged bundle,
* from a package (or axe).

### Installing a resolver bundle

To install a resolver from an unpackaged bundle (the preferred way for testing and development), in Tomahawk's Settings dialog click on "Install from file" and select the resolver's main .js file.

Keep in mind that with such a path, Tomahawk expects to find the file `metadata.json` in `../..` from the main script's path. If `metadata.json` is not found, it is likely that your resolver directory is not structured properly. The resolver's main script will still be loaded, but any additional scripts will not and the accounts list in the Settings dialog will not show any metadata for the resolver (e.g. author, version, etc.). This is a **bad thing**. The only reason why a resolver without `metadata.json` is still loaded is backward compatibility. Plain unbundled .js files as resolvers are deprecated. You should update your resolver to a proper bundle structure as soon as possible.

A packaged resolver bundle is a file with file extension `axe`. It is a compressed archive with all the contents of a resolver directory. To install such a bundle (the preferred way for end users who wish to install a resolver manually), in Tomahawk's Settings dialog click on "Install from file" and select the package file (`<something>.axe`).

**WARNING** for developers and testers: the installation process for an *unpackaged* bundle loads the resolver in-place. This means that any changed to the resolver script are applied immediately, simply by disabling and re-enabling the "installed" resolver with the account's checkbox in the accounts list. There is usually no need to remove and re-install the resolver. This also means that changes to the directory structure may make the resolver stop functioning. On the other hand, packaged bundles (axes) are decompressed and copied to a Tomahawk-managed directory (`<local user data dir>/manualresolvers`) during the installation process, so any change to the axe can only be applied by re-installing.

### Packaging

#### metadata.json

Every resolver bundle directory must contain a metadata file. This file must be named `metadata.json`, and it must be located in the directory `content` relative to the top-level resolver bundle directory.

For example, this is a `metadata.json` file for Subsonic:
```
{
"name": "Subsonic",
"pluginName": "subsonic",
"author": "mack_t and Teo",
"email": "teo@kde.org",
"version": "0.5",
"website": "http://gettomahawk.com",
"description": "Searches your Subsonic server for music to play",
"type": "resolver/javascript",
"manifest": {
"main": "contents/code/subsonic.js",
"scripts": [],
"icon": "contents/images/icon.png",
"resources": [
"contents/code/config.ui",
"contents/code/runnersid-icon.png",
"contents/code/subsonic-icon.png",
"contents/code/subsonic.png"
]
}
}
```

For most purposes all the fields are mandatory.

**WARNING**: the manifest object **must** list all the files required by the resolver. Unlisted scripts will not be loaded, and any unlisted files will not be packaged.

#### makeaxe.rb

If your resolver directory conforms to the previously described structure and your `metadata.json` is complete, the harder part is done. The Tomahawk team provides you with a script to automate the packaging process: [`makeaxe.rb`](admin/makeaxe.rb). You will need [ruby](http://www.ruby-lang.org/en/) 1.9.2 or later and the [zip](https://rubygems.org/gems/zip) gem.

To create a package from a resolver directory, simply run `makeaxe.rb` with the directory path passed as parameter.

E.g. on Linux and Mac OS X, for Subsonic and from the repository root, you would do the following:
```
% ruby admin/makeaxe.rb subsonic
% ls subsonic
content/ subsonic-0.5.axe subsonic-0.5.md5
```
In this case, `subsonic-0.5.axe` is the compressed bundle and `subsonic-0.5.md5` is the MD5 checksum file.

Please note that `makeaxe.rb` does not simply compress the contents of the directory, it also checks the metadata file and adds additional data, including a packaging timestamp and the revision hash, if any.

Optionally, if you pass the `--release` parameter to `makeaxe.rb` it will not include the commit hash in the axe, as would be expected in a release-worthy package.

Happy packaging!
3 changes: 0 additions & 3 deletions README

This file was deleted.

13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Tomahawk Resolvers

Supported resolvers are distributed and updated automatically through Tomahawk's Settings dialog.
To manually intstall a resolver: either
* clone this repo,
* download the .zip, or
* download all the files within the individual resolver folder you are installing.

After you have the files locally, open Tomahawk's preferences and from the "Services" tab click "Install from File" and select the .axe or .js file for the resolver you are installing.

Since March 2013 Tomahawk resolvers have switched to a new directory structure for easy packaging. Ideally, you should download nightly .axe files, if available.

For developer documentation, see [HACKING.md](HACKING.md).
105 changes: 105 additions & 0 deletions admin/json2desktop.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/usr/bin/env ruby
# === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
#
# Copyright 2013, Teo Mrnjavac <teo@kde.org>
#
# Tomahawk 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 3 of the License, or
# (at your option) any later version.
#
# Tomahawk 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 Tomahawk. If not, see <http://www.gnu.org/licenses/>.


#
# This script converts a json metadata/manifest file into a desktop file for Synchrotron.
#

require 'json'

if ARGV.length < 1
puts "This script converts a Tomahawk resolver's metadata/manifest JSON file"
puts "into a desktop file for Synchrotron."
puts "Usage: ruby json2desktop.rb path_to_metadata_file.json"
exit
end

inputPath = File.absolute_path( ARGV[0] )
outputPath = File.join( File.dirname( inputPath ), "metadata.desktop" )

if not File.exists?( inputPath ) or not File.readable?( inputPath )
puts "Cannot read input file."
exit
end

if File.exists?( outputPath ) and not File.writable?( outputPath )
puts "Cannot write to output file."
exit
end

inputFile = File.open( inputPath, 'r' )
inputString = inputFile.read
input = JSON.parse( inputString )
inputFile.close unless inputFile == nil

# check if outputPath exists, maybe save stuff and/or overwrite, yes?
File.open( outputPath, 'w' ) do |f|
f.write "\
############################################################################
## Desktop file generated from JSON file '#{File.basename( inputPath )}'
##
## Created: #{Time.now.utc.to_s}
## by: json2desktop.rb, https://github.com/tomahawk-player
##
## #### WARNING! ####
## All changes made to this file will be lost!
############################################################################

[Desktop Entry]\n"

unless input["name"].nil? || input["name"].empty?
f.write "Name=#{input["name"]}\n"
end

unless input["description"].nil? || input["description"].empty?
f.write "Comment=#{input["description"]}\n"
end

f.write "\nType=Service\nX-KDE-ServiceTypes=Tomahawk/Resolver\n"

unless input["manifest"].nil?
unless input["manifest"]["main"].nil? || input["manifest"]["main"].empty?
f.write "X-Synchrotron-MainScript=#{input["manifest"]["main"]}\n"
end
end

f.write "\n"

unless input["pluginName"].nil? || input["pluginName"].empty?
f.write "X-KDE-PluginInfo-Name=#{input["pluginName"]}\n"
end

f.write "X-KDE-PluginInfo-Category=Resolver\n"

unless input["author"].nil? || input["author"].empty?
f.write "X-KDE-PluginInfo-Author=#{input["author"]}\n"
end

unless input["email"].nil? || input["email"].empty?
f.write "X-KDE-PluginInfo-Email=#{input["email"]}\n"
end

unless input["version"].nil? || input["version"].empty?
f.write "X-KDE-PluginInfo-Version=#{input["version"]}\n"
end

unless input["website"].nil? || input["website"].empty?
f.write "X-KDE-PluginInfo-Website=#{input["website"]}\n"
end
end
Loading