Skip to content

Commit

Permalink
Feat: Rename State to Region
Browse files Browse the repository at this point in the history
  • Loading branch information
jcorporation committed Jul 7, 2024
1 parent ec212e0 commit 54350bc
Show file tree
Hide file tree
Showing 959 changed files with 1,016 additions and 100 deletions.
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/add-webradio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ body:
validations:
required: true
- type: input
id: state
id: region
attributes:
label: State
description: The state or region, e.g. Bayern.
label: Region
description: The region, e.g. Bayern.
validations:
required: false
- type: input
Expand Down
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/modify-webradio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ body:
validations:
required: false
- type: input
id: state
id: region
attributes:
label: New state
description: The state or region, e.g. Bayern.
label: New region
description: The region, e.g. Bayern.
validations:
required: false
- type: input
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Webradios are saved as extended m3u files with some custom fields. A coverimage
#HOMEPAGE:<homepage>
#COUNTRY:<country>
#STATE:<state>
#Region:<region>
#LANGUAGE:<language>
#DESCRIPTION:<description>
#CODEC:<codec>
Expand All @@ -104,7 +105,8 @@ The final files are located in the `docs/db` folder, it is rebuild daily. The fo
| [bitrates.min.json](https://jcorporation.github.io/webradiodb/db/index/bitrates.min.json) | Array of bitrates |
| [codecs.min.json](https://jcorporation.github.io/webradiodb/db/index/codecs.min.json) | Array of codecs |
| [countries.min.json](https://jcorporation.github.io/webradiodb/db/index/countries.min.json) | Array of countries |
| [states.min.json](https://jcorporation.github.io/webradiodb/db/index/states.min.json) | Object of countries and linked states |
| [states.min.json](https://jcorporation.github.io/webradiodb/db/index/states.min.json) | Object of countries and linked states. Deprecated, use regions. |
| [regions.min.json](https://jcorporation.github.io/webradiodb/db/index/regions.min.json) | Object of countries and linked regions |
| [genres.min.json](https://jcorporation.github.io/webradiodb/db/index/genres.min.json) | Array of genres |
| [languages.min.json](https://jcorporation.github.io/webradiodb/db/index/languages.min.json) | Array of languages |
| [status.min.json](https://jcorporation.github.io/webradiodb/db/index/status.min.json) | Array of failed stream checks |
Expand All @@ -122,6 +124,7 @@ The m3u fields are mapped for better readability.
| HOMEPAGE | Homepage | String |
| COUNTRY | Country | String |
| STATE | State | String |
| REGION | Region | String |
| LANGUAGE | Language | String |
| LANGUAGE | Languages | Array |
| CODEC | Codec | Array |
Expand All @@ -140,6 +143,7 @@ The m3u fields are mapped for better readability.
"Homepage": "https://www.swr.de/swr1/",
"Country": "Germany",
"State": "Baden-Württemberg",
"Region": "Baden-Württemberg",
"Language": "German",
"Languages": [
"German"
Expand Down
62 changes: 42 additions & 20 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ STATUSFILE="${PUBLISH_DIR}/index/status.min.json"
LANGFILE="${PUBLISH_DIR}/index/languages.min.json"
COUNTRYFILE="${PUBLISH_DIR}/index/countries.min.json"
STATEFILE="${PUBLISH_DIR}/index/states.min.json"
REGIONFILE="${PUBLISH_DIR}/index/regions.min.json"
GENREFILE="${PUBLISH_DIR}/index/genres.min.json"
CODECFILE="${PUBLISH_DIR}/index/codecs.min.json"
BITRATEFILE="${PUBLISH_DIR}/index/bitrates.min.json"
Expand Down Expand Up @@ -153,7 +154,7 @@ resize_image() {
return 0
}

# Normalizes GENRE, CODEC, COUNTRY, STATE, LANGUAGE in all m3u's in specified folder
# Normalizes GENRE, CODEC, COUNTRY, REGION, LANGUAGE in all m3u's in specified folder
normalize_fields() {
local DIR=$1
local F
Expand Down Expand Up @@ -217,6 +218,17 @@ normalize_fields() {
echo "$F: $STATE -> $STATE_UPPER"
sed -i -e "s/^#STATE:.*/#STATE:$STATE_UPPER/" "$F"
fi
# region
local REGION=""
REGION=$(get_m3u_field "$F" "REGION")
local REGION_UPPER
REGION_UPPER=$(ucwords "$REGION")
REGION_UPPER=$(trim "$REGION_UPPER")
if [ "$REGION" != "$REGION_UPPER" ]
then
echo "$F: $REGION -> $REGION_UPPER"
sed -i -e "s/^#REGION:.*/#REGION:$REGION_UPPER/" "$F"
fi
# language
local LANGUAGE_LINE=""
LANGUAGE_LINE=$(get_m3u_field "$F" "LANGUAGE")
Expand Down Expand Up @@ -323,6 +335,7 @@ sync_moode() {
#HOMEPAGE:$HOMEPAGE
#COUNTRY:$COUNTRY
#STATE:
#REGION:
#LANGUAGE:$LANGUAGE
#DESCRIPTION:
#CODEC:$CODEC
Expand Down Expand Up @@ -365,6 +378,7 @@ add_radio() {
#HOMEPAGE:<homepage>
#COUNTRY:<country>
#STATE:<state>
#REGION:<region>
#LANGUAGE:<language>
#DESCRIPTION:<description>
#CODEC:<codec>
Expand Down Expand Up @@ -394,8 +408,8 @@ add_radio_from_json() {
HOMEPAGE=$(jq -r ".homepage" < "$INPUT" | head -1 | tr -d '\n')
local COUNTRY
COUNTRY=$(jq -r ".country" < "$INPUT" | head -1 | tr -d '\n')
local STATE
STATE=$(jq -r ".state" < "$INPUT" | head -1 | tr -d '\n')
local REGION
REGION=$(jq -r ".region" < "$INPUT" | head -1 | tr -d '\n')
local LANGUAGE
LANGUAGE=$(jq -r ".language" < "$INPUT" | head -1 | tr -d '\n')
local DESCRIPTION
Expand Down Expand Up @@ -440,7 +454,8 @@ add_radio_from_json() {
#EXTIMG:$IMAGE
#HOMEPAGE:$HOMEPAGE
#COUNTRY:$COUNTRY
#STATE:$STATE
#STATE:$REGION
#REGION:$REGION
#LANGUAGE:$LANGUAGE
#DESCRIPTION:$DESCRIPTION
#CODEC:$CODEC
Expand Down Expand Up @@ -486,8 +501,8 @@ modify_radio_from_json() {
NEW_HOMEPAGE=$(jq -r ".homepage" < "$INPUT" | head -1 | tr -d '\n')
local NEW_COUNTRY
NEW_COUNTRY=$(jq -r ".country" < "$INPUT" | head -1 | tr -d '\n')
local NEW_STATE
NEW_STATE=$(jq -r ".state" < "$INPUT" | head -1 | tr -d '\n')
local NEW_REGION
NEW_REGION=$(jq -r ".region" < "$INPUT" | head -1 | tr -d '\n')
local NEW_LANGUAGE
NEW_LANGUAGE=$(jq -r ".language" < "$INPUT" | head -1 | tr -d '\n')
local NEW_DESCRIPTION
Expand All @@ -514,8 +529,8 @@ modify_radio_from_json() {
OLD_HOMEPAGE=$(get_m3u_field "${MYMPD_PLS_DIR}/${MODIFY_PLIST}.m3u" "HOMEPAGE")
local OLD_COUNTRY
OLD_COUNTRY=$(get_m3u_field "${MYMPD_PLS_DIR}/${MODIFY_PLIST}.m3u" "COUNTRY")
local OLD_STATE
OLD_STATE=$(get_m3u_field "${MYMPD_PLS_DIR}/${MODIFY_PLIST}.m3u" "STATE")
local OLD_REGION
OLD_REGION=$(get_m3u_field "${MYMPD_PLS_DIR}/${MODIFY_PLIST}.m3u" "REGION")
local OLD_LANGUAGE
OLD_LANGUAGE=$(get_m3u_field "${MYMPD_PLS_DIR}/${MODIFY_PLIST}.m3u" "LANGUAGE")
local OLD_DESCRIPTION
Expand Down Expand Up @@ -572,7 +587,7 @@ modify_radio_from_json() {
[ -z "$NEW_GENRE" ] && NEW_GENRE="$OLD_GENRE"
[ -z "$NEW_HOMEPAGE" ] && NEW_HOMEPAGE="$OLD_HOMEPAGE"
[ -z "$NEW_COUNTRY" ] && NEW_COUNTRY="$OLD_COUNTRY"
[ -z "$NEW_STATE" ] && NEW_STATE="$OLD_STATE"
[ -z "$NEW_REGION" ] && NEW_REGION="$OLD_REGION"
[ -z "$NEW_LANGUAGE" ] && NEW_LANGUAGE="$OLD_LANGUAGE"
[ -z "$NEW_DESCRIPTION" ] && NEW_DESCRIPTION="$OLD_DESCRIPTION"
[ -z "$NEW_CODEC" ] && NEW_CODEC="$OLD_CODEC"
Expand All @@ -586,7 +601,8 @@ modify_radio_from_json() {
#EXTIMG:$NEW_IMAGE
#HOMEPAGE:$NEW_HOMEPAGE
#COUNTRY:$NEW_COUNTRY
#STATE:$NEW_STATE
#STATE:$NEW_REGION
#REGION:$NEW_REGION
#LANGUAGE:$NEW_LANGUAGE
#DESCRIPTION:$NEW_DESCRIPTION
#CODEC:$NEW_CODEC
Expand Down Expand Up @@ -892,26 +908,27 @@ create_index() {
COUNTRIES_COUNT=$(jq -r '.[]' "$COUNTRYFILE.tmp" | wc -l)
echo "${COUNTRIES_COUNT} countries in index"

# states
# regions
local COUNTRY
local I=0
{
printf "{"
while read -r COUNTRY
do
[ "$I" -eq 0 ] || printf ','
local STATES=""
STATES=$(jq -r ".[] | select(.Country == \"$COUNTRY\") | select(.State != \"\") | .State" "${INDEXFILE}.tmp" | \
local REGIONS=""
REGIONS=$(jq -r ".[] | select(.Country == \"$COUNTRY\") | select(.Region != \"\") | .Region" "${INDEXFILE}.tmp" | \
sort -u | jq -R -s -c 'split("\n") | .[0:-1]' | tr -d '\n')
[ -z "$STATES" ] && STATES="[]"
printf '"%s":%s' "$COUNTRY" "$STATES"
[ -z "$REGIONS" ] && REGIONS="[]"
printf '"%s":%s' "$COUNTRY" "$REGIONS"
I=$((I+1))
done < <(jq -r '.[].Country' "${INDEXFILE}.tmp" | sort -u)
printf "}"
} > "$STATEFILE.tmp"
local STATES_COUNT
STATES_COUNT=$(jq -r '.[] | select(.State != "") | .State' "$INDEXFILE.tmp" | wc -l)
echo "${STATES_COUNT} states in index"
} > "$REGIONFILE.tmp"
cp "$REGIONFILE.tmp" "$STATEFILE.tmp"
local REGIONS_COUNT
REGIONS_COUNT=$(jq -r '.[] | select(.Region != "") | .Region' "$INDEXFILE.tmp" | wc -l)
echo "${REGIONS_COUNT} regions in index"

# genres
jq -r '.[] | .Genre | .[]' "${INDEXFILE}.tmp" | sort -u | \
Expand Down Expand Up @@ -949,7 +966,11 @@ create_index() {

printf "\"webradioStates\":" >> "${INDEXFILE_COMBINED}.tmp"
tr -d '\n' < "${STATEFILE}.tmp" >> "${INDEXFILE_COMBINED}.tmp"
printf ",\"totalwebradioStates\":%s," "$STATES_COUNT" >> "${INDEXFILE_COMBINED}.tmp"
printf ",\"totalwebradioStates\":%s," "$REGIONS_COUNT" >> "${INDEXFILE_COMBINED}.tmp"

printf "\"webradioRegions\":" >> "${INDEXFILE_COMBINED}.tmp"
tr -d '\n' < "${REGIONFILE}.tmp" >> "${INDEXFILE_COMBINED}.tmp"
printf ",\"totalwebradioRegions\":%s," "$REGIONS_COUNT" >> "${INDEXFILE_COMBINED}.tmp"

printf "\"webradioCodecs\":" >> "${INDEXFILE_COMBINED}.tmp"
tr -d '\n' < "${CODECFILE}.tmp" >> "${INDEXFILE_COMBINED}.tmp"
Expand Down Expand Up @@ -977,6 +998,7 @@ create_index() {
move_compress_changed "$LANGFILE" && CHANGED=1
move_compress_changed "$COUNTRYFILE" && CHANGED=1
move_compress_changed "$STATEFILE" && CHANGED=1
move_compress_changed "$REGIONFILE" && CHANGED=1
move_compress_changed "$GENREFILE" && CHANGED=1
move_compress_changed "$CODECFILE" && CHANGED=1
move_compress_changed "$BITRATEFILE" && CHANGED=1
Expand Down
27 changes: 14 additions & 13 deletions docs/assets/js/radiodb.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const issueDeleteAlternate = '?labels=DeleteAlternateStream&template=delete-alte
const searchInput = document.getElementById('searchStr');
const genreSelect = document.getElementById('genres');
const countrySelect = document.getElementById('countries');
const stateSelect = document.getElementById('states');
const regionSelect = document.getElementById('regions');
const languageSelect = document.getElementById('languages');
const codecSelect = document.getElementById('codecs');
const bitrateSelect = document.getElementById('bitrates');
Expand Down Expand Up @@ -54,12 +54,12 @@ function populateSelect(el, options) {
}
}

function populateStates() {
stateSelect.options.length = 0;
appendOpt(stateSelect, '', 'State');
function populateRegions() {
regionSelect.options.length = 0;
appendOpt(regionSelect, '', 'Region');
const country = getSelectValue(countrySelect);
if (country !== '') {
populateSelect(stateSelect, webradiodb.webradioStates[country]);
populateSelect(regionSelect, webradiodb.webradioRegions[country]);
}
}

Expand All @@ -82,7 +82,7 @@ searchInput.addEventListener('keyup', function(event) {
}, false);

countrySelect.addEventListener('change', function() {
populateStates();
populateRegions();
}, false);

document.getElementById('searchBtn').addEventListener('click', function() {
Expand All @@ -105,7 +105,7 @@ function returnStreamError(m3u) {
return p;
}

function search(name, genre, country, state, language, codec, bitrate, sort, offset, limit, error) {
function search(name, genre, country, region, language, codec, bitrate, sort, offset, limit, error) {
name = name.toLowerCase();
const obj = {
"result": {
Expand All @@ -119,7 +119,7 @@ function search(name, genre, country, state, language, codec, bitrate, sort, off
if (webradiodb.webradios[key].Name.toLowerCase().indexOf(name) > -1 &&
(genre === '' || webradiodb.webradios[key].Genre.includes(genre)) &&
(country === '' || country === webradiodb.webradios[key].Country) &&
(state === '' || state === webradiodb.webradios[key].State) &&
(region === '' || region === webradiodb.webradios[key].Region) &&
(language === '' || webradiodb.webradios[key].Languages.includes(language)) &&
(codec === '' || webradiodb.webradios[key].allCodecs.includes(codec)) &&
(bitrate === 0 || bitrate <= webradiodb.webradios[key].highestBitrate)
Expand Down Expand Up @@ -186,7 +186,7 @@ function showSearchResult(offset, limit, error) {
searchInput.value = '';
genreSelect.selectedIndex = 0;
countrySelect.selectedIndex = 0;
stateSelect.selectedIndex = 0;
regionSelect.selectedIndex = 0;
languageSelect.selectedIndex = 0;
codecSelect.selectedIndex = 0;
bitrateSelect.selectedIndex = 0;
Expand All @@ -196,7 +196,7 @@ function showSearchResult(offset, limit, error) {
const searchstr = searchInput.value.toLowerCase();
const genreFilter = getSelectValue(genreSelect);
const countryFilter = getSelectValue(countrySelect);
const stateFilter = getSelectValue(stateSelect);
const regionFilter = getSelectValue(regionSelect);
const languageFilter = getSelectValue(languageSelect);
const codecFilter = getSelectValue(codecSelect);
const bitrateFilter = getSelectValue(bitrateSelect);
Expand All @@ -206,7 +206,7 @@ function showSearchResult(offset, limit, error) {
resultEl.textContent = '';
}

const obj = search(searchstr, genreFilter, countryFilter, stateFilter, languageFilter, codecFilter, bitrateFilter, sort, offset, limit, error);
const obj = search(searchstr, genreFilter, countryFilter, regionFilter, languageFilter, codecFilter, bitrateFilter, sort, offset, limit, error);
document.getElementById('resultCount').textContent = obj.result.totalEntities;
for (const key in obj.result.data) {
const div = document.createElement('div');
Expand Down Expand Up @@ -243,9 +243,9 @@ function showSearchResult(offset, limit, error) {
div.getElementsByTagName('img')[0].src = pic;
div.getElementsByClassName('genre')[0].textContent = obj.result.data[key].Genre.join(', ');
div.getElementsByClassName('country')[0].textContent = obj.result.data[key].Country +
(obj.result.data[key].State === ''
(obj.result.data[key].Region === ''
? ''
: ' / ' + obj.result.data[key].State);
: ' / ' + obj.result.data[key].Region);
div.getElementsByClassName('language')[0].textContent = obj.result.data[key].Languages.join(', ');
let format = obj.result.data[key].Codec;
if (format !== '' && obj.result.data[key].Bitrate !== '') {
Expand Down Expand Up @@ -304,6 +304,7 @@ function showSearchResult(offset, limit, error) {
'&homepage=' + encodeURIComponent(obj.result.data[key].Homepage) +
'&image=' + encodeURIComponent(obj.result.data[key].Image) +
'&country=' + encodeURIComponent(obj.result.data[key].Country) +
'&region=' + encodeURIComponent(obj.result.data[key].Region) +
'&language=' + encodeURIComponent(obj.result.data[key].Language) +
'&codec=' + encodeURIComponent(obj.result.data[key].Codec) +
'&bitrate=' + encodeURIComponent(obj.result.data[key].Bitrate) +
Expand Down
2 changes: 1 addition & 1 deletion docs/db/index/countries.min.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
["Argentina","Australia","Austria","Bahamas","Belgium","Bermuda","Bolivia","Brazil","Canada","Chile","China","Colombia","Costa Rica","Cuba","Czech Republic","Denmark","Estonia","France","Germany","Ghana","Greece","Hungary","India","Israel","Italy","Japan","Korea, Democratic People's Republic Of","Kyrgyzstan","Lithuania","Luxembourg","Malaysia","Netherlands","New Zealand","Nigeria","Poland","Portugal","Republica Dominicana","Russia","Spain","Sweden","Switzerland","Syria","The Netherlands","USA","Ukraine","United Kingdom","United States","Vietnam","Wales"]
["Argentina","Australia","Austria","Bahamas","Belgium","Bermuda","Bolivia","Brazil","Canada","Chile","China","Colombia","Costa Rica","Cuba","Czech Republic","Denmark","Estonia","France","Germany","Ghana","Greece","Hungary","India","Israel","Italy","Japan","Korea, Democratic People's Republic Of","Kyrgyzstan","Lithuania","Luxembourg","Malaysia","Netherlands","New Zealand","Nigeria","Poland","Portugal","Republica Dominicana","Russia","Spain","Sweden","Switzerland","Syria","The Netherlands","Ukraine","United Kingdom","United States","USA","Vietnam","Wales"]
Binary file modified docs/db/index/countries.min.json.gz
Binary file not shown.
Loading

0 comments on commit 54350bc

Please sign in to comment.