aboutsummaryrefslogtreecommitdiffstats
path: root/build.sh
blob: 460d1cdf3afb042893c47c6cb3feaeed2c3ddd3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash

# ==============================================================================
# FUNCTIONS - START
# ==============================================================================
VERSION='1.1.14'
BASEDIR="${2-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}"

run_rebrand()
{
    printf '%b%s%b%s%b\n' '\e[1;32m' '==> ' '\e[0m\033[1m' 'Rebrand...' '\e[m'

    mv -T yt_dlp hypervideo_dl
    mv bin/yt-dlp bin/hypervideo

    find . -type f \( \
	 -iname "*" \
	 ! -iname "build.sh" \
	 ! -iname ".travis.yml" \
         ! -iname ".gitlab-ci.yml" \
	 ! -path "./.git*" \) \
	 -exec grep -rIl 'yt_dlp' {} + -exec sed -i 's|yt_dlp|hypervideo_dl|g' {} \;

    find . -name "setup.cfg" -type f -exec sed -i 's|yt-dlp|hypervideo|g' {} \;
    find . -name "Makefile" -type f -exec sed -i 's|yt-dlp|hypervideo|g' {} \;
    find . -name "*.py" -type f -exec sed -i 's|yt-dlp|hypervideo|g' {} \;
    find . -name "*.in" -type f -exec sed -i 's|yt-dlp|hypervideo|g' {} \;

    # fixes URLs
    find . -name "*.py" -type f -exec sed -i 's|hypervideo+test+video|yt-dlp+test+video|g' {} \;
    find . -name "*.py" -type f -exec sed -i 's|https://github.com/ytdl-org/hypervideo/|https://github.com/ytdl-org/yt-dlp/|g' {} \;
    find . -name "*.py" -type f -exec sed -i 's|https://github.com/rg3/hypervideo/issues/|https://github.com/rg3/yt-dlp/issues/|g' {} \;
    find . -name "*.py" -type f -exec sed -i 's|http://hypervideo.bandcamp.com/|http://yt-dlp.bandcamp.com/|g' {} \;
    find . -name "*.py" -type f -exec sed -i 's|http://yt-dlp.bandcamp.com/track/hypervideo-test-song|http://yt-dlp.bandcamp.com/track/yt-dlp-test-song|g' {} \;
    find . -name "*.py" -type f -exec sed -i 's|https://www.dropbox.com/s/nelirfsxnmcfbfh/hypervideo|https://www.dropbox.com/s/nelirfsxnmcfbfh/yt-dlp|g' {} \;
    find . -name "*.py" -type f -exec sed -i 's|http://8tracks.com/ytdl/hypervideo-test-tracks-a|http://8tracks.com/ytdl/yt-dlp-test-tracks-a|g' {} \;
    find . -name "*.py" -type f -exec sed -i 's|http://phihag.de/2014/hypervideo/|http://phihag.de/2014/yt-dlp/|g' {} \;
    find . -name "*.py" -type f -exec sed -i 's|https://hypervideo-demo.neocities.org/|https://yt-dlp-demo.neocities.org/|g' {} \;
    find . -name "*.py" -type f -exec sed -i 's|https://travis-ci.org/ytdl-org/hypervideo/|https://travis-ci.org/ytdl-org/yt-dlp/|g' {} \;
    find . -name "*.py" -type f -exec sed -i 's|https://soundcloud.com/jaimemf/hypervideo-test|https://soundcloud.com/jaimemf/yt-dlp-test|g' {} \;
    find . -name "*.py" -type f -exec sed -i 's|http://streamcloud.eu/skp9j99s4bpz/hypervideo_test_video|http://streamcloud.eu/skp9j99s4bpz/yt_dlp_test_video|g' {} \;

    find . -type f \( \
	 -iname "*" \
	 ! -iname "build.sh" \
	 ! -iname ".travis.yml" \
         ! -iname ".gitlab-ci.yml" \
	 ! -path "./.git*" \) \
	 -exec grep -rIl 'YT-DLP' {} + -exec sed -i 's|YT-DLP|HYPERVIDEO|g' {} \;

    # Set current version
    sed -i "s|__version.*|__version__ = '${VERSION}'|" hypervideo_dl/version.py
}

run_clean()
{
    printf '%b%s%b%s%b\n' '\e[1;32m' '==> ' '\e[0m\033[1m' 'Clean tempfiles...' '\e[m'
    rm -rf -- hypervideo.1.temp.md hypervideo.1 hypervideo.bash-completion README.txt MANIFEST build/ dist/ .coverage cover/ hypervideo.tar.gz hypervideo_dl/extractor/lazy_extractors.py *.dump *.part* *.ytdl *.info.json *.mp4 *.m4a *.flv *.mp3 *.avi *.mkv *.webm *.3gp *.wav *.ape *.swf *.jpg *.png CONTRIBUTING.md.tmp hypervideo hypervideo.exe
    find . -name "*.pyc" -delete
    find . -name "*.class" -delete
}

run_make()
{
    printf '%b%s%b%s%b\n' '\e[1;32m' '==> ' '\e[0m\033[1m' 'Making hypervideo...' '\e[m'
    make hypervideo.tar.gz
}

run_copy()
{
    printf '%b%s%b%s%b\n' '\e[1;32m' '==> ' '\e[0m\033[1m' 'Genering build...' '\e[m'
    install -d -m755 build
    mv hypervideo.tar.gz "./build/hypervideo.tar.gz"
    cd build && tar xzf hypervideo.tar.gz &&
          mv hypervideo "hypervideo-${VERSION}" &&
          tar -czvf "hypervideo-${VERSION}.tar.gz" "hypervideo-${VERSION}" &&
          rm -rf "hypervideo-${VERSION}" hypervideo.tar.gz
    cd "$BASEDIR" || return
    printf '%b%s%b%s%b\n' '\e[1;32m' '==> ' '\e[0m\033[1m' 'Tarball in build/ directory' '\e[m'
}

# Restore directory, compatibility reasons
run_reset()
{
    printf '%b%s%b%s%b\n' '\e[1;32m' '==> ' '\e[0m\033[1m' 'Restore compatibility...' '\e[m'
    mv -T hypervideo_dl yt_dlp
    mv bin/hypervideo bin/yt-dlp
    rm -v hypervideo
    printf '%b%s%b%s%b\n' '\e[1;32m' '==> ' '\e[0m\033[1m' 'Please execute: "git checkout ." for complete restore' '\e[m'
}

# ==============================================================================
# EXECUTION - START
# ==============================================================================
run_rebrand "$@" && run_clean "$@"

run_make "$@"

run_copy "$@" && run_reset "$@"