Skip to content
This repository has been archived by the owner on May 3, 2019. It is now read-only.

Commit

Permalink
Anghami (#120)
Browse files Browse the repository at this point in the history
* Initial support for Anghami

* Add myself to AUTHORS

* Add song position, duration and id to Anghami

* Address Anghami integration script errors
  • Loading branch information
mahmoudhossam authored and ColinDuquesnoy committed Sep 22, 2017
1 parent 27b87d1 commit 151d948
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 1 deletion.
3 changes: 2 additions & 1 deletion AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ Contributors

- [ConorIA](https://github.com/ConorIA)
- [ZeroDot1](http://basic1.moy.su/)
- [Lukas Kolletzki](https://github.com/kolletzki)
- [Lukas Kolletzki](https://github.com/kolletzki)
- [Mahmoud Hossam](https://github.com/mahmoudhossam)
Binary file added plugins/anghami/anghami-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
122 changes: 122 additions & 0 deletions plugins/anghami/integration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
var playbackStatus = mellowplayer.PlaybackStatus.STOPPED;

function update() {
return {
"playbackStatus": playbackStatus,
"canSeek": false,
"canGoNext": true,
"canGoPrevious": true,
"canAddToFavorites": false,
"volume": 1,
"duration": getDuration(),
"position": getPosition(),
"songId": getSongId(),
"songTitle": getTitle(),
"artistName": getArtist(),
"albumTitle": '',
"artUrl": getAlbumArt(),
"isFavorite": false
};
}

function toSeconds(string) {
try {
var dtimes = string.split(":");
var dminutes = dtimes[0];
var dseconds = dtimes[1];
var duration = parseInt(dseconds, 10) + (parseInt(dminutes, 10) * 60);
} catch (e) {
var duration = 0;
}
return duration
}

function getHashCode(s) {
return s.split("").reduce(function(a, b) {
a = ((a << 5) - a) + b.charCodeAt(0);
return a & a
}, 0);
}

function getDuration() {
var remaining = $('#player .duration')[0];
var position = $('#player .position')[0];
if (remaining === undefined || position === undefined) {
return 0
}
return toSeconds(remaining.innerText.substr(2)) + toSeconds(position.innerText)
}

function getPosition() {
var position = $('#player .position')[0];
if (position === undefined) {
return 0
}
return toSeconds(position.innerText)
}

function getSongId() {
var title = getTitle();
if (title === undefined) {
return 0
}
return getHashCode(title);
}

function getAlbumArt() {
var albumArt = $('.cover-art img')[0];
if (albumArt === undefined) {
return ''
}
return albumArt.attributes.src.value
}

function getTitle() {
var title = $('#player .track-title a')[0];
if (title === undefined) {
return ''
}
return title.innerText
}

function getArtist() {
var artist = $('#player .track-artist')[0];
if (artist === undefined) {
return ''
}
return artist.innerText
}

function play() {
$('#player .icon-play').click();
playbackStatus = mellowplayer.PlaybackStatus.PLAYING;
}

function pause() {
$('#player .icon-pause-2').click();
playbackStatus = mellowplayer.PlaybackStatus.PAUSED;
}

function goNext() {
$('#player .icon-next-1').click();
}

function goPrevious() {
$('#player .icon-previous-1').click();
}

function setVolume(volume) {

}

function addToFavorites() {

}

function removeFromFavorites() {

}

function seekToPosition(position) {

}
7 changes: 7 additions & 0 deletions plugins/anghami/metadata.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
author=Mahmoud Hossam
author_website=http://mahmoudhossam.com
icon=anghami-logo.png
name=Anghami
require_proprietary_codecs=false
url=https://www.anghami.com/
version=1.0
9 changes: 9 additions & 0 deletions plugins/anghami/theme.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"accent": "#ffc107",
"background": "#ffffff",
"foreground": "#505050",
"primary": "#5f81d4",
"primaryForeground": "#ffffff",
"secondary": "#5f81d4",
"secondaryForeground": "#ffffff"
}

0 comments on commit 151d948

Please sign in to comment.