forked from CCHits/Website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass_RemoteSourcesAlonetone.php
More file actions
70 lines (70 loc) · 2.82 KB
/
Copy pathclass_RemoteSourcesAlonetone.php
File metadata and controls
70 lines (70 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
* CCHits.net is a website designed to promote Creative Commons Music,
* the artists who produce it and anyone or anywhere that plays it.
* These files are used to generate the site.
*
* PHP version 5
*
* @category Default
* @package MusicSources
* @author Jon Spriggs <jon@sprig.gs>
* @license http://www.gnu.org/licenses/agpl.html AGPLv3
* @link http://cchits.net Actual web service
* @link https://github.com/CCHits/Website/wiki Developers Web Site
* @link https://github.com/CCHits/Website Version Control Service
*/
/**
* This class scrapes appropriate data from alonetone.com
* Used http://alonetone.com/pasha/tracks/cross-the-line as scrapeable template
*
* @category Default
* @package MusicSources
* @author Jon Spriggs <jon@sprig.gs>
* @license http://www.gnu.org/licenses/agpl.html AGPLv3
* @link http://cchits.net Actual web service
* @link https://github.com/CCHits/Website/wiki Developers Web Site
* @link https://github.com/CCHits/Website Version Control Service
*/
class RemoteSourcesAlonetone extends RemoteSources
{
/**
* Get all the source data we can pull from the source.
*
* @param string $src Source URL for the retriever
*
* @return const A value explaining the outcome of the fetch request
*/
function __construct($src)
{
if (preg_match('/http[s]*:\/\/.*alonetone.com\/[^\/]+/tracks\/[^\/]+/', $src) == 0) {
return 406;
}
$file_contents = file_get_contents($src);
if ($file_contents == false or $file_contents == '') {
return 406;
}
$regex_strArtistName = '/<h1 class="user">([^<]*)<\/h1>/';
$regex_strTrackName = '/<a href="[^"]*" class="track_link" title="[^"]*">([^<]*)<\/a>/';
$regex_strArtistUrl = '/<a href="[^"]*" class="artist"/';
$regex_strFileUrl = '/<a href="([^"]*)" class="download button"/';
$regex_enumTrackLicense = '/licenses\/([^\/]*)\//';
$this->strTrackUrl = $src;
if (preg_match($regex_strArtistName, $file_contents, $arrArtistName) > 0) {
$this->set_strArtistName($arrArtistName[1]);
}
if (preg_match($regex_strTrackName, $file_contents, $arrTrackName) > 0) {
$this->set_strTrackName($arrTrackName[1]);
}
if (preg_match($regex_strArtistUrl, $src, $arrArtistUrl) > 0) {
$this->set_strArtistUrl('http://alonetone.com' . $arrArtistUrl[1]);
}
if (preg_match($regex_strFileUrl, $src, $arrFileUrl) > 0) {
$this->set_fileUrl('http://alonetone.com' . $arrFileUrl[1]);
}
if (preg_match($regex_enumTrackLicense, $file_contents, $arrTrackLicense) > 0) {
$this->set_enumTrackLicense(LicenseSelector::validateLicense($arrTrackLicense[1]));
}
return $this->create_pull_entry();
}
}