Skip to content

Commit

Permalink
fix merge issues
Browse files Browse the repository at this point in the history
  • Loading branch information
buszk committed Oct 6, 2017
2 parents 9a2d2f6 + a3987d4 commit 142378d
Show file tree
Hide file tree
Showing 15 changed files with 4,446 additions and 77 deletions.
46 changes: 46 additions & 0 deletions CODE_OF_CONDUCT.md
@@ -0,0 +1,46 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [https://github.com/emilioastarita/lyricfier/issues/new]. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -16,15 +16,15 @@ git clone https://github.com/emilioastarita/lyricfier.git
# change dir
cd lyricfier
# take some coffee and download all the internet with npm
npm install
# take some coffee and download all the internet with yarn
yarn install
```

## Run dev

```
npm start
yarn start
```


Expand Down
27 changes: 18 additions & 9 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "lyricfier",
"version": "0.2.5",
"version": "0.2.7",
"description": "Fetching lyrics for spotify desktop client",
"main": "main.js",
"scripts": {
Expand All @@ -10,10 +10,11 @@
"dist:linux32": "electron-zip-packager . --arch=ia32 --platform=linux --overwrite --prune --out=build/ --icon=render/img/icon.png",
"dist:win32": "electron-zip-packager . --arch=ia32 --platform=win32 --overwrite --prune --out=build/ --icon=render/img/icon.ico",
"dist:win64": "electron-zip-packager . --arch=x64 --platform=win32 --overwrite --prune --out=build/ --icon=render/img/icon.ico",
"dist:mac": "electron-zip-packager . --arch=x64 --platform=mas --overwrite --prune --out=build/ --icon=render/img/icon.icns",
"dist:mac": "electron-packager . --arch=x64 --platform=mas --overwrite --prune --out=build/ --icon=render/img/icon.icns && electron-installer-zip build/lyricfier-mas-x64/ build/lyricfier-mac-x64.zip",
"predist": "tsc",
"dist": "npm run dist:linux64 && npm run dist:linux32 && npm run dist:win32 && npm run dist:win64 && npm run dist:mac",
"pretest": "tsc test/*Test.ts --module commonjs && tsc",
"postinstall": "electron-builder install-app-deps",
"test": "mocha"
},
"repository": {
Expand All @@ -33,7 +34,7 @@
},
"homepage": "https://github.com/emilioastarita/lyrics-spotify#readme",
"dependencies": {
"async": "^2.0.1",
"async": "^2.5.0",
"cheerio": "^0.20.0",
"electron-json-storage": "^2.0.0",
"he": "^1.1.0",
Expand All @@ -44,19 +45,27 @@
"vue-class-component": "^3.2.0"
},
"devDependencies": {
"@types/electron": "1.3.20",
"@types/electron-json-storage": "latest",
"@types/mocha": "latest",
"@types/node": "4.0.30",
"electron-builder": "^6.4.0",
"electron-packager": "^7.7.0",
"electron-prebuilt": "^1.4.10",
"electron-zip-packager": "^3.0.0",
"electron": "1.7.8",
"electron-builder": "^19.34.1",
"electron-installer-zip": "^0.1.2",
"electron-packager": "^9.1.0",
"electron-zip-packager": "^4.0.2",
"gulp": "^3.9.1",
"gulp-less": "^3.1.0",
"gulp-livereload": "^3.8.1",
"less": "^2.7.1",
"mocha": "^3.2.0",
"typescript": "^2.1.0"
"typescript": "^2.5.3"
},
"build": {
"appId": "lyricfier.cloudymedia.com",
"productName": "Lyricfier",
"asar": true,
"directories": {
"output": "build"
}
}
}
2 changes: 0 additions & 2 deletions render/LyricfierRender.ts
@@ -1,5 +1,3 @@
/// <reference path="./render-typings.d.ts" />

import Component from 'vue-class-component';
import {ipcRenderer, shell} from 'electron';
import {SettingsRender} from './SettingsRender';
Expand Down
35 changes: 21 additions & 14 deletions render/Searcher.ts
Expand Up @@ -23,28 +23,35 @@ export class Searcher {
}

loadPlugins() {
this.plugins = plugins.map((Plugin) => {
return new Plugin(request);
});
this.plugins = plugins.map(Plugin => new Plugin(request));
}

search(title:string, artist:string, cb : (error : any, result : Result) => void) {
const from = { lyric: null, sourceName: '', sourceUrl: ''};
const normalizedTitle = this.normalizer.normalize(title);
// run plugins on series
// if some returns success getting a lyric
// stop and save the lyric result
async.detectSeries(this.plugins, (plugin : SearchLyrics, callback) => {
plugin.search(normalizedTitle, artist, (err, result) => {
if (!err) {

const tasks = this.plugins.map((plugin : SearchLyrics) => {
return (callback) => {
console.log('Searching with', plugin, 'normalizedTitle', normalizedTitle, 'artist', artist);
plugin.search(normalizedTitle, artist, (err, result) => {
console.warn('Result with', plugin, 'normalizedTitle', normalizedTitle, 'artist', artist, 'err', err, 'result', result);
if (err) {
return callback(err);
}
from.lyric = result.lyric;
from.sourceName = plugin.name;
from.sourceUrl = result.url;
}
callback(null, from)
})
}, (err) => {
cb(err, from);
callback(null, from);
})
}
});
async.parallel(async.reflectAll(tasks), (err, results) => {
const result = results.find(x => !x.error);
if (result) {
cb(null, result.value);
} else {
cb(err, null);
}
});
}
}
25 changes: 9 additions & 16 deletions render/SongRender.ts
Expand Up @@ -33,22 +33,20 @@ export class SongRender {
return {
song: null,
lastSongSync: {},
searcher: new Searcher(),
}
}

beforeCompile() {
this.searcher = new Searcher();
}



scheduleNextCall() {
if (this.timer) {
clearTimeout(this.timer);
}
console.warn(
'Scheduling ',
this.settings.refreshInterval / 1000,
' seconds'
);
this.timer = setTimeout(() => {
this.refresh();
}, this.settings.refreshInterval);
this.timer = setTimeout(this.refresh.bind(this), this.settings.refreshInterval);
}

ready() {
Expand All @@ -57,7 +55,6 @@ export class SongRender {

refresh() {
this.resizeOnLyricsHide();
console.log('refreshing');
this.getSpotify().getCurrentSong((err, song) => {
if (err) {
this.showError('Current song error: ' + err);
Expand All @@ -78,7 +75,7 @@ export class SongRender {
this.showError('Plugin error: ' + err);
return;
}
if (result.lyric === null) {
if (!result || result.lyric === null) {
song.lyric = 'Sorry, couldn\'t find lyrics for this song!';
song.sourceUrl = null;
song.sourceName = null;
Expand Down Expand Up @@ -121,11 +118,7 @@ export class SongRender {
}

displaySong(song) {
const newSongObject = {};
for (let k of Object.keys(song)) {
newSongObject[k] = song[k];
}
this.song = newSongObject;
this.song = Object.assign({}, song);
}

isLastSong(song) {
Expand Down
40 changes: 19 additions & 21 deletions render/SpotifyService.ts
@@ -1,11 +1,13 @@
import {encodeData} from "./Utils";

const request = require('request').defaults({timeout: 5000});
const async = require('async');
const initialPortTest = 4370;

export class SpotifyService {
protected https = false;
protected foundPort = false;
protected port : number;
protected foundPort = false;
protected port: number;
protected portTries = 15;
protected albumImagesCache = {};

Expand All @@ -14,7 +16,7 @@ export class SpotifyService {
expires: null
};
protected csrfToken = null;
protected queue = [];



protected static headers() {
Expand All @@ -24,7 +26,7 @@ export class SpotifyService {
};
}

protected url(u:string) {
protected url(u: string) {
const protocol = this.https ? 'https' : 'http';
return `${protocol}://127.0.0.1:${this.port}${u}`;
}
Expand All @@ -34,7 +36,7 @@ export class SpotifyService {
return cb(null, this.oAuthToken.t);
}
request.get({
url:'https://open.spotify.com/token',
url: 'https://open.spotify.com/token',
rejectUnauthorized: false,
headers: SpotifyService.headers()
}, (err, status, body) => {
Expand All @@ -45,13 +47,13 @@ export class SpotifyService {
const json = JSON.parse(body);
this.oAuthToken.t = json.t;
return cb(null, json.t);
} catch(e) {
} catch (e) {
return cb(e);
}
});
}

public detectPort(cb : (err, port : number) => void) {
public detectPort(cb: (err, port: number) => void) {
if (!this.foundPort) {
this.port = initialPortTest;
}
Expand Down Expand Up @@ -96,7 +98,7 @@ export class SpotifyService {
}

public needsTokens(fn) {
this.detectPort( (err) => {
this.detectPort((err) => {
if (err) {
const failDetectPort = 'No port found! Is spotify running?';
console.error(failDetectPort, err);
Expand All @@ -118,7 +120,7 @@ export class SpotifyService {
'oauth': tokens.oauth,
'csrf': tokens.csrf,
};
const url = this.url('/remote/status.json') + '?' + this.encodeData(params);
const url = this.url('/remote/status.json') + '?' + encodeData(params);

request(url, {
headers: SpotifyService.headers(),
Expand All @@ -132,7 +134,7 @@ export class SpotifyService {
try {
const json = JSON.parse(body);
cb(null, json);
} catch(e) {
} catch (e) {
const msgParseFailed = 'Status response from spotify failed';
console.error(msgParseFailed, ' JSON body: ', body);
cb(msgParseFailed, null);
Expand All @@ -142,7 +144,7 @@ export class SpotifyService {
});
}

protected getAlbumImages(albumUri:string, cb) {
protected getAlbumImages(albumUri: string, cb) {
if (this.albumImagesCache[albumUri]) {
return cb(null, this.albumImagesCache[albumUri])
}
Expand All @@ -158,9 +160,9 @@ export class SpotifyService {
const parsed = JSON.parse(body);
finish(null, parsed.images);
this.albumImagesCache[albumUri] = parsed.images;
} catch(e) {
} catch (e) {
const msgParseFail = 'Failed to parse response from spotify api';
console.error(msgParseFail, 'URL USED: ',url);
console.error(msgParseFail, 'URL USED: ', url);
finish(msgParseFail, null);
}

Expand All @@ -170,15 +172,15 @@ export class SpotifyService {

}

public pause(pause:boolean, cb) {
public pause(pause: boolean, cb) {
this.needsTokens((err, tokens) => {
if (err) return cb(err);
const params = {
'oauth': tokens.oauth,
'csrf': tokens.csrf,
'pause': pause ? 'true' : 'false',
};
const url = this.url('/remote/pause.json') + '?' + this.encodeData(params);
const url = this.url('/remote/pause.json') + '?' + encodeData(params);
request(url, {
headers: SpotifyService.headers(),
'rejectUnauthorized': false,
Expand All @@ -194,13 +196,14 @@ export class SpotifyService {
}

public getCurrentSong(cb) {
this.getStatus((err, status)=> {
this.getStatus((err, status) => {
if (err) {
this.foundPort = false;
this.csrfToken = null;
this.oAuthToken.t = null;
return cb(err);
}

if (status.track && status.track.track_resource) {
const result = {
playing: status.playing,
Expand Down Expand Up @@ -230,10 +233,5 @@ export class SpotifyService {
});
}

protected encodeData(data) {
return Object.keys(data).map(function (key) {
return [key, data[key]].map(encodeURIComponent).join("=");
}).join("&");
}

}

0 comments on commit 142378d

Please sign in to comment.