V0.1 Deploy to DEV

This commit is contained in:
Sean Corrigan 2022-04-03 23:22:26 -04:00
commit b7dfa2c397
5 changed files with 93 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*.webm
__pycache__/main.cpython-310.pyc
__pycache__/test_main.cpython-310.pyc

14
Dockerfile Normal file
View File

@ -0,0 +1,14 @@
# set base image (host OS)
FROM python:3.9.10-slim-buster
# set the working directory in the container
WORKDIR /app
# copy the dependencies file to the working directory
COPY require.txt .
# install dependencies
RUN pip install -r require.txt
# copy the content of the local src directory to the working directory
COPY main.py .
# command to run on container start
CMD [ "python3", "main.py" ]

60
main.py Normal file
View File

@ -0,0 +1,60 @@
from typing import List
from xmlrpc.client import Boolean
from numpy import save
import requests, json, os
import yt_dlp
apikey = os.environ['apikey']
playlistId = os.environ['playlistid']
saveDirectory = '/videos'
def getPlaylistVideoIDs() -> List:
url = "https://www.googleapis.com/youtube/v3/playlistItems"
querystring = {
"key": apikey,
"playlistId": playlistId,
"maxResults": "50",
"part":"contentDetails",
}
payload = ""
response = requests.request("GET", url, data=payload, params=querystring)
videoIDs = []
for video in json.loads(response.text)['items']:
videoIDs.append(video['contentDetails']['videoId'])
return videoIDs
def getVideosOnDisk() -> List:
movies = os.listdir(saveDirectory)
moviesUpdated = []
for movie in movies:
moviesUpdated.append(movie.split("[")[1].split(']')[0])
return set(moviesUpdated)
def downloadVideo(videoId) -> Boolean:
ydl_opts = { 'outtmpl': f'{saveDirectory}/%(title)s[%(id)s].%(ext)s'}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.download([f'https://www.youtube.com/watch?v={videoId}'])
return True
def main() -> None:
IDs = getPlaylistVideoIDs()
alreadyDL = getVideosOnDisk()
for ID in IDs:
print(f"Checking disk for {ID}: ", end="")
if ID not in alreadyDL:
print("Downloading...", end="")
downloadVideo(ID)
print("\n\n\n")
else:
print("Already in Library")
if __name__ == "__main__":
main()

3
require.txt Normal file
View File

@ -0,0 +1,3 @@
yt-dlp
requests
numpy

13
test_main.py Normal file
View File

@ -0,0 +1,13 @@
import unittest
import main
class youtubeAPIunitTest(unittest.TestCase):
def test_listVideosType(self):
self.assertEqual(type(main.getPlaylistVideoIDs()), list)
def test_listVideosLen(self):
self.assertGreater(len(main.getPlaylistVideoIDs()), 0)
def test_scanVideoLibrary(self):
self.assertGreater(len(main.getVideosOnDisk()), 0)