-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
64 lines (55 loc) · 2.4 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import gradio as gr
import urllib
from urllib.parse import urlparse, parse_qs
from playlist_duration import playlist_duration_func
from average_duration import playlist_average_duration_func
from playlists_mismatch import playlists_mismatch_func
def playlist_duration_calculator(playlist_link, calculation_type):
if calculation_type == "Total Duration":
result = playlist_duration_func(playlist_link)
return f"Total Duration: {result}"
elif calculation_type == "Average Duration":
result = playlist_average_duration_func(playlist_link)
return f"Average Duration: {result}"
heading = "YouTube Playlist Duration Calculator"
description = '''Enter a YouTube playlist link to calculate its total duration or average duration.\n
Do not enter the link of a video that belongs to that playlist.\n
Use the link in the share option of the playlist's page
'''
duration_interface = gr.Interface(
fn=playlist_duration_calculator,
inputs=[
gr.Textbox(label="Playlist Link"),
gr.Radio(["Total Duration", "Average Duration"], label="What to calculate?")
],
outputs=gr.Textbox(label="Result"),
title=heading,
description=description
)
second_heading = "YouTube Playlist Mismatch Calculator"
second_description = "Enter two YouTube playlist links to compare their contents and find the mismatch."
def playlist_mismatch_calculator(playlist_link_1, playlist_link_2, output_options):
result = playlists_mismatch_func(playlist_link_1, playlist_link_2, output_options)
playlist1name = result[2]
playlist2name = result[3]
text = 'Present in {}, not in {} :- \n{} \n \nPresent in {}, not in {} :-\n {}'.format(
playlist1name, playlist2name, '\n'.join(result[0]),
playlist2name, playlist1name, '\n'.join(result[1])
)
return f"Mismatch Result between the two playlists are as follows: -\n\n{text}"
mismatch_interface = gr.Interface(
fn=playlist_mismatch_calculator,
inputs=[
gr.Textbox(label="Playlist Link 1"),
gr.Textbox(label="Playlist Link 2"),
gr.Radio(["id", "link", "name"], label="Output Options")
],
outputs=gr.Textbox(label="Mismatch between two playlists"),
title=second_heading,
description=second_description
)
combined_interface = gr.TabbedInterface(
[duration_interface, mismatch_interface],
['Playlist Total and Average Duration', 'Playlist Mismatch']
)
combined_interface.launch()