A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
7
package-lock.json8
Cargo.lock9
www/asset/css/output.css10
.version
1
FROM rust:latest as builder2
WORKDIR /home/andreas/git/verbal4
RUN curl -sLO https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x645
RUN chmod +x tailwindcss-linux-x646
RUN mv tailwindcss-linux-x64 tailwindcss8
RUN cargo init10
COPY ./Cargo.lock ./Cargo.lock
18
RUN rm ./target/release/deps/verbal*19
RUN cargo build --release21
COPY ./app ./app22
COPY ./www ./www23
COPY ./tailwind.config.js ./tailwind.config.js24
COPY ./build ./build26
COPY ./www/worker.js ./www/worker.js27
COPY ./.version ./.version29
RUN ./build30
# RUN ./tailwindcss -c tailwind.config.js -i www/asset/css/input.css -o www/asset/css/output.css --minify32
CMD ["./target/release/verbal"]
54
this.$refs.player.load();55
}56
},57
setVolume(event) {58
this.$refs.player.volume = event.target.value;59
},60
onPlay() {61
if(this.resume) {62
this.playing = false;
138
<source :src="station.url" type="audio/ogg">139
<source :src="station.url" type="audio/aac">140
</audio>138
<div class="p-5 bg-zinc-800 rounded-xl flex gap-5 items-center relative overflow-hidden shadow-2xl z-30">141
<div class="p-5 bg-zinc-800 rounded-xl flex gap-5 items-center relative overflow-hidden shadow-2xl z-30 flex-col sm:flex-row">142
<img143
v-if="station.icon"144
:src="station.icon"
171
</p>172
</div>173
<div class="inline-flex gap-4 z-10 pr-2">174
<input type="range" min="0" max="1" step="0.05" @change="setVolume">175
<v-button176
:icon="[ station.is_favorite ? 'bookmark-off' : 'bookmark' ]"177
:title="[ $lang(station.is_favorite ? 'global.unlike' : 'global.like') ]"
27
},28
template: `29
<div class="w-full gap-4 group flex items-center">30
<div class="w-[54px] h-[54px] min-w-[54px] bg-zinc-900 rounded-lg overflow-hidden">30
<div31
class="w-[54px] h-[54px] min-w-[54px] bg-zinc-900 rounded-md overflow-hidden cursor-pointer"32
@click="() => setStation(station)"33
>34
<img35
v-if="station.icon"36
:alt="station.name"
45
class="text-gray-400"46
></v-icon>47
</div>45
<div class="flex flex-col flex-1 min-w-0">46
<p :title="station.name" class="text-lg font-medium text-gray-100 pb-0 overflow-hidden text-ellipsis whitespace-nowrap">{{station.name}}</p>48
<div class="flex flex-col flex-1 min-w-0 cursor-pointer">49
<p50
:title="station.name"51
class="text-lg font-medium text-gray-100 pb-0 overflow-hidden text-ellipsis whitespace-nowrap"52
>53
{{station.name}}54
</p>55
<span class="text-md text-gray-400 overflow-hidden flex gap-2 sm:gap-3">56
<span57
v-if="station.country"
59
:title="$lang('global.country')"60
>61
<v-icon54
id="world"62
id="map-pin"63
class="w-[18px] h-[18px] !min-w-[18px] inline-flex text-gray-400"64
size="100%"65
></v-icon>58
<p>{{station.country}}</p>66
<p>{{station.state ? station.state + ', ' : ''}}{{station.country}}</p>67
</span>68
<span61
v-if="station.votes"62
class="text-gray-400 inline-flex items-center gap-[5px]"63
:title="$lang('global.votes')"69
v-if="station.is_restricted"70
class="text-white/90 items-center gap-[5px] bg-blue-600/70 rounded-[4px] text-[14px] px-[7px] hidden sm:inline-flex"71
>65
<v-icon66
id="thumb-up"67
class="w-[18px] h-[18px] !min-w-[18px] inline-flex text-gray-400"68
size="100%"69
></v-icon>70
<p>{{station.votes}}</p>72
<p class="-mt-[1px]">Restricted</p>73
</span>74
<span73
v-if="station.click_trend"74
class="text-gray-400 hidden sm:inline-flex items-center gap-[5px]"75
:title="$lang('global.trend')"75
v-if="station.is_broken"76
class="text-white/90 items-center gap-[5px] bg-red-600/70 rounded-[4px] text-[14px] px-[7px] hidden sm:inline-flex"77
>77
<v-icon78
:id="[ station.click_trend >= 0 ? 'arrow-up-right' : 'arrow-down-right' ]"79
class="w-[18px] h-[18px] !min-w-[18px] inline-flex text-gray-400"80
></v-icon>81
<p>{{Math.abs(station.click_trend) ?? 'None'}}</p>78
<p class="-mt-[1px]">Broken</p>79
</span>80
<span81
v-if="station.is_no_track_info"82
class="text-white/90 items-center gap-[5px] bg-green-600/70 rounded-[4px] text-[14px] px-[7px] hidden sm:inline-flex"83
>84
<p class="-mt-[1px]">No track info</p>85
</span>86
</span>87
</div>
93
@click="() => setLike(!station.is_favorite)"94
class="bg-zinc-900 hover:bg-white"95
></v-button>93
<v-button94
icon="player-play"95
class="bg-zinc-900 hover:bg-white"96
:title="$lang('global.play')"97
@click="() => setStation(station)"98
></v-button>96
</div>97
</div>98
`
8
export const state = {9
app: null,10
tab: 'favorites',10
tab: 'search',11
account: {12
username: '',13
language: 'en'
41
state.account = await http`get::/api/account`();42
document.addEventListener('scroll', this.onScroll);43
document.addEventListener('wheel', this.onScroll);44
if('serviceWorker' in navigator) {45
navigator.serviceWorker.register('/worker.js');46
navigator.serviceWorker.addEventListener('controllerchange', this.updated);47
}48
},49
updated() {50
// TODO: show update popup51
},52
onScroll() {53
if(state.tab === 'search') {54
if(window.innerHeight + window.pageYOffset >= document.body.offsetHeight - 200) {48
this.$refs.search.doSearchMore();55
if(this.$refs.search.searching) {56
this.$refs.search.doSearchMore();57
}58
}59
}60
}61
},62
template: `54
<div class="px-4 sm:px-10 pb-8 sm:pb-[100px] max-w-[800px] mx-auto flex flex-col">63
<div class="px-4 sm:px-10 pb-8 sm:pb-[100px] max-w-[1200px] mx-auto flex flex-col">64
<v-menu :state="state"></v-menu>65
<v-player :station="state.station"></v-player>66
<v-search ref="search" :state="state"></v-search>
9
return {10
query: {11
name: '',12
country: '',13
language: '',14
page: 015
},16
results: [],17
loading: false,16
more: true18
searching: false,19
more: true,20
countries: [],21
languages: [],22
recommended: [],23
popular: [24
45761,25
44366,26
37156,27
33977,28
56254,29
3061530
]31
};32
},33
components: {
41
this.results = [];42
this.loading = true;43
this.more = true;44
this.searching = true;45
this.query.page = 0;46
const result = await http`get::/api/search`(this.query);47
this.loading = false;
58
this.more = false;59
}60
this.results.push(...result);61
},62
async loadRecommended() {63
for(const id of this.popular) {64
this.recommended.push(await http`get::/api/station`({ id }));65
}66
},67
async loadFilters() {68
const countries = await http`get::/api/countries`();69
for(const {country} of countries) {70
this.countries.push(country);71
}72
const languages = await http`get::/api/languages`();73
for(const {language} of languages) {74
this.languages.push(language.toUpperCase());75
}76
},77
reset() {78
this.query = {79
name : '',80
page: 081
};82
this.searching = false;83
this.results = [];84
this.loadRecommended();85
}86
},87
mounted() {49
this.doSearch();88
this.loadRecommended();89
this.loadFilters();90
},91
template: `52
<v-tab id="search" :tab="state.tab" @show="doSearch">53
<input54
v-model="query.name"55
@keyup.enter="doSearch"56
type="text"57
:placeholder="$lang('search.input.placeholder')"58
class="w-full h-[56px] px-5 text-lg rounded-lg bg-zinc-900 text-white font-medium placeholder:font-normal placeholder:text-gray-500 focus:placeholder:text-gray-600 outline-none"59
spellcheck="false"60
autocomplete="off"61
>62
<ul class="flex flex-col">92
<v-tab id="search" :tab="state.tab">93
<div class="flex flex-wrap gap-4">94
<input95
v-model="query.name"96
@change="doSearch"97
type="text"98
:placeholder="$lang('search.input.placeholder')"99
class="flex-1 h-[56px] px-5 text-lg rounded-lg bg-zinc-900 text-white font-medium placeholder:font-normal placeholder:text-gray-500 focus:placeholder:text-gray-600 outline-none"100
spellcheck="false"101
autocomplete="off"102
>103
<div class="flex gap-4 w-full md:w-[300px]">104
<select105
v-model="query.country"106
@change="doSearch"107
class="w-6/12 h-[56px] px-5 text-lg rounded-lg bg-zinc-900 text-white font-medium placeholder:font-normal placeholder:text-gray-500 focus:placeholder:text-gray-600 outline-none cursor-pointer appearance-none"108
>109
<option value="" selected>All</option>110
<option v-for="country in countries" :value="country">{{country}}</option>111
</select>112
<select113
v-model="query.language"114
@change="doSearch"115
class="w-6/12 h-[56px] px-5 text-lg rounded-lg bg-zinc-900 text-white font-medium placeholder:font-normal placeholder:text-gray-500 focus:placeholder:text-gray-600 outline-none cursor-pointer appearance-none"116
>117
<option value="">All</option>118
<option v-for="language in languages" :value="language">{{language}}</option>119
</select>120
</div>121
</div>122
<ul v-if="searching" class="flex flex-col">123
<li124
:key="station.id"125
v-for="station in results"
128
<v-station :station="station"></v-station>129
</li>130
</ul>131
<div v-else>132
<h3 class="text-white text-[24px] font-bold pb-8 pt-4 sm:pt-0">{{$lang('search.recommended')}}</h3>133
<ul class="flex flex-col">134
<li135
:key="station.id"136
v-for="station in recommended"137
class="border-t sm:border-t-2 first:border-none border-zinc-900 py-5 first:pt-0"138
>139
<v-station :station="station"></v-station>140
</li>141
</ul>142
</div>143
<div144
v-show="loading"145
class="w-[60px] h-[60px] select-none pointer-events-none mx-auto"
152
></v-icon>153
</div>154
<div83
v-if="!more && results.length > 0"155
v-if="searching && !more && results.length > 0"156
class="text-zinc-400 text-md mx-auto pb-6"157
>158
{{$lang('search.list.end')}}159
</div>160
<div89
v-if="results.length == 0"161
v-if="searching && !loading && results.length == 0"162
class="text-zinc-400 text-md mx-auto pb-6"163
>164
{{$lang('search.list.empty')}}
14
const regex = /^(\w+)::([\w\/.]*)$/;15
const [, method, path] = line.match(regex) ?? [];16
return (query) => {17
if(query !== undefined) {18
query = JSON.parse(JSON.stringify(query));19
}20
return new Promise(async (resolve, reject) => {21
try {22
const headers = {23
'content-type': 'application/json',24
}22
const deviceToken = localStorage.getItem('verbal-token');23
if(deviceToken) {24
headers['verbal-token'] = deviceToken;25
const token = localStorage.getItem('verbal-token') ?? 'test-token';26
if(token) {27
headers['verbal-token'] = token;28
}29
let body = null;30
let params = '';
37
query[`${key}[${i}]`] = value[i];38
}39
}40
else if(value === null) {41
delete query[key];42
}43
}44
}45
params = '?' + new URLSearchParams(query).toString();
1
#!/bin/bash3
tailwindcss -c tailwind.config.js -i www/asset/css/input.css -o www/asset/css/output.css --minify3
./tailwindcss -c tailwind.config.js -i www/asset/css/input.css -o www/asset/css/output.css --minify5
version=$(cat ./.version)6
sed -i -e "s/{{version}}/$version/g" www/worker.js
14
score INTEGER15
);17
/* ### station status ### */19
CREATE TABLE station_status (20
id SERIAL PRIMARY KEY,21
station_id INTEGER UNIQUE,22
is_restricted BOOLEAN DEFAULT false,23
is_broken BOOLEAN DEFAULT false,24
is_no_track_info BOOLEAN DEFAULT false,25
is_hidden BOOLEAN DEFAULT false26
);28
ALTER TABLE station_status29
ADD CONSTRAINT station_status_station_id30
FOREIGN KEY (station_id)31
REFERENCES station(id);33
/* ### account ### */35
CREATE TABLE account (
34
pub languages: Option<Vec<String>>,35
pub score: i32,36
pub is_favorite: Option<bool>,37
pub is_restricted: Option<bool>,38
pub is_broken: Option<bool>,39
pub is_no_track_info: Option<bool>,40
// pub is_hidden: Option<bool>,41
}43
#[derive(Debug, Serialize, Deserialize, FromRow)]
83
Ok(sql)84
}85
}87
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]88
pub struct StationCountry {89
pub country: String,90
}92
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]93
pub struct StationLanguage {94
pub language: String,95
}97
#[derive(Debug, Clone, Deserialize)]98
pub struct StationId {99
pub id: i32,100
}
5
use tide_sqlx::SQLxRequestExt;7
use crate::model;8
use crate::model::StationCountry;9
use crate::model::StationId;10
use crate::model::StationLanguage;11
use crate::unwrap_option_or_throw;12
use crate::unwrap_result_or_throw;13
use crate::Response;
31
r#"32
SELECT33
station.*,34
station_status.is_restricted,35
station_status.is_broken,36
station_status.is_no_track_info,37
station_status.is_hidden,38
CASE39
WHEN favorite.id IS NULL OR favorite.account_id != {account_id}40
THEN false
43
FROM station44
LEFT JOIN favorite45
ON station.id = favorite.station_id46
LEFT JOIN station_status47
ON station.id = station_status.station_id48
{conditions}49
AND station_status.is_hidden IS NOT true50
OFFSET {offset}51
LIMIT 1052
"#,
107
r#"108
SELECT109
station.*,110
station_status.is_restricted,111
station_status.is_broken,112
station_status.is_no_track_info,113
station_status.is_hidden,114
true as is_favorite115
FROM station116
LEFT JOIN favorite117
ON station.id = favorite.station_id118
LEFT JOIN station_status119
ON station.id = station_status.station_id120
WHERE favorite.account_id = {account_id}121
AND station_status.is_hidden IS NOT true122
"#,123
account_id = account.id,124
);
167
sqlx::query(&sql).execute(conn.acquire().await?).await?;168
Response::with(())169
}171
pub async fn get_station(req: tide::Request<()>) -> tide::Result {172
let station_id = req.query::<StationId>()?;173
let account =174
unwrap_option_or_throw!(req.ext::<model::Account>(), "no account in request found!");175
let sql = format!(176
r#"177
SELECT178
station.*,179
station_status.is_restricted,180
station_status.is_broken,181
station_status.is_no_track_info,182
station_status.is_hidden,183
CASE184
WHEN favorite.id IS NULL OR favorite.account_id != {account_id}185
THEN false186
ELSE true187
END AS is_favorite188
FROM station189
LEFT JOIN favorite190
ON station.id = favorite.station_id191
LEFT JOIN station_status192
ON station.id = station_status.station_id193
WHERE station.id = {station_id}194
AND station_status.is_hidden IS NOT true195
"#,196
account_id = account.id,197
station_id = station_id.id,198
);199
let mut conn = req.sqlx_conn::<Postgres>().await;200
let result = sqlx::query_as::<_, model::Station>(&sql)201
.fetch_optional(conn.acquire().await?)202
.await?;203
Response::with(result)204
}206
pub async fn get_countries(req: tide::Request<()>) -> tide::Result {207
let sql = format!(208
r#"209
SELECT210
country211
FROM station212
WHERE country != ''213
GROUP BY country214
ORDER BY COUNT(*) DESC;215
"#,216
);217
let mut conn = req.sqlx_conn::<Postgres>().await;218
let result = sqlx::query_as::<_, StationCountry>(&sql)219
.fetch_all(conn.acquire().await?)220
.await?;221
Response::with(result)222
}224
pub async fn get_languages(req: tide::Request<()>) -> tide::Result {225
let sql = format!(226
r#"227
SELECT228
UNNEST(languages) AS language229
FROM station230
GROUP BY UNNEST(languages)231
ORDER BY COUNT(*) DESC;232
"#,233
);234
let mut conn = req.sqlx_conn::<Postgres>().await;235
let result = sqlx::query_as::<_, StationLanguage>(&sql)236
.fetch_all(conn.acquire().await?)237
.await?;238
Response::with(result)239
}
39
/* serve content */40
app.at("/").serve_file("www/index.html")?;41
app.at("/manifest.json").serve_file("www/manifest.json")?;42
app.at("/worker.js").serve_file("www/worker.js")?;43
app.at("/asset").serve_dir("www/asset/")?;44
app.at("/app").serve_dir("app/")?;
53
app.at("/api/favorite").get(route::get_favorites);54
app.at("/api/favorite").post(route::add_favorite);55
app.at("/api/favorite").delete(route::delete_favorite);56
app.at("/api/station").get(route::get_station);57
app.at("/api/countries").get(route::get_countries);58
app.at("/api/languages").get(route::get_languages);60
let address =61
unwrap_result_or_abort!(config.server.to_url(), "cannot parse server address!");
9
::-webkit-scrollbar {10
background-color: black;11
width: 12px;11
width: 0px;12
}14
::-webkit-scrollbar-track {
1
{2
"en": {3
"global.none": "-",4
"global.search": "Search",5
"global.favorites": "Favorites",
16
"global.languages": "Languages",17
"global.state": "State",18
"global.playback-history": "Playback History",19
"player.loading": "Loading...",20
"player.no-song-title": "- No song title available -",21
"search.input.placeholder": "Search for stations",22
"search.list.end": "You've reached the end",23
"search.list.empty": "No results found",24
"search.recommended": "Recommended",25
"account.settings": "Settings",26
"account.username": "Username",27
"account.username.info": "This is your primary account name which is visible to everyone",
31
"account.playback-history": "Show Playback History",32
"account.playback-history.info": "Displays the recently played songs for the current station",33
"account.devices": "Devices"34
},35
"de": {36
"global.none": "-",37
"global.search": "Suche",38
"global.favorites": "Favoriten",
49
"global.languages": "Sprachen",50
"global.state": "Bundesland",51
"global.playback-history": "Wiedergabeverlauf",52
"player.loading": "Laden...",53
"player.no-song-title": "- Song Titel nicht verfügbar -",54
"search.input.placeholder": "Suche nach Sender",55
"search.list.end": "Du hast das Ende erreicht",56
"search.list.empty": "Keine Ergebnisse gefunden",57
"search.recommended": "Empfohlen",58
"account.settings": "Einstellungen",59
"account.username": "Nutzername",60
"account.username.info": "Dies ist Ihr primärer Kontoname, der von allen gesehen werden kann",
64
"account.playback-history": "Wiedergabeverlauf anzeigen",65
"account.playback-history.info": "Zeigt die zuletzt gespielten Songs für den aktuellen Sender an",66
"account.devices": "Geräte"67
}68
}
8
<meta name="google" content="notranslate">9
<meta name="description" content="Online Radio App">10
<title>Verbal</title>11
<link rel="manifest" href="/manifest.json">12
<link rel="icon" type="image/png" href="/asset/img/favicon.png">13
<link rel="stylesheet" href="/asset/css/style.css">14
<link rel="stylesheet" href="/asset/css/output.css">
1
{2
"name": "Verbal",3
"short_name": "Verbal",4
"icons": [5
{6
"src": "/asset/img/icon-192x192.png",7
"sizes": "192x192",8
"type": "image/png"9
},10
{11
"src": "/asset/img/icon-512x512.png",12
"sizes": "512x512",13
"type": "image/png"14
}15
],16
"id": "/",17
"start_url": "/",18
"scope": "/",19
"theme_color": "#000000",20
"background_color": "#000000",21
"display": "standalone"22
}
1
const VERSION = 'dev-{{version}}';3
self.addEventListener('install', self.skipWaiting);5
self.addEventListener('activate', (event) => {6
event.waitUntil(caches.keys().then((keys) => {7
return Promise.all(keys.map((key) => {8
if(key === VERSION) return;9
return caches.delete(key);10
}));11
}));12
});14
self.addEventListener('fetch', (event) => {15
event.respondWith((async () => {16
const file = await caches.match(event.request);17
if(file) return file;18
const response = await fetch(event.request);19
if(!event.request.url.includes('/api')) {20
const cache = await caches.open(VERSION);21
cache.put(event.request, response.clone());22
}23
return response;24
})());25
});