Skip to content
Snippets Groups Projects
Commit 98d6d2c1 authored by Ciaran Ainsworth's avatar Ciaran Ainsworth
Browse files

Started to implement in other bases

parent b66a3500
No related branches found
No related tags found
No related merge requests found
...@@ -54,7 +54,11 @@ ...@@ -54,7 +54,11 @@
<i class="code icon"></i> <i class="code icon"></i>
<translate translate-context="Content/*/Button.Label/Verb">Embed</translate> <translate translate-context="Content/*/Button.Label/Verb">Embed</translate>
</div> </div>
<a :href="wikipediaUrl" target="_blank" rel="noreferrer noopener" class="basic item"> <a v-if="wikipediaUrl" :href="wikipediaUrl" target="_blank" rel="noreferrer noopener" class="basic item">
<i class="wikipedia w icon"></i>
<translate translate-context="Content/*/Button.Label/Verb">View on Wikipedia</translate>
</a>
<a v-else :href="wikipediaSearchUrl" target="_blank" rel="noreferrer noopener" class="basic item">
<i class="wikipedia w icon"></i> <i class="wikipedia w icon"></i>
<translate translate-context="Content/*/Button.Label/Verb">Search on Wikipedia</translate> <translate translate-context="Content/*/Button.Label/Verb">Search on Wikipedia</translate>
</a> </a>
...@@ -62,7 +66,11 @@ ...@@ -62,7 +66,11 @@
<i class="external icon"></i> <i class="external icon"></i>
<translate translate-context="Content/*/*/Clickable, Verb">View on MusicBrainz</translate> <translate translate-context="Content/*/*/Clickable, Verb">View on MusicBrainz</translate>
</a> </a>
<a :href="discogsUrl" target="_blank" rel="noreferrer noopener" class="basic item"> <a v-if="discogsUrl" :href="discogsUrl" target="_blank" rel="noreferrer noopener" class="basic item">
<i class="external icon"></i>
<translate translate-context="Content/*/Button.Label/Verb">View on Discogs</translate>
</a>
<a v-else :href="discogsSearchUrl" target="_blank" rel="noreferrer noopener" class="basic item">
<i class="external icon"></i> <i class="external icon"></i>
<translate translate-context="Content/*/Button.Label/Verb">Search on Discogs</translate> <translate translate-context="Content/*/Button.Label/Verb">Search on Discogs</translate>
</a> </a>
...@@ -145,7 +153,9 @@ export default { ...@@ -145,7 +153,9 @@ export default {
object: null, object: null,
discs: [], discs: [],
libraries: [], libraries: [],
showEmbedModal: false showEmbedModal: false,
wikipediaUrl: null,
discogsUrl: null
} }
}, },
created() { created() {
...@@ -161,10 +171,57 @@ export default { ...@@ -161,10 +171,57 @@ export default {
self.object = backend.Album.clean(response.data) self.object = backend.Album.clean(response.data)
self.discs = self.object.tracks.reduce(groupByDisc, []) self.discs = self.object.tracks.reduce(groupByDisc, [])
self.isLoading = false self.isLoading = false
self.fetchUrls()
})
},
fetchUrls () {
let self = this
this.discogsUrl = null
if (this.object.mbid) {
console.log('Getting URLS')
axios.get('https://musicbrainz.org/ws/2/release/' + this.object.mbid + '?inc=url-rels&fmt=json').then(response => {
response.data.relations.forEach(f => {
if (f.type == 'discogs') {
console.log('Found Discogs Link', f.url.resource)
return this.discogsUrl = f.url.resource
} if (f.type == 'wikidata') {
let foundUrl = f.url.resource
console.log('Found Wikidata Link')
console.log('Pasing', foundUrl, 'to getWiki')
this.getWiki(foundUrl)
}
}).catch(error => {
console.log("Couldn't reach Musicbrainz", error)
})
}) })
} }
}, },
getWiki (url) {
let self = this
this.wikipediaUrl = null
let split = url.split('/')
let id = split[split.length - 1];
let getUrl = 'https://www.wikidata.org/w/api.php?action=wbgetentities&ids=' + id + '&props=sitelinks&sitefilter=' + this.shortLocale + 'wiki&format=json&origin=*'
console.log('Fetching Wikipedia Link for', id)
$.get(getUrl).done(function (data) {
$.each(data.entities, function (index, item) {
let wikilang = self.shortLocale + 'wiki'
if (item.sitelinks[wikilang]) {
console.log('Wikipedia language is', wikilang)
let wikiUrl = 'https://' + self.shortLocale + '.wikipedia.org/wiki/' + encodeURI(item.sitelinks[wikilang].title)
console.log('Wikipedia page found at', wikiUrl)
return self.wikipediaUrl = wikiUrl}
else {
console.log('No wiki entries for this language')
}
})
})
},
},
computed: { computed: {
shortLocale() {
return this.$store.state.ui.momentLocale.split('-')[0]
},
labels() { labels() {
return { return {
title: this.$pgettext('*/*/*', 'Album') title: this.$pgettext('*/*/*', 'Album')
...@@ -175,9 +232,9 @@ export default { ...@@ -175,9 +232,9 @@ export default {
return l.privacy_level === 'everyone' return l.privacy_level === 'everyone'
}) })
}, },
wikipediaUrl() { wikipediaSearchUrl() {
return ( return (
"https://en.wikipedia.org/w/index.php?search=" + "https://" + this.shortLocale + ".wikipedia.org/w/index.php?search=" +
encodeURI(this.object.title + " " + this.object.artist.name) encodeURI(this.object.title + " " + this.object.artist.name)
) )
}, },
...@@ -186,7 +243,7 @@ export default { ...@@ -186,7 +243,7 @@ export default {
return "https://musicbrainz.org/release/" + this.object.mbid return "https://musicbrainz.org/release/" + this.object.mbid
} }
}, },
discogsUrl() { discogsSearchUrl() {
return ( return (
"https://discogs.com/search/?type=release&title=" + "https://discogs.com/search/?type=release&title=" +
encodeURI(this.object.title) + "&artist=" + encodeURI(this.object.title) + "&artist=" +
......
...@@ -176,7 +176,7 @@ export default { ...@@ -176,7 +176,7 @@ export default {
}, },
async created() { async created() {
await this.fetchData(), await this.fetchData(),
await this.fetchUrls() this.fetchUrls()
}, },
methods: { methods: {
async fetchData() { async fetchData() {
...@@ -209,7 +209,7 @@ export default { ...@@ -209,7 +209,7 @@ export default {
self.isLoadingAlbums = false self.isLoadingAlbums = false
self.isLoading = false self.isLoading = false
}, },
async fetchUrls () { fetchUrls () {
let self = this let self = this
this.discogsUrl = null this.discogsUrl = null
if (this.object.mbid) { if (this.object.mbid) {
...@@ -225,6 +225,8 @@ export default { ...@@ -225,6 +225,8 @@ export default {
console.log('Pasing', foundUrl, 'to getWiki') console.log('Pasing', foundUrl, 'to getWiki')
this.getWiki(foundUrl) this.getWiki(foundUrl)
} }
}).catch(error => {
console.log("Couldn't reach Musicbrainz", error)
}) })
}) })
} }
...@@ -245,7 +247,7 @@ export default { ...@@ -245,7 +247,7 @@ export default {
console.log('Wikipedia page found at', wikiUrl) console.log('Wikipedia page found at', wikiUrl)
return self.wikipediaUrl = wikiUrl} return self.wikipediaUrl = wikiUrl}
else { else {
console.log('No wiki entries for this language :(') console.log('No wiki entries for this language')
} }
}) })
}) })
......
...@@ -70,7 +70,11 @@ ...@@ -70,7 +70,11 @@
<i class="code icon"></i> <i class="code icon"></i>
<translate translate-context="Content/*/Button.Label/Verb">Embed</translate> <translate translate-context="Content/*/Button.Label/Verb">Embed</translate>
</div> </div>
<a :href="wikipediaUrl" target="_blank" rel="noreferrer noopener" class="basic item"> <a v-if="wikipediaUrl" :href="wikipediaUrl" target="_blank" rel="noreferrer noopener" class="basic item">
<i class="wikipedia w icon"></i>
<translate translate-context="Content/*/Button.Label/Verb">Search on Wikipedia</translate>
</a>
<a v-else :href="wikipediaSearchUrl" target="_blank" rel="noreferrer noopener" class="basic item">
<i class="wikipedia w icon"></i> <i class="wikipedia w icon"></i>
<translate translate-context="Content/*/Button.Label/Verb">Search on Wikipedia</translate> <translate translate-context="Content/*/Button.Label/Verb">Search on Wikipedia</translate>
</a> </a>
...@@ -78,7 +82,11 @@ ...@@ -78,7 +82,11 @@
<i class="external icon"></i> <i class="external icon"></i>
<translate translate-context="Content/*/*/Clickable, Verb">View on MusicBrainz</translate> <translate translate-context="Content/*/*/Clickable, Verb">View on MusicBrainz</translate>
</a> </a>
<a :href="discogsUrl" target="_blank" rel="noreferrer noopener" class="basic item"> <a v-if="discogsUrl" :href="discogsUrl" target="_blank" rel="noreferrer noopener" class="basic item">
<i class="external icon"></i>
<translate translate-context="Content/*/Button.Label/Verb">Search on Discogs</translate>
</a>
<a v-else :href="discogsSearchUrl" target="_blank" rel="noreferrer noopener" class="basic item">
<i class="external icon"></i> <i class="external icon"></i>
<translate translate-context="Content/*/Button.Label/Verb">Search on Discogs</translate> <translate translate-context="Content/*/Button.Label/Verb">Search on Discogs</translate>
</a> </a>
...@@ -154,14 +162,16 @@ export default { ...@@ -154,14 +162,16 @@ export default {
isLoadingTrack: true, isLoadingTrack: true,
track: null, track: null,
showEmbedModal: false, showEmbedModal: false,
libraries: [] libraries: [],
wikipediaUrl: null,
discogsUrl: null
} }
}, },
created() { async created() {
this.fetchData() await this.fetchData()
}, },
methods: { methods: {
fetchData() { async fetchData() {
var self = this var self = this
this.isLoadingTrack = true this.isLoadingTrack = true
let url = FETCH_URL + this.id + "/" let url = FETCH_URL + this.id + "/"
...@@ -169,10 +179,59 @@ export default { ...@@ -169,10 +179,59 @@ export default {
axios.get(url, {params: {refresh: 'true'}}).then(response => { axios.get(url, {params: {refresh: 'true'}}).then(response => {
self.track = response.data self.track = response.data
self.isLoadingTrack = false self.isLoadingTrack = false
self.fetchUrls()
})
},
fetchUrls () {
let self = this
this.discogsUrl = null
if (this.track.mbid) {
console.log('Getting URLS')
axios.get('https://musicbrainz.org/ws/2/recording/' + this.track.mbid + '?inc=url-rels&fmt=json').then(response => {
response.data.relations.forEach(f => {
if (f.type == 'discogs') {
console.log('Found Discogs Link', f.url.resource)
return this.discogsUrl = f.url.resource
} if (f.type == 'wikidata') {
let foundUrl = f.url.resource
console.log('Found Wikidata Link')
console.log('Pasing', foundUrl, 'to getWiki')
this.getWiki(foundUrl)
} else {
console.log('Nothing found')
}
}).catch(error => {
console.log("Couldn't reach Musicbrainz", error)
})
})
}
},
getWiki (url) {
let self = this
this.wikipediaUrl = null
let split = url.split('/')
let id = split[split.length - 1];
let getUrl = 'https://www.wikidata.org/w/api.php?action=wbgetentities&ids=' + id + '&props=sitelinks&sitefilter=' + this.shortLocale + 'wiki&format=json&origin=*'
console.log('Fetching Wikipedia Link for', id)
$.get(getUrl).done(function (data) {
$.each(data.entities, function (index, item) {
let wikilang = self.shortLocale + 'wiki'
if (item.sitelinks[wikilang]) {
console.log('Wikipedia language is', wikilang)
let wikiUrl = 'https://' + self.shortLocale + '.wikipedia.org/wiki/' + encodeURI(item.sitelinks[wikilang].title)
console.log('Wikipedia page found at', wikiUrl)
return self.wikipediaUrl = wikiUrl}
else {
console.log('No wiki entries for this language')
}
})
}) })
}, },
}, },
computed: { computed: {
shortLocale() {
return this.$store.state.ui.momentLocale.split('-')[0]
},
publicLibraries () { publicLibraries () {
return this.libraries.filter(l => { return this.libraries.filter(l => {
return l.privacy_level === 'everyone' return l.privacy_level === 'everyone'
...@@ -188,9 +247,9 @@ export default { ...@@ -188,9 +247,9 @@ export default {
title: this.$pgettext('*/*/*/Noun', "Track") title: this.$pgettext('*/*/*/Noun', "Track")
} }
}, },
wikipediaUrl() { wikipediaSearchUrl() {
return ( return (
"https://en.wikipedia.org/w/index.php?search=" + "https://" + this.shortLocale + ".wikipedia.org/w/index.php?search=" +
encodeURI(this.track.title + " " + this.track.artist.name) encodeURI(this.track.title + " " + this.track.artist.name)
) )
}, },
...@@ -199,7 +258,7 @@ export default { ...@@ -199,7 +258,7 @@ export default {
return "https://musicbrainz.org/recording/" + this.track.mbid return "https://musicbrainz.org/recording/" + this.track.mbid
} }
}, },
discogsUrl() { discogsSearchUrl() {
return ( return (
"https://discogs.com/search/?type=release&title=" + "https://discogs.com/search/?type=release&title=" +
encodeURI(this.track.album.title) + "&artist=" + encodeURI(this.track.album.title) + "&artist=" +
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment