-
Notifications
You must be signed in to change notification settings - Fork 632
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #357 from asingh4451/SongsMashupNewProject
Songs mashup new project
- Loading branch information
Showing
4 changed files
with
293 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
from flask import Flask,request,redirect,render_template,send_file | ||
import zipfile | ||
import numpy as np | ||
import smtplib | ||
import concurrent.futures # for multithreading compilation | ||
#import sys | ||
#import re | ||
from pytube import YouTube #downloading the mp4 file | ||
from pydub import AudioSegment # creating small snippets | ||
from pydub.utils import make_chunks # making small chunks out of it | ||
import os | ||
from email.mime.multipart import MIMEMultipart #Emailing the output to the user | ||
from email.mime.base import MIMEBase | ||
from email.utils import COMMASPACE, formatdate | ||
from email import encoders # Encoding the attachment | ||
from zipfile import ZipFile | ||
from youtube_search import YoutubeSearch #Bypassing the Youtube API with the another API | ||
import pandas as pd | ||
app=Flask(__name__) | ||
@app.route('/',methods=['GET','POST']) | ||
def index(): | ||
if(request.method=='POST'): | ||
singer=request.form['singer'] | ||
Number_vid=int(request.form['Number_vid']) | ||
duration=int(request.form['duration']) | ||
Email=request.form['email'] | ||
with concurrent.futures.ThreadPoolExecutor() as executor: | ||
executor.submit(process_audio, singer, Number_vid, duration,Email) | ||
# process_audio(singer,Number_vid,duration) | ||
#email=request.form['email'] | ||
return redirect("/success") | ||
return render_template('index.html') | ||
def process_audio(singer,Number_vid,duration,Email): | ||
singer1=singer+"songs" | ||
results1 = YoutubeSearch(singer1, max_results=Number_vid).to_dict() | ||
data=pd.DataFrame(results1) | ||
for i in range(1,(data['url_suffix'].count())): | ||
data['url_suffix'][i]="https://www.youtube.com"+data['url_suffix'][i] | ||
links=data['url_suffix'] | ||
for i in links: | ||
#yt = YouTube(str(i)) | ||
yt=YouTube(i,use_oauth=True,allow_oauth_cache=True) | ||
#print(yt.title) | ||
#if(yt.length<100): | ||
# extract only audio | ||
video = yt.streams.filter(file_extension='mp4',only_audio=True).first() | ||
# download the file | ||
out_file = video.download() | ||
# save the file | ||
base, ext = os.path.splitext(out_file) | ||
new_file = base + '.mp4' | ||
os.rename(out_file, new_file) | ||
audio_files = [] | ||
for file in os.listdir(): | ||
if file.endswith(".mp4"): | ||
audio = AudioSegment.from_file(file, "mp4") | ||
audio_file = file.replace(".mp4", ".wav") | ||
audio.export(audio_file, format="wav") | ||
audio_files.append(audio_file) | ||
chunks = [] | ||
#print(audio_files) | ||
for audio_file in audio_files: | ||
chunk = make_chunks(AudioSegment.from_file(audio_file,format="wav"), chunk_length=duration * 1000) | ||
id=np.random.randint(0,len(chunk)) | ||
chunk=chunk[id] | ||
#print(chunk) | ||
chunks.append(chunk) | ||
merged=AudioSegment.empty() | ||
for chunk in chunks: | ||
merged+=chunk | ||
merged.export('output.mp3', format="mp3") | ||
dir=os.getcwd() | ||
test = os.listdir(dir) | ||
for item in test: | ||
if item.endswith(".mp4"): | ||
os.remove(os.path.join(dir, item)) | ||
if item.endswith(".wav"): | ||
os.remove(os.path.join(dir, item)) | ||
with zipfile.ZipFile('output.zip', 'w') as zipf: | ||
zipf.write('output.mp3') | ||
msg = MIMEMultipart() | ||
msg['From'] = "noobbobby241@gmail.com" | ||
msg['To'] = COMMASPACE.join([Email]) | ||
msg['Date'] = formatdate(localtime=True) | ||
msg['Subject'] = "Downloaded and Converted Audio" | ||
|
||
with open("output.zip", "rb") as f: | ||
part = MIMEBase('application', "octet-stream") | ||
part.set_payload(f.read()) | ||
|
||
encoders.encode_base64(part) | ||
part.add_header('Content-Disposition', 'attachment', filename="output.zip") | ||
msg.attach(part) | ||
smtp = smtplib.SMTP('smtp.gmail.com', 587) | ||
smtp.ehlo() | ||
smtp.starttls() | ||
smtp.ehlo() | ||
smtp.login("noobbobby241@gmail.com", "cliwqftyqujpisht") | ||
smtp.sendmail("noobbobby241@gmail.com", [Email], msg.as_string()) | ||
print("Email Sent") | ||
@app.route('/success') | ||
def success(): | ||
return render_template('success.html') | ||
#@app.route('/download') | ||
# def download(): | ||
# #@after_this_request | ||
# #def cleanup(response): | ||
# #cleanup_directory() | ||
# #return response | ||
# return send_file('output.zip', as_attachment=True) | ||
#def cleanup_directory(): | ||
#test = os.listdir() | ||
#for item in test: | ||
#if item.endswith(".mp3"): | ||
#os.remove(os.path.join(os.getcwd(), item)) | ||
#if item.endswith(".zip"): | ||
#os.remove(os.path.join(os.getcwd(), item)) | ||
if __name__=='__main__': | ||
app.debug=True | ||
app.run(host="0.0.0.0",port=5000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<style> | ||
body { | ||
font-family:'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif; | ||
margin: 0; | ||
padding: 0; | ||
background-image: url('https://images.unsplash.com/photo-1470225620780-dba8ba36b745?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxleHBsb3JlLWZlZWR8MXx8fGVufDB8fHx8fA%3D%3D&w=1000&q=80'); | ||
background-size: cover; | ||
background-repeat: no-repeat; | ||
background-attachment: fixed; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: space-between; /* Adjust the vertical spacing */ | ||
min-height: 100vh; | ||
} | ||
|
||
.site-title { | ||
font-size: 24px; | ||
font-family:'Trebuchet MS', sans-serif; | ||
font-weight: bold; | ||
margin-top: 20px; /* Adjust the spacing from the top */ | ||
color: rgba(239, 42, 42, 0.8); /* Change the text color to contrast with the background */ | ||
} | ||
|
||
.made-by { | ||
font-size: 18px; | ||
margin-bottom: 20px; /* Adjust the spacing from the bottom */ | ||
color: rgb(255, 164, 27,0.9); /* Change the text color to contrast with the background */ | ||
} | ||
|
||
.form-container { | ||
background-color: rgba(123, 215, 238, 0.6); /* Semi-transparent white background */ | ||
padding: 20px; | ||
border-radius: 8px; | ||
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1); | ||
width: 300px; | ||
text-align: center; | ||
} | ||
|
||
label { | ||
font-family:Verdana, Geneva, Tahoma, sans-serif; | ||
display: block; | ||
margin-bottom: 6px; | ||
font-weight: bold; | ||
} | ||
|
||
input[type="text"], | ||
input[type="number"], | ||
input[type="email"] { | ||
width: 100%; | ||
padding: 10px; | ||
margin-bottom: 12px; | ||
border: 1px solid #ccc; | ||
border-radius: 4px; | ||
box-sizing: border-box; | ||
} | ||
|
||
input[type="submit"] { | ||
background-color: #007bff; | ||
color: #fff; | ||
border: none; | ||
padding: 10px 20px; | ||
border-radius: 4px; | ||
cursor: pointer; | ||
} | ||
|
||
input[type="submit"]:hover { | ||
background-color: #0056b3; | ||
} | ||
</style> | ||
<title>Songs Mashup</title> | ||
</head> | ||
<body> | ||
<div class="site-title"> | ||
Songs Mashup | ||
</div> | ||
<div class="form-container"> | ||
<form method="post"> | ||
<label for="singer">Singer Name:</label> | ||
<input type="text" id="singer" name="singer"> | ||
<br><br> | ||
<label for="Number_vid">Number of Videos:</label> | ||
<input type="number" id="Number_vid" name="Number_vid"> | ||
<br><br> | ||
<label for="duration">Duration of songs:</label> | ||
<input type="number" id="duration" name="duration"> | ||
<br><br> | ||
<label for="email">Email:</label> | ||
<input type="email" id="email" name="email"> | ||
<br><br> | ||
<input type="submit" value="Submit"> | ||
</form> | ||
</div> | ||
<div class="made-by"> | ||
Made By Abhijot Singh | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
body { | ||
margin: 0; | ||
padding: 0; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
min-height: 100vh; | ||
background-color: #f0f0f0; /* Change this to your desired background color */ | ||
} | ||
|
||
.center { | ||
width: 50%; | ||
max-width: 400px; | ||
padding: 20px; | ||
background-color: #ffffff; | ||
border-radius: 10px; | ||
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1); | ||
} | ||
|
||
.page-title { | ||
background-color: #007bff; | ||
color: #ffffff; | ||
text-align: center; | ||
padding: 10px; | ||
border-top-left-radius: 10px; | ||
border-top-right-radius: 10px; | ||
margin-bottom: 20px; /* Add some margin between title and form */ | ||
} | ||
|
||
.form-container { | ||
padding: 20px; | ||
} | ||
|
||
/* ... other CSS rules ... */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<style> | ||
body { | ||
font-family: Arial, sans-serif; | ||
margin: 0; | ||
padding: 0; | ||
background-image: url('https://images.unsplash.com/photo-1514320291840-2e0a9bf2a9ae?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=870&q=80'); | ||
background-size: cover; | ||
background-repeat: no-repeat; | ||
background-attachment: fixed; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: space-between; /* Adjust the vertical spacing */ | ||
min-height: 100vh; | ||
} | ||
|
||
h1 { | ||
font-size: 24px; | ||
font-family:'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif; | ||
font-weight: bold; | ||
margin: 10px 0; /* Adjust the vertical margin */ | ||
color: #F3FDE8cc; /* Change the text color to contrast with the background */ | ||
} | ||
</style> | ||
<title>Success</title> | ||
</head> | ||
<body> | ||
<h1>File Emailed Successfully</h1> | ||
</body> | ||
</html> |