Skip to content

Commit

Permalink
check some nulls errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
Manurocker95 committed Jan 7, 2020
1 parent 2d122cd commit 9a196d0
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 13 deletions.
16 changes: 15 additions & 1 deletion Assets/YoutubePlayer/Scripts/DownloadYoutubeVideo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ private void Start()

public async void Download()
{
if (string.IsNullOrEmpty(youtubePlayer.youtubeUrl))
{
return;
}

YoutubePlayer.OnDownloading.Invoke();

try
Expand All @@ -37,7 +42,7 @@ public async void Download()

var v = (useDataPath ? System.IO.Directory.GetCurrentDirectory() : Environment.GetFolderPath(destination)) + @"/Recordings/ExtractedVideo";

if (Directory.Exists(v))
if (!Directory.Exists(v))
Directory.CreateDirectory(v);

var videoDownloadTask = youtubePlayer.DownloadVideoAsync(v, null, this);
Expand Down Expand Up @@ -73,6 +78,15 @@ private void Update()
{
if (downloadProgress)
downloadProgress.fillAmount = progress;

if (Input.GetKeyDown(KeyCode.F1))
{
var v = (useDataPath ? System.IO.Directory.GetCurrentDirectory() : Environment.GetFolderPath(destination)) + @"/Recordings/ExtractedVideo/";
if (!Directory.Exists(v))
Directory.CreateDirectory(v);

System.Diagnostics.Process.Start(Path.GetFullPath(v));
}
}
}
}
31 changes: 22 additions & 9 deletions Assets/YoutubePlayer/Scripts/YoutubeAudioDownload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void DownloadAudioAsync()

var v = (useDataPath ? System.IO.Directory.GetCurrentDirectory() : Environment.GetFolderPath(destination)) + @"/Recordings/";

if (Directory.Exists(v))
if (!Directory.Exists(v))
Directory.CreateDirectory(v);

var link1 = new LinkInfo(youtubePlayer.youtubeUrl);
Expand Down Expand Up @@ -91,7 +91,7 @@ public void DownloadAudioSync()

var v = (useDataPath ? System.IO.Directory.GetCurrentDirectory() : Environment.GetFolderPath(destination)) + @"/Recordings/";

if (Directory.Exists(v))
if (!Directory.Exists(v))
Directory.CreateDirectory(v);

var link1 = new LinkInfo(youtubePlayer.youtubeUrl);
Expand Down Expand Up @@ -147,7 +147,7 @@ public async void DownloadAudio()

var v = (useDataPath ? System.IO.Directory.GetCurrentDirectory() : Environment.GetFolderPath(destination)) + @"\Recordings\";

if (Directory.Exists(v))
if (!Directory.Exists(v))
Directory.CreateDirectory(v);

var link1 = new LinkInfo(youtubePlayer.youtubeUrl);
Expand Down Expand Up @@ -210,7 +210,7 @@ void NewTest()

var v = (useDataPath ? System.IO.Directory.GetCurrentDirectory() : Environment.GetFolderPath(destination)) + @"\Recordings\";

if (Directory.Exists(v))
if (!Directory.Exists(v))
Directory.CreateDirectory(v);

var source = v;
Expand Down Expand Up @@ -250,7 +250,7 @@ async void OldDownload()
var bytes = await video.GetBytesAsync();
var v = (useDataPath ? System.IO.Directory.GetCurrentDirectory() : Environment.GetFolderPath(destination)) + @"/Recordings/";

if (Directory.Exists(v))
if (!Directory.Exists(v))
Directory.CreateDirectory(v);

var filePath = v + @"\" + video.FullName + ".mp3";
Expand Down Expand Up @@ -310,7 +310,7 @@ public async void DownloadVideoAndExtract()

var v = (useDataPath ? System.IO.Directory.GetCurrentDirectory() : Environment.GetFolderPath(destination)) + @"/Recordings/ExtractedAudio/";

if (Directory.Exists(v))
if (!Directory.Exists(v))
Directory.CreateDirectory(v);

try
Expand All @@ -319,8 +319,14 @@ public async void DownloadVideoAndExtract()
YoutubePlayer.OnEndDownload.Invoke();

string filename = Path.GetFileNameWithoutExtension(filePath);
//System.Diagnostics.Process.Start(Application.dataPath + "/convert.bat", $@"""{Application.dataPath}/MediaToolkit"" ""{v}{filename}.mp4"" ""{v}{filename}.mp3""");
System.Diagnostics.Process p = new System.Diagnostics.Process();
string audioname = $"{v}{filename}.mp3";
if (File.Exists(audioname))
{
File.Delete(audioname);
}

//System.Diagnostics.Process.Start(Application.dataPath + "/convert.bat", $@"""{Application.dataPath}/MediaToolkit"" ""{v}{filename}.mp4"" ""{v}{filename}.mp3""");
System.Diagnostics.Process p = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();

startInfo.CreateNoWindow = false;
Expand Down Expand Up @@ -366,7 +372,14 @@ private void Update()
if (downloadProgress)
downloadProgress.fillAmount = progress;


if (Input.GetKeyDown(KeyCode.F2))
{
var v = (useDataPath ? System.IO.Directory.GetCurrentDirectory() : Environment.GetFolderPath(destination)) + @"/Recordings/ExtractedAudio/";
if (!Directory.Exists(v))
Directory.CreateDirectory(v);

System.Diagnostics.Process.Start(Path.GetFullPath(v));
}
}
}
}
32 changes: 29 additions & 3 deletions Assets/YoutubePlayer/Scripts/YoutubePlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,26 @@ public class YoutubePlayer : MonoBehaviour
public bool paused = false;
public Text m_pauseTxt;
public KeyCode exitKey = KeyCode.Escape;
public KeyCode pauseResumeKey = KeyCode.Space;
public KeyCode pauseResumeKey = KeyCode.S;
public KeyCode playkey = KeyCode.Return;
public string defaultVideo = "https://www.youtube.com/watch?v=2oRxLgoNpRs";

private void Awake()
{
if (string.IsNullOrEmpty(m_inputField.text))
{
m_inputField.text = defaultVideo;
}

if (overrideURLWithInputField && !string.IsNullOrEmpty(m_inputField.text))
{
youtubeUrl = m_inputField.text;

}
else
{
youtubeUrl = "";
}

youtubeClient = new YoutubeClient();
videoPlayer = GetComponent<VideoPlayer>();
_slider.value = PlayerPrefs.GetFloat("YoutubeVolume", 1.0f);
Expand Down Expand Up @@ -97,7 +109,11 @@ private void OnApplicationQuit()

private async void OnEnable()
{

if (string.IsNullOrEmpty(youtubeUrl))
{
return;
}

if (videoPlayer.playOnAwake)
await PlayVideoAsync();
}
Expand All @@ -117,6 +133,11 @@ public void SetVolume()

public async void Play()
{
if (string.IsNullOrEmpty(youtubeUrl))
{
return;
}

paused = false;
await PlayVideoAsync();
}
Expand Down Expand Up @@ -171,6 +192,11 @@ public void Restart()

public void Pause()
{
if (string.IsNullOrEmpty(youtubeUrl))
{
return;
}

if (!paused)
{
m_pauseTxt.text = "Resume";
Expand Down

0 comments on commit 9a196d0

Please sign in to comment.