aboutsummaryrefslogtreecommitdiffstats
path: root/build.sh
blob: a39582798a5c744edd743110d91921b501196b95 (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
100
101
102
103
104
#!/bin/bash

# ==============================================================================
# FUNCTIONS - START
# ==============================================================================
VERSION='1.1.11'
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 youtube_dl hypervideo_dl
    mv bin/youtube-dl bin/hypervideo
    mv youtube-dl.plugin.zsh hypervideo.plugin.zsh

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

    find . -name "tox.ini" -type f -exec sed -i 's|youtube-dl|hypervideo|g' {} \;
    find . -name "setup.cfg" -type f -exec sed -i 's|youtube-dl|hypervideo|g' {} \;
    find . -name "Makefile" -type f -exec sed -i 's|youtube-dl|hypervideo|g' {} \;
    find . -name "*.py" -type f -exec sed -i 's|youtube-dl|hypervideo|g' {} \;
    find . -name "*.in" -type f -exec sed -i 's|youtube-dl|hypervideo|g' {} \;
    find . -name "*.zsh" -type f -exec sed -i 's|youtube-dl|hypervideo|g' {} \;
    find docs -type f -exec sed -i 's|youtube-dl|hypervideo|g' {} \;

    # fixes URLs
    find . -name "*.py" -type f -exec sed -i 's|hypervideo+test+video|youtube-dl+test+video|g' {} \;
    find . -name "*.py" -type f -exec sed -i 's|https://github.com/ytdl-org/hypervideo/|https://github.com/ytdl-org/youtube-dl/|g' {} \;
    find . -name "*.py" -type f -exec sed -i 's|https://github.com/rg3/hypervideo/issues/|https://github.com/rg3/youtube-dl/issues/|g' {} \;
    find . -name "*.py" -type f -exec sed -i 's|http://hypervideo.bandcamp.com/|http://youtube-dl.bandcamp.com/|g' {} \;
    find . -name "*.py" -type f -exec sed -i 's|http://youtube-dl.bandcamp.com/track/hypervideo-test-song|http://youtube-dl.bandcamp.com/track/youtube-dl-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/youtube-dl|g' {} \;
    find . -name "*.py" -type f -exec sed -i 's|http://8tracks.com/ytdl/hypervideo-test-tracks-a|http://8tracks.com/ytdl/youtube-dl-test-tracks-a|g' {} \;
    find . -name "*.py" -type f -exec sed -i 's|http://phihag.de/2014/hypervideo/|http://phihag.de/2014/youtube-dl/|g' {} \;
    find . -name "*.py" -type f -exec sed -i 's|https://hypervideo-demo.neocities.org/|https://youtube-dl-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/youtube-dl/|g' {} \;
    find . -name "*.py" -type f -exec sed -i 's|https://soundcloud.com/jaimemf/hypervideo-test|https://soundcloud.com/jaimemf/youtube-dl-test|g' {} \;
    find . -name "*.py" -type f -exec sed -i 's|http://streamcloud.eu/skp9j99s4bpz/hypervideo_test_video|http://streamcloud.eu/skp9j99s4bpz/youtube_dl_test_video|g' {} \;

    find . -type f \( \
	 -iname "*" \
	 ! -iname "build.sh" \
	 ! -iname ".travis.yml" \
         ! -iname ".gitlab-ci.yml" \
	 ! -path "./.git*" \) \
	 -exec grep -rIl 'YOUTUBE-DL' {} + -exec sed -i 's|YOUTUBE-DL|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.zsh hypervideo.fish 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 youtube_dl
    mv bin/hypervideo bin/youtube-dl
    mv hypervideo.plugin.zsh youtube-dl.plugin.zsh
    rm -v hypervideo hypervideo.1 hypervideo.bash-completion hypervideo.fish hypervideo.zsh
    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 "$@"