Skip to content

Commit

Permalink
tests updated
Browse files Browse the repository at this point in the history
  • Loading branch information
neonwatty committed Jul 31, 2024
1 parent 72cfca0 commit 1820bca
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 41 deletions.
Empty file.
44 changes: 44 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python application

on:
pull_request:
branches: [ "main" ]
paths-ignore:
- '**/README.md'
- '**/CONTRIBUTING.md'
- '**LICENSE'

jobs:
ruff:
name: lint with ruff
runs-on: ubuntu-latest
timeout-minutes: 3
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v2
- uses: chartboost/ruff-action@v1
with:
args: 'format --check'
config: .ruff.toml
test:
name: run pytest
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.test
pip install -r requirements.txt
- name: Run pytest
run: |
PYTHONPATH=. python3.10 -m pytest tests/test_app.py
18 changes: 4 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Build stage
FROM python:3.10-slim AS builder
FROM python:3.10-slim

RUN apt-get update && apt-get install -y \
build-essential \
Expand All @@ -9,23 +8,14 @@ RUN apt-get update && apt-get install -y \

WORKDIR /home

COPY requirements.txt .

RUN pip3 install --no-cache-dir -r requirements.txt

# Runtime stage
FROM python:3.10-slim

ENV PYTHONPATH=.

WORKDIR /home

COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
COPY requirements.txt /home/requirements.txt
COPY ytdatakit /home/ytdatakit
COPY .streamlit /home/.streamlit
RUN pip3 install -r /home/requirements.txt

EXPOSE 8501
EXPOSE 8502

HEALTHCHECK CMD curl --fail http://localhost:8502/_stcore/health || exit 1

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ A simple app that lets you conveniently download youtube videos, transcripts, th
To run the app install the associated `requirements.txt` and run

```python
python youtube_downloader/app.py
python streamlit run ytdatakit/app.py
```

Or run via Docker
Expand Down
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ services:
image: ytdatakit
container_name: ytdatakit
ports:
- 8502:8502
- 8502:8502
volumes:
- ./data:/home/data
4 changes: 2 additions & 2 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os

cwd = os.getcwd()
CONTAINER_NAME = "youtube_downloader"
APP_FILE = "youtube_downloader/app.py"
CONTAINER_NAME = "ytdatakit"
APP_FILE = "ytdatakit/app.py"
2 changes: 1 addition & 1 deletion tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@pytest.fixture(scope="module")
def start_app():
cmd = f"python {APP_FILE}"
cmd = f"python -m streamlit run {APP_FILE} --server.headless true"
process = subprocess.Popen(
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
Expand Down
6 changes: 4 additions & 2 deletions ytdatakit/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
st.set_page_config(page_title=app_name)
st.title(app_name)

tab1, tab2, tab3, tab4, tab5, tab6 = st.tabs(["Video downloader", "Transcript downloader", "Thumbnail downloader", "Channel downloader", "💡 About", "Settings"])
tab1, tab2, tab3, tab4, tab5, tab6 = st.tabs(
["Video downloader", "Transcript downloader", "Thumbnail downloader", "Channel downloader", "💡 About", "Settings"]
)

with tab1:
video_downloader()
Expand All @@ -17,4 +19,4 @@
with tab3:
thumbnail_downloader()
with tab4:
channel_downloader()
channel_downloader()
4 changes: 2 additions & 2 deletions ytdatakit/youtube_channel_downloader/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def app():
st.session_state.channel_data_table = df_table
st.session_state.channel_data_download = df_download
st.session_state.channel_fetch_count += 1

with video_channel_col_c:
st.markdown('<p class="custom-font">fetch</p>', unsafe_allow_html=True)
st.markdown('<span id="button-download"></span>', unsafe_allow_html=True)
Expand All @@ -83,4 +83,4 @@ def app():
type="primary",
)
with st.container(border=True):
st.table(st.session_state.channel_data_table.head(10))
st.table(st.session_state.channel_data_table.head(10))
4 changes: 1 addition & 3 deletions ytdatakit/youtube_channel_downloader/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@


default_channel_name = "Monkhaus"
default_channel_name = "Monkhaus"
1 change: 0 additions & 1 deletion ytdatakit/youtube_channel_downloader/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ def state_reset():
if "channel_data_download" not in st.session_state:
st.session_state.channel_data_download = df.to_csv().encode("utf-8")
st.session_state.channel_fetch_count = 0

14 changes: 7 additions & 7 deletions ytdatakit/youtube_channel_downloader/yt_channel_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

def get_channel_id_from_name(channel_name: str) -> str | None:
ydl_opts = {
'quiet': True,
'skip_download': True,
'extract_flat': True,
'force_generic_extractor': True,
"quiet": True,
"skip_download": True,
"extract_flat": True,
"force_generic_extractor": True,
}

with yt_dlp.YoutubeDL(ydl_opts) as ydl:
try:
info = ydl.extract_info(f'ytsearch1:{channel_name}', download=False)
info = ydl.extract_info(f"ytsearch1:{channel_name}", download=False)
return info["entries"][0]["channel_id"]
except Exception as e:
print(f"FAILURE: get_channel_id_from_name failed with exception {e}")
Expand All @@ -26,7 +26,7 @@ def get_videourl_from_channel_id(channel_id: str) -> Tuple[list, list] | Tuple[N
video_urls = []
video_ids = []
for video in videos:
vid = video['videoId']
vid = video["videoId"]
vurl = "https://www.youtube.com/watch?v=" + vid
video_ids.append(vid)
video_urls.append(vurl)
Expand Down
4 changes: 2 additions & 2 deletions ytdatakit/youtube_downloader/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def app():
value="https://www.youtube.com/watch?v=qQgyoHsknIk",
label="🔗 Paste YouTube / Shorts URL here",
placeholder="e.g., https://www.youtube.com/watch?v=.",
key="youtube_download_text_input"
key="youtube_download_text_input",
)
with video_download_col_b:
resolution_dropdown = st.selectbox(options=video_choices, index=st.session_state.youtube_download_resolution_index, label="video resolution")
Expand All @@ -70,7 +70,7 @@ def app():
url_input,
resolution_dropdown,
),
key="youtube_download_fetch_button"
key="youtube_download_fetch_button",
)
with st.container(border=True):
with open(st.session_state.youtube_download_location, "rb") as file:
Expand Down
10 changes: 5 additions & 5 deletions ytdatakit/youtube_thumbnail_downloader/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@ def app():
with open(st.session_state.thumbnails_zip_path, "rb") as file:
st.download_button(
label="download thumbnails",
data=file, #st.session_state.thumbnails_zip_path if "thumbnails_zip_path" in st.session_state else "./data/input/blank.zip",
data=file, # st.session_state.thumbnails_zip_path if "thumbnails_zip_path" in st.session_state else "./data/input/blank.zip",
file_name="thumbnails.zip",
mime="application/zip",
type="primary",
disabled=True if st.session_state.thumbnail_fetch_count == 0 else False
)
disabled=True if st.session_state.thumbnail_fetch_count == 0 else False,
)
else:
st.download_button(
label="download thumbnails",
data="./data/input/blank.zip",
file_name="thumbnails.zip",
mime="application/zip",
type="primary",
disabled=True
)
disabled=True,
)

with st.container(border=True):
for ind, thumbnail_savepath in enumerate(st.session_state.thumbnail_savepaths):
Expand Down

0 comments on commit 1820bca

Please sign in to comment.