A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
1
import {state, SWIPE_THRESHOLD} from '../main.js';2
import {http, $lang, duration} from '../utils.js';2
import {http, $lang, $route, duration} from '../utils.js';3
import VButton from '../element/button.js';4
import VTab from '../component/tab.js';5
import VIcon from '../element/icon.js';6
import VImage from '../element/image.js';7
import VPlayButton from '../element/play-button.js';
12
return {13
station: null,14
group: null,14
open: false15
open: true,16
state17
};18
},19
components: {20
VTab,21
VButton,22
VIcon,23
VImage,
26
},27
methods: {28
$lang,29
$route,30
duration,31
async show(station) {32
this.station = await http`get::/api/station/${station.id}`();33
if(this.station === null) {34
$route('@not-found', { update: false });35
return;36
}37
this.group = null;38
if(this.station.group_id) {39
this.group = await http`get::/api/group/${this.station.group_id}`();
83
},84
getDescription() {85
return this.station.description ?? this.group?.group.description;86
},87
share() {88
if('share' in navigator) {89
navigator.share({90
url: window.location.href,91
title: this.station.name92
});93
}94
}95
},96
mounted() {97
const path = window.location.pathname;98
const match = /^\/station\/(\d+)$/.exec(path);99
if(match) {100
const id = match[1];101
this.show({ id });102
}103
},104
created() {
118
}119
},120
template: `97
<div class="z-40">98
<div99
@click="open = false"100
class="fixed top-0 bottom-0 left-0 right-0 bg-black/60 transition-detail"101
:style="opacity"102
>103
</div>104
<div105
ref="modal"106
class="w-full mx-auto flex flex-col bg-black fixed left-[100vw] top-0 h-[100vh] overflow-y-auto px-4 pb-12 sm:pb-[100px] sm:px-10 transition-detail"107
:class="{ 'detail-active': open }"108
>109
<div class="w-full flex flex-col max-w-[1200px] mx-auto">110
<div111
class="w-full absolute top-0 left-0 h-[40vh] z-[-1]"112
:style="{'background': gradient(station?.color)}"113
>114
</div>115
<div class="w-full h-[98px] py-6 flex gap-4 justify-between">116
<v-button117
icon="chevron-left"118
@click="open = false"119
></v-button>120
<v-button121
icon="share"122
></v-button>123
</div>124
<div class="flex flex-col gap-5 md:mt-8">125
<v-image126
v-if="station"127
:station="station"128
class="w-[96px] h-[96px] min-w-[96px]"129
></v-image>121
<v-tab id="detail" :tab="state.tab">122
<div class="z-40">123
<div124
@click="open = false"125
class="fixed top-0 bottom-0 left-0 right-0 bg-black/60 transition-detail"126
:style="opacity"127
>128
</div>129
<div130
ref="modal"131
class="w-full mx-auto flex flex-col bg-black fixed left-[100vw] top-0 h-[100vh] overflow-y-auto px-4 pb-12 sm:pb-[100px] sm:px-10 transition-detail"132
:class="{ 'detail-active': open }"133
>134
<div class="w-full flex flex-col max-w-[1200px] mx-auto">135
<div131
v-if="station"132
class="flex flex-col flex-1 min-w-0"136
class="w-full absolute top-0 left-0 h-[40vh] z-[-1]"137
:style="{'background': gradient(station?.color)}"138
>134
<p135
:title="station.name"136
class="text-[24px] md:text-[36px] font-[600] text-gray-100 pb-0 overflow-hidden text-ellipsis whitespace-nowrap"139
</div>140
<div class="w-full h-[98px] py-6 flex gap-4 justify-between">141
<v-button142
icon="chevron-left"143
@click="$route('/')"144
></v-button>145
<v-button146
icon="share"147
@click="share()"148
></v-button>149
</div>150
<div class="flex flex-col gap-5 md:mt-8">151
<v-image152
v-if="station"153
:station="station"154
class="w-[96px] h-[96px] min-w-[96px]"155
></v-image>156
<div157
v-if="station"158
class="flex flex-col flex-1 min-w-0"159
>138
{{station.name}}139
</p>140
<span class="text-md text-gray-400 overflow-hidden flex flex-wrap gap-x-3 gap-y-1 pt-1">141
<span142
v-if="group?.group"143
class="text-gray-400 inline-flex items-center gap-[5px] w-full sm:w-auto"144
:title="$lang('global.country')"160
<p161
:title="station.name"162
class="text-[24px] md:text-[36px] font-[600] text-gray-100 pb-0 overflow-hidden text-ellipsis whitespace-nowrap"163
>146
<p>{{$lang('detail.hosted-by')}} {{group.group.name}}</p>164
{{station.name}}165
</p>166
<span class="text-md text-gray-400 overflow-hidden flex flex-wrap gap-x-3 gap-y-1 pt-1">167
<span168
v-if="group?.group"169
class="text-gray-400 inline-flex items-center gap-[5px] w-full sm:w-auto"170
:title="$lang('global.country')"171
>172
<p>{{$lang('detail.hosted-by')}} {{group.group.name}}</p>173
</span>174
<span175
v-if="station.country"176
class="text-gray-400 inline-flex items-center gap-[5px]"177
:title="$lang('global.country')"178
>179
<v-icon180
id="map-pin"181
class="w-[18px] h-[18px] !min-w-[18px] inline-flex text-gray-400"182
size="100%"183
></v-icon>184
<p>{{station.state ? station.state + ', ' : ''}}{{station.country}}</p>185
</span>186
<span187
v-if="station?.playtime && duration(station.playtime ?? 0).length > 0"188
class="text-gray-400 inline-flex items-center gap-[5px]"189
:title="$lang('detail.playtime')"190
>191
<v-icon192
id="clock"193
class="w-[18px] h-[18px] !min-w-[18px] inline-flex text-gray-400"194
size="100%"195
></v-icon>196
<p>{{duration(station.playtime ?? 0)}}</p>197
</span>198
</span>199
</div>200
</div>201
<div202
v-if="station"203
class="flex flex-col gap-6 mt-8"204
>205
<div v-if="station.tags && station.tags.length > 0" class="flex gap-3 flex-wrap">206
<span v-for="tag in station.tags" class="cursor-pointer text-md text-white/90 font-medium items-center gap-[5px] bg-zinc-900 hover:bg-zinc-800 rounded-[4px] text-[14px] px-[14px] inline-flex h-[34px] leading-[34px]">{{tag}}</span>207
</div>208
<div class="flex gap-3">209
<v-play-button :station="station"></v-play-button>210
<v-button211
:icon="station.is_favorite ? 'bookmark-off' : 'bookmark'"212
:title="$lang(station.is_favorite ? 'global.unlike' : 'global.like')"213
@click="() => setLike(!station.is_favorite)"214
class="bg-zinc-900 hover:bg-white px-1"215
:text="station.likes.toString()"216
></v-button>217
</div>218
<p v-if="getDescription()" class="text-md text-gray-400 mt-2" v-html="getDescription()"></p>219
<p v-else class="text-md text-gray-400">{{$lang('detail.no-description')}}</p>220
<div v-if="station.is_restricted || station.is_broken || station.is_no_track_info" class="flex gap-2 flex-wrap">221
<span149
v-if="station.country"150
class="text-gray-400 inline-flex items-center gap-[5px]"151
:title="$lang('global.country')"222
v-if="station.is_restricted"223
class="text-white/90 items-center gap-[5px] bg-blue-600/70 rounded-[4px] text-[14px] px-[7px] inline-flex h-[24px] leading-[24px]"224
>153
<v-icon154
id="map-pin"155
class="w-[18px] h-[18px] !min-w-[18px] inline-flex text-gray-400"156
size="100%"157
></v-icon>158
<p>{{station.state ? station.state + ', ' : ''}}{{station.country}}</p>225
<p class="-mt-[1px]">Restricted</p>226
</span>227
<span161
v-if="station?.playtime && duration(station.playtime ?? 0).length > 0"162
class="text-gray-400 inline-flex items-center gap-[5px]"163
:title="$lang('detail.playtime')"228
v-if="station.is_broken"229
class="text-white/90 items-center gap-[5px] bg-red-600/70 rounded-[4px] text-[14px] px-[7px] inline-flex h-[24px] leading-[24px]"230
>165
<v-icon166
id="clock"167
class="w-[18px] h-[18px] !min-w-[18px] inline-flex text-gray-400"168
size="100%"169
></v-icon>170
<p>{{duration(station.playtime ?? 0)}}</p>231
<p class="-mt-[1px]">Broken</p>232
</span>172
</span>173
</div>174
</div>175
<div176
v-if="station"177
class="flex flex-col gap-6 mt-8"178
>179
<div v-if="station.tags && station.tags.length > 0" class="flex gap-3 flex-wrap">180
<span v-for="tag in station.tags" class="cursor-pointer text-md text-white/90 font-medium items-center gap-[5px] bg-zinc-900 hover:bg-zinc-800 rounded-[4px] text-[14px] px-[14px] inline-flex h-[34px] leading-[34px]">{{tag}}</span>181
</div>182
<div class="flex gap-3">183
<v-play-button :station="station"></v-play-button>184
<v-button185
:icon="station.is_favorite ? 'bookmark-off' : 'bookmark'"186
:title="$lang(station.is_favorite ? 'global.unlike' : 'global.like')"187
@click="() => setLike(!station.is_favorite)"188
class="bg-zinc-900 hover:bg-white px-1"189
:text="station.likes.toString()"190
></v-button>191
</div>192
<p v-if="getDescription()" class="text-md text-gray-400 mt-2" v-html="getDescription()"></p>193
<p v-else class="text-md text-gray-400">{{$lang('detail.no-description')}}</p>194
<div v-if="station.is_restricted || station.is_broken || station.is_no_track_info" class="flex gap-2 flex-wrap">195
<span196
v-if="station.is_restricted"197
class="text-white/90 items-center gap-[5px] bg-blue-600/70 rounded-[4px] text-[14px] px-[7px] inline-flex h-[24px] leading-[24px]"198
>199
<p class="-mt-[1px]">Restricted</p>200
</span>201
<span202
v-if="station.is_broken"203
class="text-white/90 items-center gap-[5px] bg-red-600/70 rounded-[4px] text-[14px] px-[7px] inline-flex h-[24px] leading-[24px]"204
>205
<p class="-mt-[1px]">Broken</p>206
</span>207
<span208
v-if="station.is_no_track_info"209
class="text-white/90 items-center gap-[5px] bg-green-600/70 rounded-[4px] text-[14px] px-[7px] inline-flex h-[24px] leading-[24px]"210
>211
<p class="-mt-[1px]">No track info</p>212
</span>213
</div>214
<div v-if="hasGroup()" class="mt-[32px]">215
<h3 class="text-white text-[24px] font-bold pb-6 sm:pt-0">{{$lang('detail.related')}}</h3>216
<ul class="flex flex-col">217
<li218
:key="station.id"219
v-for="group_station in group.stations"220
v-if="station.id !== group_station.id"221
class="border-t sm:border-t-2 first:border-none border-zinc-900 py-4 first:pt-0"233
<span234
v-if="station.is_no_track_info"235
class="text-white/90 items-center gap-[5px] bg-green-600/70 rounded-[4px] text-[14px] px-[7px] inline-flex h-[24px] leading-[24px]"236
>223
<v-station :station="group_station"></v-station>224
</li>225
</ul>237
<p class="-mt-[1px]">No track info</p>238
</span>239
</div>240
<div v-if="hasGroup()" class="mt-[32px]">241
<h3 class="text-white text-[24px] font-bold pb-6 sm:pt-0">{{$lang('detail.related')}}</h3>242
<ul class="flex flex-col">243
<li244
:key="station.id"245
v-for="group_station in group.stations"246
v-if="station.id !== group_station.id"247
class="border-t sm:border-t-2 first:border-none border-zinc-900 py-4 first:pt-0"248
>249
<v-station :station="group_station"></v-station>250
</li>251
</ul>252
</div>253
</div>254
</div>255
</div>256
</div>230
</div>257
</v-tab>258
`259
}
1
import {$lang} from '../utils.js';1
import {$lang, $route} from '../utils.js';2
import VButton from '../element/button.js';4
export default {
7
VButton8
},9
methods: {10
$lang10
$lang,11
$route12
},13
template: `14
<div class="sticky top-0 z-30 -mb-2">
18
icon="search"19
:title="$lang('global.search')"20
:active="state.tab === 'search'"20
@click="() => state.tab = 'search'"21
@click="$route('/search')"22
></v-button>23
<v-button24
icon="bookmarks"25
:title="$lang('global.favorites')"26
:active="state.tab === 'favorites'"26
@click="() => state.tab = 'favorites'"27
@click="$route('/favorites')"28
></v-button>29
</div>30
<v-button
32
icon="user"33
:title="$lang('global.account')"34
:active="state.tab === 'account'"34
@click="() => state.tab = 'account'"35
@click="$route('/account')"36
></v-button>37
</div>38
<div class="w-full h-2 bg-gradient-to-b from-black to-transparent"></div>
1
import {state} from '../main.js';2
import {$lang, http} from '../utils.js';2
import {$lang, $route, http} from '../utils.js';3
import VButton from '../element/button.js';4
import VIcon from '../element/icon.js';5
import VImage from '../element/image.js';
16
},17
methods: {18
$lang,19
$route20
},21
template: `22
<div>
28
></v-image>29
<div30
class="flex flex-col flex-1 min-w-0 cursor-pointer"30
@click="() => state.app.$refs.detail.show(station)"31
@click="$route('/station/' + station.id)"32
>33
<p34
:title="station.name"
55
<div v-if="type === 'grid'" class="flex flex-col gap-3 group w-full min-w-full">56
<v-image57
:station="station"57
@click="() => state.app.$refs.detail.show(station)"58
@click="$route('/station/' + station.id)"59
class="w-full aspect-square min-w-full cursor-pointer"60
></v-image>61
<p
1
import Vue, {reactive} from '/asset/lib/vue.min.js';2
import {http, $lang} from './utils.js';2
import {http, $lang, $route} from './utils.js';3
import VMenu from './component/menu.js';4
import VPlayer from './component/player.js';5
import VPopup from './component/popup.js';6
import VSearch from './page/search.js';7
import VFavorites from './page/favorites.js';8
import VAccount from './page/account.js';9
import VNotfound from './page/notfound.js';10
import VAuth from './page/auth.js';11
import VDetail from './component/detail.js';
14
export const SWIPE_THRESHOLD = 70;15
export const TOKEN_NAME = 'verbal-token';17
export const ROUTES = {18
'^\/$': 'search',19
'^\/search$': 'search',20
'^\/favorites$': 'favorites',21
'^\/account$': 'account',22
'^\/station\/(\\d+)$': 'detail',23
'^@not-found$': 'not-found'24
};26
export const state = reactive({27
app: null,28
tab: 'search',
49
VSearch,50
VFavorites,51
VAccount,52
VNotfound,53
VAuth,54
VPlayer,55
VPopup,
59
document.body.style.display = '';60
state.app = this;61
this.init();62
window.addEventListener('popstate', this.onPopState);63
},64
methods: {65
async init() {
87
navigator.serviceWorker.register('/worker.js');88
navigator.serviceWorker.addEventListener('controllerchange', this.updated);89
}90
$route(window.location.pathname, { update: false });91
},92
showError(error) {93
this.$refs.popup.open({
120
]121
});122
},123
onPopState() {124
$route(window.location.pathname, { update: false });125
},126
onScroll() {127
if(state.tab === 'search') {128
if(window.innerHeight + window.pageYOffset >= document.body.offsetHeight - 200) {
147
</div>148
<v-player ref="player" v-if="state.authenticated" :station="state.station"></v-player>149
<v-detail ref="detail" v-if="state.authenticated"></v-detail>150
<v-notfound v-if="state.authenticated" :state="state"></v-notfound>151
<v-popup ref="popup"></v-popup>152
</div>153
`
1
import {state} from '../main.js';2
import {$lang, $route} from '../utils.js';3
import VButton from '../element/button.js';4
import VTab from '../component/tab.js';5
import VIcon from '../element/icon.js';7
export default {8
props: ['state'],9
components: {10
VTab,11
VButton,12
VIcon,13
},14
methods: {15
$lang,16
$route,17
},18
template: `19
<v-tab id="not-found" :tab="state.tab">20
<div class="z-40">21
<div22
ref="modal"23
class="w-full mx-auto flex flex-col bg-black fixed left-[100vw] top-0 h-[100vh] overflow-y-auto px-4 pb-12 sm:pb-[100px] sm:px-10 transition-detail detail-active"24
>25
<div class="w-full flex flex-col max-w-[1200px] mx-auto">26
<div class="w-full h-[98px] py-6 flex gap-4 justify-between">27
<v-button28
icon="chevron-left"29
@click="$route('/')"30
></v-button>31
<v-button32
icon="message-report"33
></v-button>34
</div>35
<div class="flex flex-col gap-5 md:mt-16">36
<div class="flex flex-col flex-1 min-w-0 text-center">37
<p class="text-[24px] md:text-[36px] font-[600] text-gray-100 pb-0 overflow-hidden text-ellipsis whitespace-nowrap">38
{{$lang('global.not-found')}}39
</p>40
</div>41
</div>42
</div>43
</div>44
</div>45
</v-tab>46
`47
}
1
import {state, TOKEN_NAME} from './main.js';1
import {state, TOKEN_NAME, ROUTES} from './main.js';3
const ltr = (parts, values) => {4
let string = '';
81
return message;82
}84
export function $route(path, { update = true } = {}) {85
for(const [key, value] of Object.entries(ROUTES)) {86
const regex = new RegExp(key);87
const match = regex.exec(path);88
if(match !== null) {89
state.tab = value;90
if(value === 'detail') {91
if(state.app.$refs.detail) {92
state.app.$refs.detail.show({ id: match[1] });93
}94
}95
if(update) {96
window.history.pushState(null, null, path);97
}98
return;99
}100
}101
state.tab = 'not-found';102
}104
export function duration(time) {105
let seconds = time * 10;106
const hours = Math.floor(seconds / 3600);
51
($target:expr, $message:expr) => {{52
match $target {53
Ok(target) => target,54
Err(_) => {55
error!("{}", $message);54
Err(err) => {55
error!("{}\n{}", $message, err);56
return $crate::Response::throw($message);57
}58
}
27
{28
let query = format!(29
"30
SELECT account.*30
SELECT31
account.*,32
(33
SELECT34
sum(playtime)35
FROM get_playtime(account.id)36
)37
AS playtime38
FROM account39
INNER JOIN device33
ON account.id = device.account_id40
ON account.id = device.account_id41
WHERE device.uid = '{}'42
",43
&token,
11
pub id: i32,12
pub name: Option<String>,13
pub language: String,14
pub playtime: i64,15
}17
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
466
name = '{name}',467
language = '{language}'468
WHERE account.id = {account_id}469
RETURNING *469
RETURNING470
account.*,471
(472
SELECT473
sum(playtime)474
FROM get_playtime(account.id)475
)476
AS playtime477
"#,478
account_id = account.id,479
name = updated_account.name.unwrap_or_default(),
39
/* serve content */40
app.at("/").serve_file("dist/www/index.html")?;41
app.at("/*").serve_file("dist/www/index.html")?;42
app.at("/manifest.json")43
.serve_file("dist/www/manifest.json")?;44
app.at("/worker.js").serve_file("dist/www/worker.js")?;
26
"global.upcoming": "<br><br>Comming soon!",27
"global.logout": "Log Out",28
"global.listen": "Listen",29
"global.not-found": "Page not found",30
"player.loading": "Loading...",31
"player.no-song-title": "- No song title available -",32
"search.input.all": "All",
81
"global.logout": "Abmelden",82
"player.loading": "Laden...",83
"global.listen": "Hören",84
"global.not-found": "Seite konnte nicht gefunden werden",85
"player.no-song-title": "- Song Titel nicht verfügbar -",86
"search.input.all": "Alle",87
"search.input.placeholder": "Suche nach Sender",