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} from '../utils.js';2
import {http, $lang, duration} from '../utils.js';3
import VButton from '../element/button.js';4
import VIcon from '../element/icon.js';5
import VImage from '../element/image.js';7
export default {8
props: ['station'],8
data() {9
return {10
station: null,11
open: false12
};13
},
23
},24
methods: {25
$lang,26
duration,27
async load(stationId) {28
this.station = await http`get::/api/station/${stationId}`();29
this.open = true;30
},31
onTouchStart(event) {32
this.touch = event.changedTouches[0];33
this.target = event.target;
57
}58
}59
}60
},61
gradient(color) {62
return `linear-gradient(to bottom, ${color ?? 'transparent'}, transparent)`;63
}64
},65
created() {
91
class="w-full max-w-[1200px] mx-auto flex flex-col bg-black fixed left-0 right-0 top-[100vh] h-[100vh] px-4 sm:px-10 transition-modal"92
:class="{ 'modal-active': open }"93
>94
<div95
class="w-full absolute top-0 left-0 h-[40vh] z-[-1]"96
:style="{'background': gradient(station?.color)}"97
>98
</div>99
<div class="w-full h-[98px] py-6 flex gap-4 justify-between">100
<v-button101
icon="chevron-down"
105
icon="share"106
></v-button>107
</div>95
<div class="flex gap-4 items-center">108
<div class="flex flex-col gap-4">109
<v-image110
v-if="station"111
:station="station"
144
<div v-if="station.tags && station.tags.length > 0" class="flex gap-3 flex-wrap">145
<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>146
</div>147
<p class="text-md text-gray-400">{{$lang('detail.playtime')}}: {{duration(station.playtime ?? 0)}}</p>148
<p v-if="station.description" class="text-md text-gray-400" v-html="station.description"></p>149
<p v-else class="text-md text-gray-400">{{$lang('detail.no-description')}}</p>150
<div v-if="station.is_restricted || station.is_broken || station.is_no_track_info" class="flex gap-2 flex-wrap">
28
state.app.$refs.player.open = true;29
},30
openDetail(station) {31
state.app.$refs.detail.station = station;32
state.app.$refs.detail.open = true;31
state.app.$refs.detail.load(station.id);32
}33
},34
template: `
61
></v-icon>62
<p>{{station.state ? station.state + ', ' : ''}}{{station.country}}</p>63
</span>65
<span66
v-if="station.is_restricted"67
class="text-white/90 items-center gap-[5px] bg-blue-600/70 rounded-[4px] text-[14px] px-[7px] hidden sm:inline-flex leading-[24px]"68
>69
<p class="-mt-[1px]">Restricted</p>70
</span>71
<span72
v-if="station.is_broken"73
class="text-white/90 items-center gap-[5px] bg-red-600/70 rounded-[4px] text-[14px] px-[7px] hidden sm:inline-flex leading-[24px]"74
>75
<p class="-mt-[1px]">Broken</p>76
</span>77
<span78
v-if="station.is_no_track_info"79
class="text-white/90 items-center gap-[5px] bg-green-600/70 rounded-[4px] text-[14px] px-[7px] hidden sm:inline-flex leading-[24px]"80
>81
<p class="-mt-[1px]">No track info</p>82
</span>64
</span>65
</div>66
<div class="inline-flex gap-3 sm:gap-4">
163
<v-account v-if="state.authenticated" :state="state"></v-account>164
</div>165
<v-player ref="player" v-if="state.authenticated" :station="state.station"></v-player>166
<v-detail ref="detail" v-if="state.authenticated" :station="state.station"></v-detail>166
<v-detail ref="detail" v-if="state.authenticated"></v-detail>167
<v-popup ref="popup"></v-popup>168
</div>169
`
73
};74
}76
export async function update() {78
}76
export function $lang(id, ...args) {77
let message = state.locale[state.account?.language ?? 'en'][id];78
for(const i in args) {
80
}81
return message;82
}84
export function duration(time) {85
let seconds = time * 10;86
const hours = Math.floor(seconds / 3600);87
const minutes = Math.floor((seconds - (hours * 3600)) / 60);88
seconds = seconds - (hours * 3600) - (minutes * 60);89
return `${hours > 0 ? hours + ' h ' : ''}${minutes} min`;90
}
1
#!/bin/bash3
id="$1"4
echo "$id"5
ext="$2"6
url=$(psql verbal -c "select icon from station where id = $id;" -t | xargs echo -n)7
curl -sL "$url" -o "logo.$ext"8
color=$(echo $(convert "logo.$ext" -colors 1 -unique-colors txt:) | awk '{print $8}')9
echo "$color"10
psql verbal -c "update station set color = '$color' where id = $id;"11
rm "logo.$ext"
12
state TEXT,13
languages TEXT[],14
score INTEGER,15
description TEXT15
description TEXT,16
color TEXT17
);19
/* ### station status ### */
27
pub uid: String,28
pub name: String,29
pub url: String,30
pub icon: Option<String>,31
pub country: Option<String>,32
pub state: Option<String>,33
pub is_favorite: Option<bool>,34
pub is_icon: Option<bool>,35
}37
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]38
pub struct StationDetail {39
pub id: i32,40
pub uid: String,41
pub name: String,42
pub url: String,43
pub description: Option<String>,44
pub icon: Option<String>,45
pub homepage: Option<String>,
53
pub is_broken: Option<bool>,54
pub is_no_track_info: Option<bool>,55
pub is_icon: Option<bool>,43
// pub is_hidden: Option<bool>,56
pub playtime: Option<i32>,57
pub color: Option<String>,58
}60
#[derive(Debug, Serialize, Deserialize, FromRow)]
33
station_status.is_no_track_info,34
station_status.is_hidden,35
station_status.is_icon,36
station_stats.playtime,37
CASE38
WHEN favorite.id IS NULL OR favorite.account_id != {account_id}39
THEN false
44
ON station.id = favorite.station_id45
LEFT JOIN station_status46
ON station.id = station_status.station_id47
LEFT JOIN station_stats48
ON station.id = station_stats.station_id49
AND station_stats.account_id = {account_id}50
{conditions}51
AND station_status.is_hidden IS NOT true52
OFFSET {offset}
67
let account =68
unwrap_option_or_throw!(req.ext::<model::Account>(), "no account in request found!");69
let station = req.query::<model::Station>()?;70
let sql = format!(71
r#"72
INSERT INTO73
station_stats74
(account_id, station_id, playtime)75
VALUES76
({account_id}, {station_id}, 1)77
ON CONFLICT (account_id, station_id)78
DO UPDATE79
SET playtime = station_stats.playtime + EXCLUDED.playtime;80
"#,81
account_id = account.id,82
station_id = station.id,83
);84
let mut conn = req.sqlx_conn::<Postgres>().await;85
sqlx::query(&sql).execute(conn.acquire().await?).await?;86
let mut response = surf::get(&station.url).header("icy-metadata", "1").await?;87
let meta_int = match response.header("icy-metaint") {88
Some(header) => header.as_str(),
117
}118
total += len;119
}100
let sql = format!(101
r#"102
INSERT INTO103
station_stats104
(account_id, station_id, playtime)105
VALUES106
({account_id}, {station_id}, 1)107
ON CONFLICT (account_id, station_id)108
DO UPDATE109
SET playtime = station_stats.playtime + EXCLUDED.playtime;110
"#,111
account_id = account.id,112
station_id = station.id,113
);114
let mut conn = req.sqlx_conn::<Postgres>().await;115
sqlx::query(&sql).execute(conn.acquire().await?).await?;120
Response::with(title)121
}
132
station_status.is_no_track_info,133
station_status.is_hidden,134
station_status.is_icon,135
station_stats.playtime,136
true as is_favorite137
FROM station138
LEFT JOIN favorite139
ON station.id = favorite.station_id140
LEFT JOIN station_status141
ON station.id = station_status.station_id142
LEFT JOIN station_stats143
ON station.id = station_stats.station_id144
AND station_stats.account_id = {account_id}145
WHERE favorite.account_id = {account_id}146
AND station_status.is_hidden IS NOT true147
"#,
206
station_status.is_no_track_info,207
station_status.is_hidden,208
station_status.is_icon,209
station_stats.playtime,210
CASE211
WHEN favorite.id IS NULL OR favorite.account_id != {account_id}212
THEN false
217
ON station.id = favorite.station_id218
LEFT JOIN station_status219
ON station.id = station_status.station_id220
LEFT JOIN station_stats221
ON station.id = station_stats.station_id222
AND station_stats.account_id = {account_id}223
WHERE station.id = {station_id}224
AND station_status.is_hidden IS NOT true225
"#,
227
station_id = station_id,228
);229
let mut conn = req.sqlx_conn::<Postgres>().await;218
let result = sqlx::query_as::<_, model::Station>(&sql)230
let result = sqlx::query_as::<_, model::StationDetail>(&sql)231
.fetch_optional(conn.acquire().await?)232
.await?;233
Response::with(result)
43
"account.devices.unknown": "Unknown device",44
"account.devices.current": "Current",45
"account.devices.add": "Add device",46
"detail.no-description": "No description available"46
"detail.no-description": "No description available",47
"detail.playtime": "Playtime"48
},49
"de": {50
"global.none": "-",
90
"account.devices.unknown": "Unbekanntes Gerät",91
"account.devices.current": "Aktuelles",92
"account.devices.add": "Gerät hinzufügen",92
"detail.no-description": "Keine Beschreibung vorhanden"93
"detail.no-description": "Keine Beschreibung vorhanden",94
"detail.playtime": "Spielzeit"95
}96
}