Jeffgold commited on
Commit
3c753ee
·
1 Parent(s): 79683ca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -15
app.py CHANGED
@@ -36,41 +36,38 @@ aspect_ratio = gr.inputs.Dropdown(choices=[
36
 
37
  video_url = gr.inputs.Textbox(label="Video URL")
38
 
39
- def convert_video(video_file: dict, quality, aspect_ratio, video_url):
40
  # If a file was uploaded
41
  if video_file is not None:
42
  # Get the file extension
43
- file_extension = video_file['name'].split(".")[-1]
44
 
45
  # Define output file name
46
- output_file_name = video_file['name'][:-len(file_extension)] + ".m3u8"
47
 
48
- # Write the uploaded file to the temporary directory
49
- with open(os.path.join(temp_dir, video_file['name']), 'wb') as f:
50
- f.write(video_file['content'])
51
-
52
- input_path = os.path.join(temp_dir, video_file['name'])
53
 
54
  # If a URL was provided
55
  elif video_url is not None:
 
 
 
56
  # Get the file extension
57
- file_extension = video_url.split(".")[-1]
58
 
59
  # Define output file name
60
- output_file_name = video_url.split("/")[-1][:-len(file_extension)] + ".m3u8"
61
 
62
  # Download the file to the temporary directory
63
  response = requests.get(video_url)
64
 
65
  if response.status_code == 200:
66
- with open(os.path.join(temp_dir, output_file_name), 'wb') as f:
67
- f.write(response.content)
68
-
69
  input_path = os.path.join(temp_dir, output_file_name)
 
 
70
  else:
71
  print("Failed to download file from URL.")
72
  return None
73
-
74
  else:
75
  print("No input was provided.")
76
  return None
@@ -82,7 +79,6 @@ def convert_video(video_file: dict, quality, aspect_ratio, video_url):
82
  if os.path.exists(output_path):
83
  # The file already exists, so we can just display it in the output viewer
84
  return gr.outputs.File(output_path, label="Download")
85
-
86
  else:
87
  # The file does not exist, so we need to convert it
88
  ffmpeg_command = f"ffmpeg -i {input_path} -c:v libx264 -crf {quality} -vf scale=-1:720,setsar=1:1 -hls_time 6 -hls_playlist_type vod -f hls {output_path}"
 
36
 
37
  video_url = gr.inputs.Textbox(label="Video URL")
38
 
39
+ def convert_video(video_file, quality, aspect_ratio, video_url):
40
  # If a file was uploaded
41
  if video_file is not None:
42
  # Get the file extension
43
+ file_extension = video_file.name.split(".")[-1]
44
 
45
  # Define output file name
46
+ output_file_name = video_file.name[:-len(file_extension)] + ".m3u8"
47
 
48
+ input_path = video_file.name
 
 
 
 
49
 
50
  # If a URL was provided
51
  elif video_url is not None:
52
+ # Get the file name from URL
53
+ file_name = video_url.split("/")[-1]
54
+
55
  # Get the file extension
56
+ file_extension = file_name.split(".")[-1]
57
 
58
  # Define output file name
59
+ output_file_name = file_name[:-len(file_extension)] + ".m3u8"
60
 
61
  # Download the file to the temporary directory
62
  response = requests.get(video_url)
63
 
64
  if response.status_code == 200:
 
 
 
65
  input_path = os.path.join(temp_dir, output_file_name)
66
+ with open(input_path, 'wb') as f:
67
+ f.write(response.content)
68
  else:
69
  print("Failed to download file from URL.")
70
  return None
 
71
  else:
72
  print("No input was provided.")
73
  return None
 
79
  if os.path.exists(output_path):
80
  # The file already exists, so we can just display it in the output viewer
81
  return gr.outputs.File(output_path, label="Download")
 
82
  else:
83
  # The file does not exist, so we need to convert it
84
  ffmpeg_command = f"ffmpeg -i {input_path} -c:v libx264 -crf {quality} -vf scale=-1:720,setsar=1:1 -hls_time 6 -hls_playlist_type vod -f hls {output_path}"