Added geoLocation code

This commit is contained in:
Luca 2020-10-22 13:47:30 +02:00
parent d62e2ea036
commit bf2737b947
4 changed files with 47 additions and 6 deletions

8
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "freetube", "name": "freetube",
"version": "0.9.0", "version": "0.9.1",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -8552,7 +8552,7 @@
}, },
"humanize-plus": { "humanize-plus": {
"version": "1.8.2", "version": "1.8.2",
"resolved": "https://registry.npmjs.org/humanize-plus/-/humanize-plus-1.8.2.tgz", "resolved": "http://registry.npmjs.org/humanize-plus/-/humanize-plus-1.8.2.tgz",
"integrity": "sha1-pls0RZrWNnrbs3B6gqPJ+RYWcDA=", "integrity": "sha1-pls0RZrWNnrbs3B6gqPJ+RYWcDA=",
"dev": true "dev": true
}, },
@ -13899,7 +13899,7 @@
}, },
"safe-regex": { "safe-regex": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz", "resolved": "http://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz",
"integrity": "sha1-QKNmnzsHfR6UPURinhV91IAjvy4=", "integrity": "sha1-QKNmnzsHfR6UPURinhV91IAjvy4=",
"dev": true, "dev": true,
"requires": { "requires": {
@ -15070,7 +15070,7 @@
}, },
"strip-eof": { "strip-eof": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz", "resolved": "http://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz",
"integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=", "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=",
"dev": true "dev": true
}, },

View File

@ -1,5 +1,6 @@
import Vue from 'vue' import Vue from 'vue'
import $ from 'jquery' import $ from 'jquery'
import FS from 'fs'
import { mapActions } from 'vuex' import { mapActions } from 'vuex'
import FtCard from '../ft-card/ft-card.vue' import FtCard from '../ft-card/ft-card.vue'
import FtSelect from '../ft-select/ft-select.vue' import FtSelect from '../ft-select/ft-select.vue'
@ -24,6 +25,8 @@ export default Vue.extend({
instanceNames: [], instanceNames: [],
instanceValues: [], instanceValues: [],
currentLocale: '', currentLocale: '',
currentGeoLocation: '',
geoLocationArray: [],
backendValues: [ backendValues: [
'invidious', 'invidious',
'local' 'local'
@ -535,6 +538,9 @@ export default Vue.extend({
} }
}, },
computed: { computed: {
isDev: function () {
return process.env.NODE_ENV === 'development'
},
invidiousInstance: function () { invidiousInstance: function () {
return this.$store.getters.getInvidiousInstance return this.$store.getters.getInvidiousInstance
}, },
@ -584,6 +590,12 @@ export default Vue.extend({
return names return names
}, },
geoLocationOptions: function () {
return this.geoLocationArray.map((entry) => { return entry.code })
},
geoLocationNames: function () {
return this.geoLocationArray.map((entry) => { return entry.name })
},
backendNames: function () { backendNames: function () {
return [ return [
@ -639,6 +651,8 @@ export default Vue.extend({
this.updateInvidiousInstanceBounce = debounce(this.updateInvidiousInstance, 500) this.updateInvidiousInstanceBounce = debounce(this.updateInvidiousInstance, 500)
this.currentLocale = this.$i18n.locale this.currentLocale = this.$i18n.locale
this.currentGeoLocation = this.$i18n.geoLocation
this.updateGeoLocationNames(this.currentLocale)
}, },
beforeDestroy: function () { beforeDestroy: function () {
if (this.invidiousInstance === '') { if (this.invidiousInstance === '') {
@ -664,6 +678,26 @@ export default Vue.extend({
this.$i18n.locale = locale this.$i18n.locale = locale
this.currentLocale = locale this.currentLocale = locale
localStorage.setItem('locale', locale) localStorage.setItem('locale', locale)
this.updateGeoLocationNames(locale)
},
updateGeoLocation: function (location) {
this.$i18n.geoLocation = location
this.currentGeoLocation = location
localStorage.setItem('geoLocation', location)
},
updateGeoLocationNames: function (locale) {
let fileData
const fileLocation = this.isDev ? '.' : `${__dirname}`
if (FS.existsSync(`${fileLocation}/static/geolocations/${locale}`)) {
fileData = FS.readFileSync(`${fileLocation}/static/geolocations/${locale}/countries.json`)
} else {
fileData = FS.readFileSync(`${fileLocation}/static/geolocations/en-US/countries.json`)
}
const countries = JSON.parse(fileData).map((entry) => { return { id: entry.id, name: entry.name, code: entry.alpha2 } })
countries.sort((a, b) => { return a.id - b.id })
this.geoLocationArray = countries
}, },
...mapActions([ ...mapActions([

View File

@ -85,6 +85,13 @@
:select-values="localeOptions" :select-values="localeOptions"
@change="updateLocale" @change="updateLocale"
/> />
<ft-select
:placeholder="$t('Settings.General Settings.Region for Trending')"
:value="currentGeoLocation"
:select-names="geoLocationNames"
:select-values="geoLocationOptions"
@change="updateGeoLocation"
/>
</div> </div>
<ft-flex-box class="generalSettingsFlexBox"> <ft-flex-box class="generalSettingsFlexBox">
<ft-input <ft-input

View File

@ -65,8 +65,8 @@ export default Vue.extend({
this.isLoading = true this.isLoading = true
console.log('getting local trending') console.log('getting local trending')
console.log(localStorage.geoLocation)
ytrend.scrape_trending_page().then((result) => { ytrend.scrape_trending_page(localStorage.geoLocation.toUpperCase()).then((result) => {
const returnData = result.filter((item) => { const returnData = result.filter((item) => {
return item.type === 'video' || item.type === 'channel' || item.type === 'playlist' return item.type === 'video' || item.type === 'channel' || item.type === 'playlist'
}) })