Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#11 2020-08-15 09:49:58

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,269
Website

Re: size limitation in forms?

Bloke wrote #325369:

Yes! There’s soooo much duplication in that <txp::media> shortcode. There has to be a way of refactoring it somehow to help the poor parser out. My site’s memory usage went into meltdown when I added a video to it :)

Stay tuned for v2 in the next couple of weeks:)


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github | Covid-19; a resource
I do my best editing after I click on the submit button.

Offline

#12 2020-08-15 11:02:37

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,721
Website

Re: size limitation in forms?

I would expect a good approach might be to process all the variables up-front and use defaults so you can guarantee that they have values. Even if the value is a well-known fake value like “UNAVAILABLE” or something.

That will give you the ability to get rid of a tonne of conditionals in the individual handlers. So you may only need to worry about testing cookies. But even there you can perhaps pre-process them once you know which flavour of content you’re serving? Then it’s just a single <txp:if_variable> test for each content type.

There may be some complexities I haven’t figured as I didn’t quite understand the way you’d set it all up when I was hacking out the bits I didn’t need. But there ought to be a way of making a single template per type (audio, video) or maybe a few types with common elements, and feeding the variables into them.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#13 2020-08-15 11:49:37

etc
Developer
Registered: 2010-11-11
Posts: 3,863
Website

Re: size limitation in forms?

We could reduce the memory consumption (at the price of a slight runtime increase), storing only top-level tags of each parsed $thing. But optimizing your txp code will never hurt.

Offline

#14 2020-08-15 17:00:41

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,721
Website

Re: size limitation in forms?

Nah, the parser’s great. It’s the tag code in this case that needs refactoring


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#15 2020-08-15 17:45:00

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,269
Website

Re: size limitation in forms?

Bloke wrote #325373:

Nah, the parser’s great. It’s the tag code in this case that needs refactoring

+1. I am studying it:)

The issue is that there appears to be very little commonalities amongst hosts for their embed iframes. Furthermore, GDPR demands that the privacy statement from each host is linked to, and again all these addresses are different.

I find youtube’s approach the best regarding their urls for videos, images and the embed codes. it makes perfect sense and it may have a little something to do with its popularity.

In contrast, vimeo needs an API key in order to parse images to external sites and the urls of those, have nothing to do with the video urls, which is the reason I omitted them.

It needs thinking!


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github | Covid-19; a resource
I do my best editing after I click on the submit button.

Offline

#16 2020-08-15 21:15:19

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,721
Website

Re: size limitation in forms?

colak wrote #325374:

there appears to be very little commonalities amongst hosts for their embed iframes.

Maybe. But there aren’t an infinite number of ways of rendering a media clip. You should be able to group them. Type A use the same URL key for cover images. Type B need an API key, and so on.

If you could classify them that way, you’d know which ones take which options. Then cater to the various types and make sure you pass in the relevant parameters. If someone supplies the wrong params or misses one, your default cases will fill in the blanks or allow the shortcode to fail gracefully.

That way, you don’t need if type=‘vimeo’ then do this. And another block if type=‘dailymotion’ then do this. If you know both those services use broadly the same flavour of iframe, you can set up your variables from all the yields passed in and then do:

if type=“vimeo, dailymotion, …” match=“any” then …

GDPR demands that the privacy statement from each host is linked to, and again all these addresses are different.

This is what is complicating things in the current setup. Maybe you could collate all the URLs at the start in a huge privacy table:

<txp:variable name="privacy_youtube">https://youtube.com/privacy</txp:variable>
<txp:variable name="privacy_vimeo">https://vimeo.com/privacy-policy</txp:variable>
<txp:variable name="privacy_bandcamp">https://bandcamp.com/policies/privacy</txp:variable>
...

Then you can just grab the relevant variable when you do know the type:

<a href="<txp:variable name='privacy_<txp:yield name="type" />'">Privacy policy</a>

vimeo needs an API key in order to parse images to external sites and the urls of those, have nothing to do with the video urls

The example URLs they give out are different keys indeed if you’re logged in, but if you actually try passing in the same key as the video URL itself, it actually does work (or at least it seemed to in my tests).

I might be wrong, but they’d be daft to make it more difficult than necessary to get the cover image for a video when users want to link to the service. If they do make it more difficult, that might partly explain why they’re not the dominant video provider in the marketplace!


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#17 2020-08-16 04:49:14

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,269
Website

Re: size limitation in forms?

I might be thinking about it in the wrong way but there is nothing wrong, memory wise, with the privacy policies as they are just html.

One way I am thinking is to split the form into 4 forms which could be based on popularity.

The media template could host the variables and a growing number of if_yields. Something like

<txp:if_yield name="from" value="yt"><txp:output_form form="media_popular_a" /></txp:if_yield>
<txp:if_yield name="from" value="v"><txp:output_form form="media_popular_a" /></txp:if_yield>
<txp:if_yield name="from" value="pt"><txp:output_form form="media_popular_c" /></txp:if_yield>
...

A second, lazy way, would be to have the media form as described above but create a new form for each host.

Maybe if there is a way to evaluate if a form exists I’ll just need a few lines of code.

<txp:variable name="check_form"><txp:output_form form='media_<txp:yield name="from" />' /></txp:variable>
<txp:evaluate test='<txp:variable name="check_form" />'>
	<txp:variable name="check_form" />
<txp:else />
	<txp:if_logged_in>
		<p class="error">Error: There is no <b><txp:yield name="from" /></b> host using the <b>from</b> attribute.</p>
	</txp:if_logged_in>
</txp:evaluate>

I know that this untested method might over-populate the forms side, but it may be the most efficient memory-wise. I nevertheless do not know what happens, memory-wise, to articles/pages that may host a number of embeds from various hosts and if the evaluate tag will work.

On the positive side, the code will be totally modularised and those who may be interested in this shortcode, will only be needing to download the media form, and the forms for the hosts they use.


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github | Covid-19; a resource
I do my best editing after I click on the submit button.

Offline

#18 2020-08-16 06:30:32

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,269
Website

Re: size limitation in forms?

Bloke wrote #325375:

The example URLs they give out are different keys indeed if you’re logged in, but if you actually try passing in the same key as the video URL itself, it actually does work (or at least it seemed to in my tests).

I might be wrong, but they’d be daft to make it more difficult than necessary to get the cover image for a video when users want to link to the service. If they do make it more difficult, that might partly explain why they’re not the dominant video provider in the marketplace!

My tests return different imgs for example video id 7430730 returns 782791131.jpg and 7430730.jpg belongs to an unknown video.

I think that there are good things with vimeo such as no advertising as they rely on the paying users for their revenue. Their codecs are excellent and they produce better quality streams. On the down side they have limitations on how much one can upload for free. For the paying users, they delete their videos once they stop their subscriptions. URLs are of course another issue, as well as their unnecessary use of third party analytics in their site.

I am considering to recommend to the NeMe committee to re-upload most of our videos to as many hosts as possible, starting from the Internet Archive and YouTube, in order to extend their life-span, and audience, beyond our platform of choice.


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github | Covid-19; a resource
I do my best editing after I click on the submit button.

Offline

#19 2020-08-16 07:33:30

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,721
Website

Re: size limitation in forms?

colak wrote #325377:

My tests return different imgs for example video id 7430730 returns 782791131.jpg and 7430730.jpg belongs to an unknown video.

Okay, I might have got mixed up then, sorry. It worked for soundcloud. Thought it might be the same for Vimeo.

The trouble with this approach is that you can get all the info you want if you supply the URL to the video, as you get back all the info you need. But since you want to get the cover image directly without trying to use the URL first (because accessing the video URL violates GDPR) then you will likely need to jump through a lot of hoops to get it.

The alternative is to provide a fallback with a simple ‘play triangle’ and no cover image in cases where it is difficult to retrieve. Not ideal.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#20 2020-08-16 08:17:42

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,269
Website

Re: size limitation in forms?

Images are indeed an issue I am struggling with but I have to admit that tags is another. I actually hoped that my second example above would yield some results but in spite of the evaluate tag returning true, the error appears. Here’s the relevant tag trace:

70.67 4.73 <txp:variable name="check_form">
70.68 [true]
tags in the output form
75.40 </txp:variable>
75.40 0.07 <txp:evaluate test='<txp:variable name="check_form" />'>
75.41 0.02 [attribute 'test']
75.41 [true]
75.42 0.01 <txp:variable name="check_form" />
75.43 [/attribute]
75.44 [true]
75.45 0.02 <txp:if_logged_in>
75.46 [true]
75.46 0.01 <txp:yield name="from" />
75.47 </txp:if_logged_in>
75.47 </txp:evaluate>

Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github | Covid-19; a resource
I do my best editing after I click on the submit button.

Offline

Board footer

Powered by FluxBB