iTunes search API undefined first result - json

Hi I'm struggling for a long time with the itunes api album listing.
My issue is the thumbnail and album title in the first <li></li> always comes back as undefined.
The code is based on itunes artist search which works as intended, but my version for album listing always gives this glitch.
$(document).ready(function(){
var searchTerm = '909253';
$.getJSON( "http://itunes.apple.com/lookup?id=" + searchTerm + '&limit=30' + '&entity=album' + '&callback=?', function(data) {
$.each(data.results, function() {
$('<li></li>')
.hide()
.append('<img src="' + this.artworkUrl60 + '" />' )
.append('<span><a href="http://itunes.apple.com/search?term='
+ this.artistName + '">' + 'Artist: ' + this.artistName
+ '</a> ' + '<br />Album Title: ' + this.collectionName + '</span>')
.appendTo('#results')
.fadeIn();
});
$("#results").listview("refresh");
});
});
​
See http://jsfiddle.net/tris_wood/u2sYe/2/
I've seen similar posts with this issue wth the itunes api but no solutions that I could find.
Any help would be greatly appreciated.

This is because the first returned element is always the parent element, in this case the artist.
If you request:
http://itunes.apple.com/lookup?id=909253&entity=album
You will get (as you can see in wrapperType):
0) Artist information
1) First album
2) Second album
Unfortunately your code is temporary offline at the moment and I can't check if my intuition is correct.

Related

Trouble Adding Array output to an Dynamically Generated HTML String in GAS Google Script

I am trying to automate my businesses blog. I want to create a dynamic html string to use as a wordpress blog description. I am pulling text data from email body's in my gmail account to use as information. I parse the email body using the first function below.
I have everything working properly except for the for loop (in the second code block) creating the description of the post. I have searched for hours and tried dozens of different techniques but I cant figure it out for the life of me.
Here is how I am reading the text values into an array:
function getMatches(string, regex, index) {
index || (index = 1); // default to the first capturing group
var matches = [];
var match;
while (match = regex.exec(string)) {
matches.push(match[index]);
}
return matches;
}
This is how I am trying to dynamically output the text arrays to create a basic HTML blogpost description (which I pass to xmlrpc to post):
var1 = getMatches(string, regex expression, 1);
var2 = getMatches(string, regex expression, 1);
var3 = getMatches(string, regex expression, 1);
var3 = getMatches(string, regex expression, 1);
var fulldesc = "<center>";
var text = "";
for (var k=0; k<var1.length; k++) {
text = "<u><b>Var 1:</u></b> " + var1[k] + ", <u><b>Var 2:</u></b> " + var2[k] + ", <u><b>Var 3:</u></b> " + var3[k] + ", <u><b>Var 4:</u></b> " + var4[k] + ", <br><br>";
fulldesc += text;
}
fulldesc += "</center>";
Lastly here is the blog post description code (using GAS XMLRPC library):
var fullBlog = "<b><u>Headline:</u> " + sub + "</b><br><br>" + fulldesc + "<br><br>General Description: " + desc;
var blogPost = {
post_type: 'post',
post_status: 'publish', // Set to draft or publish
title: 'Ticker: ' + sub, //sub is from gmail subject and works fine
categories: cat, //cat is defined elsewhere and works fine
date_created_gmt: pubdate2, //defined elsewhere (not working but thats another topic)
mt_allow_comments: 'closed',
description: fullBlog
};
request.addParam(blogPost);
If there's only one value in the var1,2,3,4 arrays all works as it should. But any more than 1 value and I get no output at all from the "fulldesc" var. All other text variables work as they should and the blog still gets posted (just minus some very important information). I'm pretty sure the problem lies in my for loop which adds the HTML description to text var.
Any suggestions would be greatly appreciated, I'm burned out trying to get the answer! I am a self taught programmer (just from reading this forum) so please go easy on me if I missed something stupid :)
Figured it out: It wasnt the html/text loop at all. My blogpost title had to be a variable or text, but not both.
Not working:
title: 'Ticker: ' + sub, //sub is from gmail subject and works fine
Working:
var test = 'Ticker: ' + sub;
//
title:test,

jquery button works fine first time but second time not working

I created a very simple index.html file and inside I included some jquery script. You can see below:
<script>
$(document).ready(function(){
var $tweets = $('.tweets');
var current_position = -1;
function getTweets(){
var index = streams.home.length - 1;
var cp = index;
while(index >= current_position + 1){
var tweet = streams.home[index];
$tweets.append('<div class="twe"><span class="name" style="color:blue">' + '#' + tweet.user + ': ' + ' </span><span class="message">' + tweet.message + tweet.created_at + '</span></div>');
index--;
}
current_position = cp;
}
getTweets();
$('button').click(function(){
getTweets();
});
$('.name').click(function(){
$tweets.prepend('<div>' + 'objname' + streams.home.length + '</div>');
});
});
</script>
there is one button used for updates all the tweets and dynamically put them in the section with class="tweets" part. And this button works fine no matter how many times I press it.
Then I add click event to all those with class name 'name' and once I click it , it will add 'objname' + streams.home.length to the front of my
section class="tweets" part. The problem is first time , I CLICK the $('.name') it works fine , but later after I added more items through $('button') click event. it seems the new created $('.name') items is not clickable which means they don't generate 'objname' + streams.home.length to the front of my
section with class="tweets" part. I am really confused here and don't know why.
try following
$("body").on("click",".name",function(){
$tweets.prepend('<div>' + 'objname' + streams.home.length + '</div>');
});
As your element gets added runtime on the page, it needed to be taken care separately with help of "on" which bind events automatically when event gets created.
check reference

How to get the map zoom action on Ti.map

There are articles about ti.map.
Map
View
I found some entry about zoom.
However I couldn't figure out how to get the map zoom level,
when user pinch the maps on devices.
I tried like this but in vain.
var mapView = Map.createView({
mapType:Map.NORMAL_TYPE,
userLocation:true,
region: {latitude:35.699058, longitude:139.326099,
latitudeDelta:0.01, longitudeDelta:0.01},
animate:false,regionFit:true,
userLocation:true,
});
mapView.addEventListener('pinch', function(evt) {
Ti.API.info("pinch " + evt);
//This is not fired.
});
mapView.addEventListener('click', function(evt) {
Ti.API.info("Clicked " + evt.clicksource + " on " + evt.latitude + "," + evt.longitude);
// This is fired.
});
Thanks to #Fokke Zandbergen's help
I solve the problem.
mapView.addEventListener('regionChanged',function(evt){
Ti.API.info('regionchanged delta lati,longi ' + evt.latitudeDelta + "," + evt.longitudeDelta);
if (evt.latitudeDelta > 0.020){
// do something.
}
});
I think you can achieve your goal by listening to the regionchanged event of the view. You'll get the region displayed, but there's zoom level. Depending on what you need it for you'll have to use the region to calculate that yourself.

Request details about a specific torrent using Kickass Json api

I have used https://kat.cr/json.php?q=test to request Json that list the torrents that where found by the given query. That works fine but, I haven't been able to find any documentation for the api. So I hoped that some of you may know how to request detailed information about a torrent such as its description, file names, comments and so on.
Thanks in advance!
Just type some parameter:
base_url: https://kat.cr/json.php
if search by category:
base_url+"category:'+category_name+' '+keyword;
//seads:
base_url+'seeds:'+seeds;
//tv:
base_url+'tv:'+tvrange+' '+keyword;
//imdb:
base_url+'imdb:'+query_imdb+' '+keyword;
And code from api:
if (typeof query === 'string') {
queryParams = { q: query };
} else {
queryParams.q = query.query || '';
if (query.category) queryParams.q += ' category:' + query.category;
if (query.min_seeds) queryParams.q += ' seeds:' + query.min_seeds;
if (query.uploader) queryParams.q += ' user:' + query.uploader;
if (query.age) queryParams.q += ' age:' + query.age;
if (query.safety_filter) queryParams.q += ' is_safe:' + query.safety_filter;
if (query.verified) queryParams.q += ' verified:' + query.verified;
if (query.language) queryParams.q += ' lang_id:' + filteredLangCode(query.language);
if (query.imdb) queryParams.q += ' imdb:' + query.imdb.replace(/\D/g,'');
if (query.tvrage) queryParams.q += ' tv:' + query.tvrage;
if (query.sort_by) queryParams.field = query.sort_by;
if (query.order) queryParams.order = query.order;
if (query.page) queryParams.page = query.page;
}
I was also interested in this. I found a NodeJS library floating around: https://github.com/isdampe/kat-api
However digging into the code, it seems to follow your example of making a GET to the url above, and then parsing out the results, for specific params.
What specifically were you looking to do? Was there certain params you only wanted to search for/pull back?

Show link in html table cell

I'm tring to add a link in my code like below,I have written a javascript function,thing is in UI it has to show data as link.
string str="" + dataTable.Rows[i][j] + ""
Is there a way to show my datatable data as a link in UI?
Reply
assuming that your dataTable[i][j] is the link .. we can simply do this in javascript to create a link
link = '<a href="' + dataTable[i][j] + '" >Link</a>';
then use this string wherever you want.
or as i just saw the updated question
'<td>' + dataTable[i][j] + '</td>'
Where is the start of the anchor (<a ...>) tag? There is only an end one. Try...
<td>{link}</td>