Adding save option on youtube search.

This commit is contained in:
Anonymous Raccoon
2018-05-12 18:46:49 +02:00
parent 0c28e46368
commit 609bce0e4d
3 changed files with 48 additions and 41 deletions
+1 -40
View File
@@ -241,46 +241,7 @@ namespace MusicApp.Resources.Portable_Class
{
string url = view.FindViewById<EditText>(Resource.Id.playlistURL).Text;
string playlistID = url.Substring(url.IndexOf('=') + 1);
ChannelSectionsResource.ListRequest forkedRequest = YoutubeEngine.youtubeService.ChannelSections.List("snippet,contentDetails");
forkedRequest.Mine = true;
ChannelSectionListResponse forkedResponse = await forkedRequest.ExecuteAsync();
foreach (ChannelSection section in forkedResponse.Items)
{
if (section.Snippet.Title == "Saved Playlists")
{
//AddToSection
if (section.ContentDetails.Playlists.Contains(playlistID))
{
Snackbar.Make(Activity.FindViewById<View>(Resource.Id.snackBar), "You've already added this playlist.", 1).Show();
return;
}
else
{
section.ContentDetails.Playlists.Add(playlistID);
ChannelSectionsResource.UpdateRequest request = YoutubeEngine.youtubeService.ChannelSections.Update(section, "snippet,contentDetails");
ChannelSection response = await request.ExecuteAsync();
Refresh();
return;
}
}
}
//CreateSection and add to it
ChannelSection newSection = new ChannelSection();
ChannelSectionContentDetails details = new ChannelSectionContentDetails();
ChannelSectionSnippet snippet = new ChannelSectionSnippet();
details.Playlists = new List<string>() { playlistID };
snippet.Title = "Saved Playlists";
snippet.Type = "multiplePlaylists";
snippet.Style = "horizontalRow";
newSection.ContentDetails = details;
newSection.Snippet = snippet;
ChannelSectionsResource.InsertRequest insert = YoutubeEngine.youtubeService.ChannelSections.Insert(newSection, "snippet,contentDetails");
ChannelSection insertResponse = await insert.ExecuteAsync();
await YoutubeEngine.ForkPlaylist(playlistID);
Refresh();
})
.Show();
@@ -813,6 +813,48 @@ namespace MusicApp.Resources.Portable_Class
insertRequest.Execute();
}
public static async Task ForkPlaylist(string playlistID)
{
ChannelSectionsResource.ListRequest forkedRequest = youtubeService.ChannelSections.List("snippet,contentDetails");
forkedRequest.Mine = true;
ChannelSectionListResponse forkedResponse = await forkedRequest.ExecuteAsync();
foreach (ChannelSection section in forkedResponse.Items)
{
if (section.Snippet.Title == "Saved Playlists")
{
//AddToSection
if (section.ContentDetails.Playlists.Contains(playlistID))
{
Snackbar.Make(MainActivity.instance.FindViewById<View>(Resource.Id.snackBar), "You've already added this playlist.", 1).Show();
return;
}
else
{
section.ContentDetails.Playlists.Add(playlistID);
ChannelSectionsResource.UpdateRequest request = youtubeService.ChannelSections.Update(section, "snippet,contentDetails");
ChannelSection response = await request.ExecuteAsync();
return;
}
}
}
//CreateSection and add to it
ChannelSection newSection = new ChannelSection();
ChannelSectionContentDetails details = new ChannelSectionContentDetails();
ChannelSectionSnippet snippet = new ChannelSectionSnippet();
details.Playlists = new List<string>() { playlistID };
snippet.Title = "Saved Playlists";
snippet.Type = "multiplePlaylists";
snippet.Style = "horizontalRow";
newSection.ContentDetails = details;
newSection.Snippet = snippet;
ChannelSectionsResource.InsertRequest insert = youtubeService.ChannelSections.Insert(newSection, "snippet,contentDetails");
ChannelSection insertResponse = await insert.ExecuteAsync();
}
public static async void RandomPlay(string playlistID)
{
List<Song> tracks = new List<Song>();
@@ -94,7 +94,7 @@ namespace MusicApp.Resources.Portable_Class
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.instance, MainActivity.dialogTheme);
builder.SetTitle("Pick an action");
builder.SetItems(new string[] { "Random play", "Download" }, (senderAlert, args) =>
builder.SetItems(new string[] { "Random play", "Save To Youtube", "Download" }, (senderAlert, args) =>
{
switch (args.Which)
{
@@ -102,6 +102,10 @@ namespace MusicApp.Resources.Portable_Class
YoutubeEngine.RandomPlay(playlist.GetPath());
break;
case 1:
#pragma warning disable CS4014
YoutubeEngine.ForkPlaylist(playlist.GetPath());
break;
case 2:
YoutubeEngine.DownloadPlaylist(playlist.GetPath());
break;
default: