V0.1 Deploy to DEV
This commit is contained in:
commit
b7dfa2c397
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
*.webm
|
||||||
|
__pycache__/main.cpython-310.pyc
|
||||||
|
__pycache__/test_main.cpython-310.pyc
|
||||||
14
Dockerfile
Normal file
14
Dockerfile
Normal 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
60
main.py
Normal 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
3
require.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
yt-dlp
|
||||||
|
requests
|
||||||
|
numpy
|
||||||
13
test_main.py
Normal file
13
test_main.py
Normal 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)
|
||||||
Loading…
Reference in New Issue
Block a user