Skip to content

Commit cc46893

Browse files
committed
Initial Checkin
0 parents  commit cc46893

16 files changed

+4149
-0
lines changed

YMC/Virus/HttpClient.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: pascal
5+
* Date: 12.09.14
6+
* Time: 11:47
7+
*/
8+
9+
namespace YMC\Virus;
10+
11+
12+
class HttpClient {
13+
14+
public function getSslPage($url) {
15+
16+
17+
$ch = curl_init();
18+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
19+
curl_setopt($ch, CURLOPT_HEADER, false);
20+
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
21+
curl_setopt($ch, CURLOPT_URL, $url);
22+
curl_setopt($ch, CURLOPT_REFERER, $url);
23+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
24+
$result = curl_exec($ch);
25+
curl_close($ch);
26+
return $result;
27+
}
28+
29+
}

YMC/Virus/Lyrics.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: pascal
5+
* Date: 12.09.14
6+
* Time: 11:52
7+
*/
8+
9+
namespace YMC\Virus;
10+
11+
12+
class Lyrics implements RemoteContent {
13+
14+
private $client;
15+
private $song;
16+
17+
public function __construct(HttpClient $client, Song $song)
18+
{
19+
$this->client = $client;
20+
$this->song = $song;
21+
}
22+
23+
public function setSong(Song $song)
24+
{
25+
$this->song = $song;
26+
}
27+
28+
public function getName()
29+
{
30+
return "lyrics";
31+
}
32+
public function getMetadata()
33+
{
34+
return $this->getLyrics();
35+
}
36+
private function getLyrics()
37+
{
38+
$apiString = $this->client->getSslPage("http://lyrics.wikia.com/api.php?artist=".urlencode(strtolower($this->song->getArtist()))."&song=".urlencode(strtolower($this->song->getTitle()))."&fmt=xml");
39+
$xml = simplexml_load_string($apiString);
40+
$lyrics = (string) $xml->lyrics;
41+
if ($lyrics == 'Not found') {
42+
$lyrics = false;
43+
} else {
44+
$lyrics = nl2br($lyrics);
45+
}
46+
return $lyrics;
47+
48+
}
49+
50+
51+
}

YMC/Virus/RemoteContent.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: pascal
5+
* Date: 12.09.14
6+
* Time: 11:52
7+
*/
8+
9+
namespace YMC\Virus;
10+
11+
12+
interface RemoteContent {
13+
14+
public function __construct(HttpClient $client, Song $song);
15+
public function setSong(Song $song);
16+
public function getMetadata();
17+
public function getName();
18+
}

YMC/Virus/Song.php

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
namespace YMC\Virus;
3+
4+
include_once("HttpClient.php");
5+
include_once("RemoteContent.php");
6+
include_once("Spotify.php");
7+
include_once("Youtube.php");
8+
include_once("Lyrics.php");
9+
10+
11+
12+
class Song {
13+
14+
private $title;
15+
16+
private $artist;
17+
18+
private $id;
19+
20+
/**
21+
* @var RemoteContent[]
22+
*/
23+
private $collectors;
24+
25+
public function __construct()
26+
{
27+
$this->collectors[] = new Spotify(new HttpClient(), $this);
28+
$this->collectors[] = new Youtube(new HttpClient(), $this);
29+
$this->collectors[] = new Lyrics(new HttpClient(), $this);
30+
}
31+
32+
public function isValid()
33+
{
34+
if ($this->title != '') {
35+
return true;
36+
}
37+
return false;
38+
}
39+
40+
public function getMetadata()
41+
{
42+
$metadata = [
43+
'title' => $this->title,
44+
'artist' => $this->artist,
45+
];
46+
foreach ($this->collectors as $collector) {
47+
$metadata[$collector->getName()] = $collector->getMetadata();
48+
}
49+
return $metadata;
50+
}
51+
52+
/**
53+
* @return mixed
54+
*/
55+
public function getArtist()
56+
{
57+
return $this->artist;
58+
}
59+
60+
/**
61+
* @param mixed $artist
62+
*/
63+
public function setArtist($artist)
64+
{
65+
$this->artist = $artist;
66+
}
67+
68+
/**
69+
* @return mixed
70+
*/
71+
public function getId()
72+
{
73+
return $this->id;
74+
}
75+
76+
/**
77+
* @param mixed $id
78+
*/
79+
public function setId($id)
80+
{
81+
$this->id = $id;
82+
}
83+
84+
/**
85+
* @return mixed
86+
*/
87+
public function getTitle()
88+
{
89+
return $this->title;
90+
}
91+
92+
/**
93+
* @param mixed $title
94+
*/
95+
public function setTitle($title)
96+
{
97+
$this->title = $title;
98+
}
99+
100+
101+
}

YMC/Virus/Spotify.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: pascal
5+
* Date: 12.09.14
6+
* Time: 11:52
7+
*/
8+
9+
namespace YMC\Virus;
10+
11+
12+
class Spotify implements RemoteContent {
13+
14+
private $client;
15+
private $song;
16+
17+
public function __construct(HttpClient $client, Song $song)
18+
{
19+
$this->client = $client;
20+
$this->song = $song;
21+
}
22+
23+
public function setSong(Song $song)
24+
{
25+
$this->song = $song;
26+
}
27+
28+
public function getName()
29+
{
30+
return "spotify";
31+
}
32+
public function getMetadata()
33+
{
34+
return $this->getSpotifyData();
35+
}
36+
private function getSpotifyData()
37+
{
38+
$apiString = $this->client->getSslPage("https://api.spotify.com/v1/search?q=".$this->getSearchString().'&type=track');
39+
$rawData = json_decode($apiString, true);
40+
41+
return $rawData['tracks']['items'][0];
42+
43+
}
44+
private function getSearchString()
45+
{
46+
return urlencode('artist:'.$this->song->getArtist().' track:'.$this->song->getTitle());
47+
}
48+
49+
50+
}

YMC/Virus/Youtube.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: pascal
5+
* Date: 12.09.14
6+
* Time: 11:52
7+
*/
8+
9+
namespace YMC\Virus;
10+
11+
12+
class Youtube implements RemoteContent {
13+
14+
private $client;
15+
private $song;
16+
17+
public function __construct(HttpClient $client, Song $song)
18+
{
19+
$this->client = $client;
20+
$this->song = $song;
21+
}
22+
23+
public function setSong(Song $song)
24+
{
25+
$this->song = $song;
26+
}
27+
28+
public function getName()
29+
{
30+
return "youtube";
31+
}
32+
public function getMetadata()
33+
{
34+
return $this->getYoutubeData();
35+
}
36+
private function getYoutubeData()
37+
{
38+
$apiString = $this->client->getSslPage("https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&videoDefinition=high&videoEmbeddable=true&key=AIzaSyAajCr-83tFsM2_pM3v9rpcRCoF8L6vacs&q=".$this->getSearchString());
39+
$rawData = json_decode($apiString, true);
40+
return $rawData['items'][0];
41+
42+
}
43+
private function getSearchString()
44+
{
45+
return urlencode($this->song->getArtist().' '.$this->song->getTitle());
46+
}
47+
48+
49+
}

ajax.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
include_once("YMC/Virus/Song.php");
3+
4+
list($artist, $title) = explode(' - ', $_POST['songdata']);
5+
6+
header('Content-Type: Application/json');
7+
$song = new \YMC\Virus\Song();
8+
$song->setTitle($title);
9+
$song->setArtist($artist);
10+
if ($song->isValid()) {
11+
echo json_encode(
12+
$song->getMetadata()
13+
);
14+
}

atlassian-ide-plugin.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<atlassian-ide-plugin>
2+
<project-configuration id="1">
3+
<servers id="2" />
4+
</project-configuration>
5+
</atlassian-ide-plugin>

css/chartist.css

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)