Skip to content

Commit

Permalink
Merge branch 'master' into docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
bhaveshAn authored Oct 4, 2017
2 parents 0627565 + 366de46 commit 4c5e63a
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 11 deletions.
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Contributors

> This work is made possible thanks to all of our great and wonderful contributers. To get involved, feel free to fork the repo, make changes and submit a pull request with [this template](https://github.com/OpenGenus/vidsum/blob/master/COMMIT_TEMPLATE.md).
## Contributors

Thanks goes to these wonderful people who made this possible:

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
| [<img src="https://avatars3.githubusercontent.com/u/10634210?v=4" width="100px;"/><br /><sub>Aditya Chatterjee</sub>](https://github.com/AdiChat)<br /> | [<img src="https://avatars1.githubusercontent.com/u/1000117?v=4" width="100px;"/><br /><sub>Larry Gray</sub>](https://github.com/lwgray)<br /> | [<img src="https://avatars1.githubusercontent.com/u/11667059?v=4" width="100px;"/><br /><sub>Jay Turner</sub>](https://github.com/JayTurnr)<br /> | [<img src="https://avatars1.githubusercontent.com/u/934782?v=4" width="100px;"/><br /><sub>Trevor</sub>](https://github.com/grimd34th)<br /> | [<img src="https://avatars2.githubusercontent.com/u/17149476?v=4" width="100px;"/><br /><sub>Subbu Dantu</sub>](https://github.com/subkrish)<br /> | [<img src="https://avatars2.githubusercontent.com/u/16636569?v=4" width="100px;"/><br /><sub>Nikhil Nayak</sub>](https://github.com/codebu5ter)<br /> |
| :---: | :---: | :---: | :---: | :---: | :---: |
<!-- ALL-CONTRIBUTORS-LIST:END -->

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Please note that vidsum requires the following packages to be installed:

If you do not have these packages installed, then you can do so by running this command:
```sh
$ pip install pysrt imageio moviepy pytube sumy
$ pip install -r requirements.txt

```

Expand Down
44 changes: 34 additions & 10 deletions code/sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@
import argparse
import os
import re
import subprocess
import sys
import math
from itertools import starmap

import pysrt
import imageio
import youtube_dl
import chardet
import nltk
imageio.plugins.ffmpeg.download()
from moviepy.editor import *
nltk.download('punkt')
from itertools import starmap

from moviepy.editor import VideoFileClip, concatenate_videoclips
from sumy.parsers.plaintext import PlaintextParser
from sumy.nlp.tokenizers import Tokenizer
from sumy.nlp.stemmers import Stemmer
from sumy.utils import get_stop_words
from sumy.summarizers.lsa import LsaSummarizer


imageio.plugins.ffmpeg.download()

# generate segmented summary
def summarize(srt_file, n_sentences, language="english"):
"""
Generate segmented summary
Expand All @@ -44,6 +48,7 @@ def summarize(srt_file, n_sentences, language="english"):
return segment


# Extract text from subtitles file
def srt_to_txt(srt_file):
"""
Extract text from subtitles file
Expand All @@ -58,12 +63,13 @@ def srt_to_txt(srt_file):
if item.text.startswith("["):
continue
text += "(%d) " % index
text += item.text.replace("\n", "").strip("...").replace(".",
"").replace("?", "").replace("!", "")
text += item.text.replace("\n", "").strip("...").replace(
".", "").replace("?", "").replace("!", "")
text += ". "
return text


# Handling of srt segments to time range
def srt_segment_to_range(item):
"""
Handling of srt segments to time range
Expand All @@ -76,15 +82,18 @@ def srt_segment_to_range(item):
return start_segment, end_segment


# duration of segments
def time_regions(regions):
"""
Duration of segments
"""
return sum(starmap(lambda start, end: end - start, regions))



# find important sections
def find_summary_regions(srt_filename, duration=30, language="english"):

"""
Find important sections
Expand All @@ -96,6 +105,10 @@ def find_summary_regions(srt_filename, duration=30, language="english"):
"""
srt_file = pysrt.open(srt_filename)

enc = chardet.detect(open(srt_filename,"rb").read())['encoding']
srt_file = pysrt.open(srt_filename,encoding = enc)

# generate average subtitle duration
subtitle_duration = time_regions(
map(srt_segment_to_range, srt_file)) / len(srt_file)
Expand All @@ -117,6 +130,7 @@ def find_summary_regions(srt_filename, duration=30, language="english"):
return summary


# join segments
def create_summary(filename, regions):
"""
Join segments
Expand All @@ -132,6 +146,7 @@ def create_summary(filename, regions):
return concatenate_videoclips(subclips)


# abstract function
def get_summary(filename="1.mp4", subtitles="1.srt"):
"""
Abstract function
Expand All @@ -146,11 +161,14 @@ def get_summary(filename="1.mp4", subtitles="1.srt"):
summary = create_summary(filename, regions)
base, ext = os.path.splitext(filename)
output = "{0}_1.mp4".format(base)
summary.to_videofile(output, codec="libx264",
temp_audiofile="temp.m4a", remove_temp=True, audio_codec="aac")
summary.to_videofile(
output,
codec="libx264",
temp_audiofile="temp.m4a", remove_temp=True, audio_codec="aac")
return True


# download video with subtitles
def download_video_srt(subs):
"""
Downloads specified Youtube video's subtitles as a vtt/srt file.
Expand All @@ -161,11 +179,17 @@ def download_video_srt(subs):
returns:
True
The video will be downloaded as 1.mp4 and its subtitles as 1.(lang).srt
Both, the video and its subtitles, will be downloaded to the same location as that of this script (sum.py)
"""
'''
# The video will be downloaded as 1.mp4 and its subtitles as 1.(lang).srt
# Both, the video and its subtitles, will be downloaded to the same
# location as that of this script (sum.py)

ydl_opts = {
'format': 'best',
'outtmpl': '1.%(ext)s',
Expand Down
21 changes: 21 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
breadability==0.1.20
certifi==2017.7.27.1
chardet==3.0.4
decorator==4.0.11
docopt==0.6.2
idna==2.6
imageio==2.2.0
lxml==4.0.0
moviepy==0.2.3.2
nltk==3.2.5
numpy==1.13.3
olefile==0.44
Pillow==4.3.0
pysrt==1.1.1
pytube==6.4.2
requests==2.18.4
six==1.11.0
sumy==0.7.0
tqdm==4.11.2
urllib3==1.22
youtube-dl==2017.10.1

0 comments on commit 4c5e63a

Please sign in to comment.