I've Vimeo PRO and I'm trying to get the download link so the end user can download the video source. However, the lack of documentation makes it really hard to figure that out.
I'm trying VimeoDotNet but I cannot authenticate, I'm doing the following:
var client = new VimeoClientFactory().GetVimeoClient(key, secret)
var downloadLink = client.GetVideo(video_id).download;
However, the call to GetVideo throws an error saying I have to authenticate first, but I don't see how!
I've also tried with another VimeoClient, but it doesn't seem to implement the download link part.
Can anyone help? Or better yet, share a working example. Thanks.
After 2 days I was finally able to do it, I'll share what I did in case someone needs it. First, download this library:
https://github.com/saeedafshari/VimeoDotNet3
Open in Visual Studio and compile it. It's pretty simple so it compiled right away.
Then reference that compiled DLL from your project and do the following:
var VimeoClient3 = Vimeo.VimeoClient.ReAuthorize(_vimeoAccessToken,
_vimeoAppConsumerKey, _vimeoAppClientSecret);
// videoId is the ID of the video as in the public URL (eg, 123874983)
var result = VimeoClient3.Request("/videos/" + videoId, null, "GET");
if (result == null)
{
throw new Exception("Video not found.");
}
if (result["download"] == null)
{
throw new Exception("Download link not available.");
}
foreach (var item in (ArrayList)result["download"])
{
var downloadLinkInfo = item as Dictionary<string, object>;
if (downloadLinkInfo == null) continue;
// For example, get the link for SD quality.
// As of today, Vimeo was returning an HD quality and a 'mobile' one
// that is for streaming.
if (string.Equals((downloadLinkInfo["quality"] as string), "sd", StringComparison.InvariantCultureIgnoreCase))
{
return downloadLinkInfo["link"] as string;
}
}
Related
Is there a way to get the whole Facebook friends list using an api!
I've tried a lot of thing and here's my shot:
FacebookClient f = new FacebookClient(access_token);
f.IsSecureConnection = true;
dynamic friendlist = await f.GetTaskAsync(#"https://graph.facebook.com/me/friendlists?access_token="+access_token);
t.Text = JsonConvert.SerializeObject(friendlist);
But all I got is an empty data!
Can anyone help me?
The friendlists endpoint is deprecated, as you can see in the breaking changes log: https://developers.facebook.com/docs/graph-api/changelog/breaking-changes#tagged-users-4-4
It would not have been what you expected anyway, it was only for lists, not friends directly. Access to all friends is not possible since a very long time. You can only get data of users/friends who authorized your App. You can use the /me/friends endpoint for that.
Another thread about getting all friends: Facebook Graph API v2.0+ - /me/friends returns empty, or only friends who also use my application
There is another way can give you an access to your all friend list names by downloading a copy of your facebook information data by selecting friends and following checkbox and wait till your file is ready then download it.
This is not the API way but for starters who want one time download list of friends
Go to the friend list page: https://www.facebook.com/friends/list
Scroll all the way down so that all friend list loads
Press F12 to open developer tools, click on console tab
A. Show in console
copy paste following script in console and hit enter.
var accumulated = "";
for (var el of document.querySelectorAll('[data-visualcompletion="ignore-dynamic"]')) {
var name = el.getAttribute("aria-label");
if(name!= null && name != "null"){
accumulated = "Name:"+name +", "+ accumulated;
console.log(accumulated);
accumulated = "";
}else{
var a = el.getElementsByTagName("a")[0];
if(a){
accumulated += "Profile URL: "+ a.getAttribute("href");
//console.log(a);
}
}
}
B. Download a .json file
copy paste following script in console and hit enter.
var exportObj = [];
var accumulated = "";
for (var el of document.querySelectorAll('[data-visualcompletion="ignore-dynamic"]')) {
var name = el.getAttribute("aria-label");
if(name!= null && name != "null"){
exportObj.push({name: name, profileURL: accumulated});
accumulated = "";
}else{
var a = el.getElementsByTagName("a")[0];
if(a){
accumulated += a.getAttribute("href");
}
}
}
var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(exportObj));
var downloadAnchorNode = document.createElement('a');
downloadAnchorNode.setAttribute("href", dataStr);
downloadAnchorNode.setAttribute("download", "friendsList.json");
document.body.appendChild(downloadAnchorNode);
downloadAnchorNode.click();
downloadAnchorNode.remove();
Note: pseudo code tested in firefox
I am using the TFS API to get latest code files, directories, .csproj files, etc. under a TFS-bound folder.
For the same, I use something like the following:
var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new
Uri(ConfigurationManager.AppSettings["TFSUrl"]));
tfs.EnsureAuthenticated();
var vsStore = tfs.GetService<VersionControlServer>();
string workingFolder = #"C:\TFS\SolutionFolder";
Workspace wsp = vsStore.TryGetWorkspace(workingFolder);
if (wsp != null)
{
ItemSet items = vsStore.GetItems(workingFolder, VersionSpec.Latest, RecursionType.Full);
string relativePath = workingFolder + #"/";
foreach (Item item in items.Items)
{
string relativePath1 = item.ServerItem.Replace("$/TFS/SolutionFolder", relativePath);
if (item.ItemType == ItemType.Folder)
{
Directory.CreateDirectory(relativePath1);
}
else
{
item.DownloadFile(relativePath1);
}
}
}
Now, I get the items to download and then download happens. However, I want it to be like how VS handles it - if (and only if) there is a change in a file/folder, then only download the same. With this code, I always get 'n' number of files/folders in that folder and then I overwrite the same. Wrong approach, I know. I can, however, modify this code to check for the folder's or file's last change time and then choose to either overwrite it or ignore it. That's an option, albeit a bad one at that.
Now, what I would ideally like is to get ONLY the list of files/folders that actually need to be changed i.e. the incremental change. After that, I can choose to overwrite/ignore each item in that list. So, in the present case, if a new file/folder is created (or one of the existing ones got changed inside $/TFS/SolutionFolder i.e. in the sever), then only I want to pull that item in the list of files/folders to change(and decide what I want to do with it inside C:\TFS\SolutionFolder).
Also, is using one of the overloads of VersionControlServer.QueryHistory() an option? I had something like this:
(latestVersionIdOf $/TFS/SolutionFolder) - (existingVersionIdOf C:\TFS\SolutionFolder) = (Versions that I'd go out and get back from the server, for that folder)
in mind.
Any pointers will be very helpful. Thanks!
Just use Workspace.Get() or overload method (wsp.Get()), it just update updated files.
I don't think we can achieve that. If the files are downloaded to a folder without in source control, there are no versions compared within the folder, even if the folder is in source control, the behavior is just download also no version compare actions. So, it will download all the files ever time and then overwrite the same ones.
In VS, the files are all in TFS source control system, so when we Get Latest Version the changed/added files will be retrieved from TFS. If you want to get the same behavior as VS handles, you can use the tf get command. See Get Command
You can reference this article to use the tf get command :
get-latest-version-of-specific-files-with-tfs-power-tools
Update :-
var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(ConfigurationManager.AppSettings["TFSUrl"]));
tfs.EnsureAuthenticated();
var vsStore = tfs.GetService<VersionControlServer>();
string workingFolder = ConfigurationManager.AppSettings["LocalPathToFolder"]; // C:\TFS\SolutionFolder
string tfsPathToFolder = ConfigurationManager.AppSettings["TFSPathToFolder"]; // $/TFS/SolutionFolder
Workspace wsp = vsStore.GetWorkspace(workingFolder);
if (wsp != null)
{
ItemSpec[] specs = { new ItemSpec(tfsPathToFolder, RecursionType.Full) };
ExtendedItem[][] extendedItems = wsp.GetExtendedItems(specs, DeletedState.NonDeleted, ItemType.Any);
ExtendedItem[] extendedItem = extendedItems[0];
var itemsToDownload = extendedItem.Where(itemToDownload => itemToDownload.IsLatest == false);
foreach (var itemToDownload in itemsToDownload)
{
try
{
switch (itemToDownload.ItemType)
{
case ItemType.File:
if (itemToDownload.LocalItem != null)
{
vsStore.DownloadFile(itemToDownload.SourceServerItem, itemToDownload.LocalItem);
}
else
{
string localItemPath = itemToDownload.SourceServerItem.Replace(tfsPathToFolder,
workingFolder);
vsStore.DownloadFile(itemToDownload.SourceServerItem, localItemPath);
}
break;
case ItemType.Folder:
string folderName = itemToDownload.SourceServerItem.Replace(tfsPathToFolder, workingFolder);
if ((!string.IsNullOrEmpty(folderName)) && (!Directory.Exists(folderName)))
{
Directory.CreateDirectory(folderName);
}
break;
}
}
catch (Exception e)
{
File.AppendAllText(#"C:\TempLocation\GetLatestExceptions.txt", e.Message);
}
}
}
This code works well, except:
a. Whenever it downloads the latest copy of, let's say a file, it 'checks it out' in TFS :(
b. For some items, it throws errors like 'Item $/TFS/SolutionFolder/FolderX/abc.cs was not found in source control at version T.' - I have to find out what the exact cause of this issue is, though.
Any ideas on how to get around these two issues or any other problems you see with this code? Thanks!
I am trying to copy a blob from one location to another and it seems like this method is obsolete. Everything I've read says I should use "StartCopy". However, when I try this it doesn't copy the blob. I just get a 404 error at the destination.
I don't seem to be able to find any documentation for this. Can anyone advise me on how to do this in the latest version of the API or point me in the direction of some docs.
Uri uploadUri = new Uri(destinationLocator.Path);
string assetContainerName = uploadUri.Segments[1];
CloudBlobContainer assetContainer =
cloudBlobClient.GetContainerReference(assetContainerName);
string fileName = HttpUtility.UrlDecode(Path.GetFileName(model.BlockBlob.Uri.AbsoluteUri));
var sourceCloudBlob = mediaBlobContainer.GetBlockBlobReference(fileName);
sourceCloudBlob.FetchAttributes();
if (sourceCloudBlob.Properties.Length > 0)
{
IAssetFile assetFile = asset.AssetFiles.Create(fileName);
var destinationBlob = assetContainer.GetBlockBlobReference(fileName);
destinationBlob.DeleteIfExists();
destinationBlob.StartCopyFromBlob(sourceCloudBlob);
destinationBlob.FetchAttributes();
if (sourceCloudBlob.Properties.Length != destinationBlob.Properties.Length)
model.UploadStatusMessage += "Failed to copy as Media Asset!";
}
I'm just posting my comment as the answer to make it easier to see.
It wasn't the access level of the container. It wasn't anything to do with StartCopy either. It turned out to be these lines of code.
var mediaBlobContainer = cloudBlobClient.GetContainerReference(cloudBlobClient.BaseUri + "temporarymedia");
mediaBlobContainer.CreateIfNotExists();
Apparently I shouldn't be supplying the cloudBlobClient.BaseUri, just the name temporarymedia.
var mediaBlobContainer = cloudBlobClient.GetContainerReference("temporarymedia");
There was no relevant error message though. Hopefully it'll save another Azure newbie some time in future.
I'm developing a Windows Phone app that needs to retrieve and manipulate information about the songs played on the device.
I know it is possible to get the song that is currently playing using MediaPlayer.Queue.ActiveSong.
However, what I really need is to have access to a list of recently played tracks.
MediaHistory and MediaHistoryItem classes don't seem to provide this.
Is is really possible? How?
The current API, as #Igor has pointed out in his answer does not allow this. However, there is another way for us to reasonably assume that a particular media file has been played recently, by getting some information about the actual file.
We can use GetBasicPropertiesAsync() along with RetrievePropertiesAsync() which will give us the DateAccessed property for that file.
Here is a code snippet taken from this MSDN page:
public async void test()
{
try
{
StorageFile file = await StorageFile.GetFileFromPathAsync("Filepath");
if (file != null)
{
StringBuilder outputText = new StringBuilder();
// Get basic properties
BasicProperties basicProperties = await file.GetBasicPropertiesAsync();
outputText.AppendLine("File size: " + basicProperties.Size + " bytes");
outputText.AppendLine("Date modified: " + basicProperties.DateModified);
// Specify more properties to retrieve
string dateAccessedProperty = "System.DateAccessed";
string fileOwnerProperty = "System.FileOwner";
List<string> propertiesName = new List<string>();
propertiesName.Add(dateAccessedProperty);
propertiesName.Add(fileOwnerProperty);
// Get the specified properties through StorageFile.Properties
IDictionary<string, object> extraProperties = await file.Properties.RetrievePropertiesAsync(propertiesName);
var propValue = extraProperties[dateAccessedProperty];
if (propValue != null)
{
outputText.AppendLine("Date accessed: " + propValue);
}
propValue = extraProperties[fileOwnerProperty];
if (propValue != null)
{
outputText.AppendLine("File owner: " + propValue);
}
}
}
// Handle errors with catch blocks
catch (FileNotFoundException)
{
// For example, handle a file not found error
}
}
Once you have the DateAccessed property in a variable, we can see if it is a recent date, say, yesterday, or maybe even 2 or 3 days ago. Then we'll know that if it's been accessed within a short period of time, it could have been played.
There are some caveats to this, though. Some virus scanners change the Timestamp properties on files and folders, and they also need to open files to scan them which I would assume would change the DateAccessed property. However, many new Antivirus apps that I've seen revert the Timestamp info back to the original, as if it had never touched the file.
I believe this is the best workaround for this problem at the moment. Unless you only care about when your app recently played a file. Then the answer to that question is as simple as you managing your own recently-played lists for media files.
Update
In order to retrieve the PlayCount for a specified song, you can access that song using the MediaLibrary class:
MediaLibrary library = new MediaLibrary();
Then just access the song like this:
Int32 playCount = library.Songs[0].PlayCount;
where [0] is the index of the song you'd like to get the PlayCount for. An easier way (depending on how you're accessing songs already, might be to do something like:
Int32 playCount = library.Artists[selectedArtistIndex].Albums[selectedArtistAlbumIndex].Songs[selectedSongInAlbumIndex].PlayCount;
Not possible with the current API. MediaHistoryItem only returns last item set by your application, so it is of no use.
I need to create a qrreader with windows phone.
Xzing examples only print to video the qr string captured,
I need an example of how to understand if this string is a vcard and, consequently, save it in contact, or if it is a link and open it in the browser.
private void ScanPreviewBuffer()
{
try
{
_photoCamera.GetPreviewBufferY(_luminance.PreviewBufferY);
var binarizer = new HybridBinarizer(_luminance);
var binBitmap = new BinaryBitmap(binarizer);
var result = _reader.decode(binBitmap);
Dispatcher.BeginInvoke(() => CheckQr(result.Text));
}
catch { }
}
private void CheckQr(string qrString)
{
VibrateController vibrate = VibrateController.Default;
vibrate.Start(TimeSpan.FromMilliseconds(500));
MessageBox.Show(qrString);
/* CONTROLS HERE */
}
Obviously you have to start by parsing the qrString content to get what you want, i think we'll both agree on that point ;)
So the main issues are :
Determining formats (url or vcard)
Parsing them (if needed)
Using them to trigger wanted actions
1. About vCard
To determine if you qrString holds a vCard, maybe you could just try to match (with string.Contains or string.StartsWith methods) the vCard header which is BEGIN:VCARD and always seems to be the same from one version to another (see wikipedia).
For Windows Phone 7, there's no builtin features to parse vCards, so you have to do it by yourself or you could try to use the vCard library For Windows Phone. It would be used this way :
byte[] byteArray = Encoding.UTF8.GetBytes(qrString);
using (StreamReader reader = new StreamReader(new MemoryStream(byteArray)))
{
vCard card = new vCard(reader);
// access here card.PropertyFromvCard to get the information you need
}
There's not so much documentation about it, but sources are available on codeplex, so you'll probably find all the property names and samples you need.
For Windows Phone 8, the builtin ContactInformation.ParseVcardAsync method could help you to parse your qrString content (here is an official tutorial)
Then you need to finally create your contact :
If you're developping your App on Windows Phone 7, there's no way to create a contact directly from your application. You need to use the "save contact task" and pre-populate the fields you need. Here's an example :
SaveContactTask saveContactTask = new SaveContactTask();
saveContactTask.Completed += new EventHandler<SaveContactResult>(saveContactTask_Completed);
saveContactTask.FirstName = "John"; // card.PropertyFromvCard and so on...
saveContactTask.LastName = "Doe";
saveContactTask.MobilePhone = "2065550123";
saveContactTask.Show();
If you're developping on Windows Phone 8 (and it doesn't seem to be the case given your question tags), you can create a Custom contact store and write directly into it
2. About URLs
To know if you're dealing with an URL or not, i would advice you to follow suggestions coming with this SO answer. To make a long story short, here's the code you could use or at least something similar :
static bool IsValidUrl(string qrString)
{
Uri uri;
return Uri.TryCreate(urlString, UriKind.Absolute, out uri)
&& (uri.Scheme == Uri.UriSchemeHttp
|| uri.Scheme == Uri.UriSchemeHttps
|| uri.Scheme == Uri.UriSchemeFtp
|| uri.Scheme == Uri.UriSchemeMailto
/*...*/);
}
And finally to open your URL into a web browser (if it is a valid one of course), you could use the WebBrowser task or embed a true WebBrowser into your application with the WebBrowser control and make good use of it.
ZXing has a class called ResultParser with a static method parseResult.
The ResultParser supports some common content formats like vCard, vEvent, URL, etc.
It gives you as a result an instance of AddressBookParsedResult for vCard content back.
ParsedResult parsedResult = ResultParser.parseResult(result);