combine.fm/lib/services/google/url.js

30 lines
591 B
JavaScript
Raw Normal View History

2015-08-20 23:22:57 +01:00
import { parse } from 'url';
2015-08-20 23:22:57 +01:00
export function* match(url) {
var parsed = parse(url.replace(/\+/g, "%20"));
if (!parsed.host.match(/play\.google\.com$/)) {
return false;
}
2015-08-20 23:22:57 +01:00
const path = parsed.path;
const hash = parsed.hash;
if (hash) {
2015-08-20 23:22:57 +01:00
const parts = hash.split("/");
const id = parts[2];
const artist = parts[3];
if (id.length > 0) {
return true;
} else if (artist.length > 0) {
return true;
}
} else if(path) {
2015-08-20 23:22:57 +01:00
const matches = path.match(/\/music\/m\/([\w]+)/);
if (matches[1]) {
return true
}
}
return false
};