public SftpUploader(AppConfig conf) { this.config = conf; if (config.sftpEnabled) { AuthenticationMethod[] auths = new AuthenticationMethod[1]; if (String.IsNullOrWhiteSpace(config.sftpPrivateKeyPath)) { auths[0] = new PasswordAuthenticationMethod(config.sftpUsername, Utils.GetBytes(config.sftpPassword)); } else { try { PrivateKeyFile pkf = null; if (string.IsNullOrEmpty(config.sftpPassword)) { pkf = new PrivateKeyFile(config.sftpPrivateKeyPath); } else { pkf = new PrivateKeyFile(config.sftpPrivateKeyPath, config.sftpPassword); } auths[0] = new PrivateKeyAuthenticationMethod(config.sftpUsername, pkf); } catch (IOException) { Log.Error("Unable to read private key file: " + config.sftpPrivateKeyPath); return; } } connInfo = new ConnectionInfo(config.sftpRemoteServer, config.sftpUsername, auths); } }
public ConfigControl(AppConfig conf = null) { InitializeComponent(); config = conf; if(config == null) { config = new AppConfig(); } spotifyBitrate.Items.Clear(); spotifyBitrate.Items.Add(96); spotifyBitrate.Items.Add(160); spotifyBitrate.Items.Add(320); lameBitrate.Items.Clear(); lameBitrate.Items.Add(96); lameBitrate.Items.Add(128); lameBitrate.Items.Add(160); lameBitrate.Items.Add(192); lameBitrate.Items.Add(256); lameBitrate.Items.Add(320); Binding binding1 = new Binding("Checked", config, "sftpEnabled"); Binding binding2 = new Binding("Text", config, "sftpRemoteServer"); Binding binding3 = new Binding("Text", config, "sftpUsername"); Binding binding4 = new Binding("Text", config, "sftpPassword"); Binding binding7 = new Binding("Text", config, "sftpRemoteFolder"); Binding binding8 = new Binding("Text", config, "sftpPort"); Binding binding9 = new Binding("SelectedItem", config, "spotifyBitrate"); Binding binding10 = new Binding("SelectedItem", config, "lameBitrate"); sftpCheckbox.DataBindings.Add(binding1); sftpPasswordBox.DataBindings.Add(binding4); sftpPortBox.DataBindings.Add(binding8); sftpRemoteFolderBox.DataBindings.Add(binding7); sftpServerBox.DataBindings.Add(binding2); sftpUsernameBox.DataBindings.Add(binding3); spotifyBitrate.DataBindings.Add(binding9); lameBitrate.DataBindings.Add(binding10); folderBrowse.SelectedPath = (config.localBaseFolder != null ? config.localBaseFolder : ""); privateKeyBrowse.FileName = (config.sftpPrivateKeyPath != null ? config.sftpPrivateKeyPath : ""); }
static void DoConsole(string[] args) { nito.Do(() => { var options = new Options(); if (CommandLine.Parser.Default.ParseArguments(args, options)) { if (options.URL == null || options.URL.Length == 0) { Log.Error("Error: No URL specified"); return; } if (!Session.Login(options.Username, options.Password)) { Log.Error("Error: Bad credentials"); return; } AppConfig config = AppConfig.Load(); if (config == null) { config = new AppConfig(); } if (options.UseSftp != null) config.sftpEnabled = options.UseSftp.Value; if (options.LocalFolder != null) config.localBaseFolder = options.LocalFolder; if (options.SftpUsername != null) config.sftpUsername = options.SftpUsername; if (options.SftpPassword != null) config.sftpPassword = options.SftpPassword; if (options.SftpPort != null) config.sftpPort = options.SftpPort.Value; if (options.SftpServer != null) config.sftpRemoteServer = options.SftpServer; if (options.SftpKey != null) config.sftpPrivateKeyPath = options.SftpKey; if (options.SftpPath != null) config.sftpRemoteServer = options.SftpPath; config.spotifyBitrate = options.SpotifyBitrate; config.lameBitrate = options.LameBitrate; if (options.Save == true) config.Save(); Download(options.URL, config); } }); }
public static void Download(string url, AppConfig config) { nito.Do(() => { _confo = config; if (frm != null) frm.SetStatus("Download in progress..."); if (url != null && url.Length > 0) { IntPtr sess = Session.GetSessionPtr(); libspotify.sp_bitrate br; int delta96 = Math.Abs(config.spotifyBitrate - 96), delta160 = Math.Abs(config.spotifyBitrate - 160), delta320 = Math.Abs(config.spotifyBitrate - 320); br = libspotify.sp_bitrate.BITRATE_96k; if (delta160 < delta96) br = libspotify.sp_bitrate.BITRATE_160k; if (delta320 < delta160) br = libspotify.sp_bitrate.BITRATE_320k; Log.Debug("Set download bitrate to " + br.ToString()); libspotify.sp_session_preferred_bitrate(sess, br); IntPtr splink = Functions.StringToLinkPtr(url); if (libspotify.sp_link_type(splink) == libspotify.sp_linktype.SP_LINKTYPE_TRACK) { Log.Debug("Starting work on track " + url); IntPtr sptrack = libspotify.sp_link_as_track(splink); IntPtr sptrack2 = libspotify.sp_track_get_playable(sess, sptrack); if (Session.LoadPlayer(sptrack2) != libspotify.sp_error.OK) { Log.Error("Unable to load track player for " + url); } else { audioStreamComplete = false; _artist = Utils.Utf8ToString(libspotify.sp_artist_name(libspotify.sp_track_artist(sptrack2, 0))).Replace(":", ""); _album = Utils.Utf8ToString(libspotify.sp_album_name(libspotify.sp_track_album(sptrack2))).Replace(":", ""); _song = Utils.Utf8ToString(libspotify.sp_track_name(sptrack2)).Replace(":", ""); Log.Debug("Artist: " + _artist + "; Album: " + _album + "; Song: " + _song); outFile = new FileInfo(Path.Combine(config.localBaseFolder, _artist, _album, _artist + " - " + _song + ".mp3")); if(outFile.Exists) { new SftpUploader(_confo).go(outFile.FullName); } else { Log.Debug("Making directory " + Path.GetDirectoryName(outFile.FullName)); Directory.CreateDirectory(Path.GetDirectoryName(outFile.FullName)); libspotify.sp_session_player_prefetch(Session.GetSessionPtr(), sptrack2); Session.Play(); Log.Debug("Data is streaming!"); //if (outFile.Exists) // outFile.Delete(); } } } else { Log.Error("Error: Invalid link type!"); } } }); }