Skip to content

Commit

Permalink
Merge pull request #6 from paramt/refactor
Browse files Browse the repository at this point in the history
Refactor code
  • Loading branch information
paramt authored Jun 11, 2019
2 parents e615fac + eecf2df commit a32a3cc
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 59 deletions.
30 changes: 0 additions & 30 deletions api.py

This file was deleted.

12 changes: 0 additions & 12 deletions now.json

This file was deleted.

4 changes: 0 additions & 4 deletions requirements.txt

This file was deleted.

7 changes: 7 additions & 0 deletions scripts/videocloud
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

if [[ ! $@ ]]; then
python -m videocloud -h
else
python -m videocloud $@
fi
25 changes: 25 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import setuptools

with open("README.md") as f:
long_description = f.read()

setuptools.setup(
name="VideoCloud",
version="1.1",
url="https://github.com/paramt/VideoCloud",
license="MIT",
author="Param Thakkar",
author_email="contact@param.me",
description="A command line tool that generates word clouds from YouTube video captions",
long_description=long_description,
long_description_content_type="text/markdown",
scripts=["./scripts/videocloud"],
packages=["videocloud"],
install_requires=[
"setuptools",
"pillow==6.0.0",
"wordcloud==1.5.0",
"youtube-transcript-api==0.1.4"
],
python_requires=">= 3.6"
)
12 changes: 0 additions & 12 deletions src/main.py

This file was deleted.

File renamed without changes.
35 changes: 35 additions & 0 deletions videocloud/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os
import sys
from videocloud.utilities import get_video_id, generate_word_cloud as word_cloud, get_captions as get_cc
from youtube_transcript_api import YouTubeTranscriptApi as ytcc


def main(url: str, filepath):
try:
video_id = get_video_id(url)
captions = get_cc(video_id)
image = word_cloud(captions)
image.save(filepath)
except ytcc.CouldNotRetrieveTranscript:
print("The specified video either doesn't exist or doesn't have captions enabled. Please try again")
exit()
except IOError:
print("There was an error saving the wordcloud file")
exit()

return os.path.abspath(filepath)

if __name__ == "__main__":
try:
video_id = sys.argv[1]
except:
print("Please specify a YouTube video link or video ID")
exit()

try:
filepath = sys.argv[2]
except IndexError:
filepath = "wordcloud.png"

wordcloud = main(video_id, filepath)
print(f"Wordcloud created in {wordcloud}")
File renamed without changes.
2 changes: 1 addition & 1 deletion src/utilities.py → videocloud/utilities.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from PIL.Image import Image
from wordcloud import WordCloud
from youtube_transcript_api import YouTubeTranscriptApi as ytcc
from src import constants
from videocloud import constants

def get_video_id(url: str) -> str:
return(url[-11:])
Expand Down

0 comments on commit a32a3cc

Please sign in to comment.